OSDN Git Service

不要なExtractTimelineTweetsメソッドの呼び出しを削除
[opentween/open-tween.git] / OpenTween.Tests / TweetDetailsViewTest.cs
1 // OpenTween - Client of Twitter
2 // Copyright (c) 2014 kim_upsilon (@kim_upsilon) <https://upsilo.net/~upsilon/>
3 // All rights reserved.
4 //
5 // This file is part of OpenTween.
6 //
7 // This program is free software; you can redistribute it and/or modify it
8 // under the terms of the GNU General Public License as published by the Free
9 // Software Foundation; either version 3 of the License, or (at your option)
10 // any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 // for more details.
16 //
17 // You should have received a copy of the GNU General Public License along
18 // with this program. If not, see <http://www.gnu.org/licenses/>, or write to
19 // the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
20 // Boston, MA 02110-1301, USA.
21
22 using System;
23 using System.Collections.Generic;
24 using System.Globalization;
25 using System.Linq;
26 using System.Text;
27 using System.Threading.Tasks;
28 using OpenTween.Models;
29 using Xunit;
30
31 namespace OpenTween
32 {
33     public class TweetDetailsViewTest
34     {
35         [WinFormsFact]
36         public void Initialize_Test()
37         {
38             using var detailsView = new TweetDetailsView();
39         }
40
41         [Fact]
42         public void FormatQuoteTweetHtml_PostClassTest()
43         {
44             var post = new PostClass
45             {
46                 StatusId = new TwitterStatusId("12345"),
47                 Nickname = "upsilon",
48                 ScreenName = "kim_upsilon",
49                 Text = """<a href="https://twitter.com/twitterapi">@twitterapi</a> hogehoge""",
50                 CreatedAt = new DateTimeUtc(2015, 3, 30, 3, 30, 0),
51             };
52
53             // PostClass.Text はリンクを除去するのみでエスケープは行わない
54             // (TweetFormatter によって既にエスケープされた文字列が格納されているため)
55
56             var expected = """<a class="quote-tweet-link" href="//opentween/status/12345">""" +
57                 """<blockquote class="quote-tweet">""" +
58                 "<p>@twitterapi hogehoge</p> &mdash; upsilon (@kim_upsilon) " + DateTimeUtc.Parse("2015/03/30 3:30:00", DateTimeFormatInfo.InvariantInfo).ToLocalTimeString() +
59                 "</blockquote></a>";
60             Assert.Equal(expected, TweetDetailsView.FormatQuoteTweetHtml(post, isReply: false));
61         }
62
63         [Fact]
64         public void FormatQuoteTweetHtml_HtmlTest()
65         {
66             var statusId = new TwitterStatusId("12345"); // リンク先のステータスID
67             var html = "<marquee>hogehoge</marquee>"; // HTMLをそのまま出力する (エスケープしない)
68
69             var expected = """<a class="quote-tweet-link" href="//opentween/status/12345">""" +
70                 """<blockquote class="quote-tweet"><marquee>hogehoge</marquee></blockquote>""" +
71                 "</a>";
72             Assert.Equal(expected, TweetDetailsView.FormatQuoteTweetHtml(statusId, html, isReply: false));
73         }
74
75         [Fact]
76         public void FormatQuoteTweetHtml_ReplyHtmlTest()
77         {
78             // blockquote の class に reply が付与される
79             var expected = """<a class="quote-tweet-link" href="//opentween/status/12345">""" +
80                 """<blockquote class="quote-tweet reply">hogehoge</blockquote>""" +
81                 "</a>";
82             Assert.Equal(expected, TweetDetailsView.FormatQuoteTweetHtml(new TwitterStatusId("12345"), "hogehoge", isReply: true));
83         }
84
85         [Fact]
86         public void StripLinkTagHtml_Test()
87         {
88             var html = """<a href="https://twitter.com/twitterapi">@twitterapi</a>""";
89
90             var expected = "@twitterapi";
91             Assert.Equal(expected, TweetDetailsView.StripLinkTagHtml(html));
92         }
93     }
94 }