OSDN Git Service

OpenTween v1.4.2 リリース
[opentween/open-tween.git] / OpenTween.Tests / HashtagManageTest.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.Linq;
25 using System.Text;
26 using System.Windows.Forms;
27 using Xunit;
28 using Xunit.Extensions;
29
30 namespace OpenTween
31 {
32     public class HashtagManageTest
33     {
34         // _isPermanent絡みの挙動が謎すぎて全然網羅できてない
35
36         [Fact]
37         public void InitHashtagHistory_Test()
38         {
39             var hashtags = new[] { "#foo", "#bar" };
40
41             using (var atDialog = new AtIdSupplement())
42             using (var hashDialog = new HashtagManage(atDialog, hashtags, "", false, false, false))
43             {
44                 hashDialog.RunSilent = true;
45
46                 Assert.Equal(new[] { "#foo", "#bar" }, hashDialog.HistoryHashList.Items.Cast<string>());
47                 Assert.Equal(new[] { "#foo", "#bar" }, hashDialog.HashHistories);
48             }
49         }
50
51         [Fact]
52         public void InitHashtagHistory_EmptyTest()
53         {
54             var hashtags = new string[0];
55
56             using (var atDialog = new AtIdSupplement())
57             using (var hashDialog = new HashtagManage(atDialog, hashtags, "", false, false, false))
58             {
59                 hashDialog.RunSilent = true;
60
61                 Assert.Empty(hashDialog.HistoryHashList.Items);
62                 Assert.Empty(hashDialog.HashHistories);
63             }
64         }
65
66         [Fact]
67         public void AddHashtag_Test()
68         {
69             using (var atDialog = new AtIdSupplement())
70             using (var hashDialog = new HashtagManage(atDialog, new string[0], "", false, false, false))
71             {
72                 hashDialog.RunSilent = true;
73
74                 TestUtils.FireEvent(hashDialog.AddButton, "Click"); // 「新規 (&N)」ボタン
75
76                 hashDialog.UseHashText.Text = "#OpenTween";
77
78                 TestUtils.FireEvent(hashDialog.PermOK_Button, "Click"); // 「詳細」グループ内の「OK」ボタン
79
80                 Assert.Equal(new[] { "#OpenTween" }, hashDialog.HistoryHashList.Items.Cast<string>());
81                 Assert.Equal(new[] { "#OpenTween" }, hashDialog.HashHistories);
82             }
83         }
84
85         [Fact]
86         public void AddHashtag_FullWidthTest()
87         {
88             using (var atDialog = new AtIdSupplement())
89             using (var hashDialog = new HashtagManage(atDialog, new string[0], "", false, false, false))
90             {
91                 hashDialog.RunSilent = true;
92
93                 TestUtils.FireEvent(hashDialog.AddButton, "Click"); // 「新規 (&N)」ボタン
94
95                 hashDialog.UseHashText.Text = "#ほげほげ";
96
97                 TestUtils.FireEvent(hashDialog.PermOK_Button, "Click"); // 「詳細」グループ内の「OK」ボタン
98
99                 Assert.Equal(new[] { "#ほげほげ" }, hashDialog.HistoryHashList.Items.Cast<string>());
100                 Assert.Equal(new[] { "#ほげほげ" }, hashDialog.HashHistories);
101             }
102         }
103
104         [Fact]
105         public void AddHashtag_CombiningCharacterSequenceTest()
106         {
107             // ハッシュタグを表す「#」の直後に結合文字 (濁点など) が続いた場合に対するテスト
108
109             using (var atDialog = new AtIdSupplement())
110             using (var hashDialog = new HashtagManage(atDialog, new string[0], "", false, false, false))
111             {
112                 hashDialog.RunSilent = true;
113
114                 TestUtils.FireEvent(hashDialog.AddButton, "Click"); // 「新規 (&N)」ボタン
115
116                 // どんちき└(^ω^ )┐♫ ┌( ^ω^)┘♫どんちき
117                 hashDialog.UseHashText.Text = "#゛t゛e゛s゛a゛b゛u゛";
118
119                 TestUtils.FireEvent(hashDialog.PermOK_Button, "Click"); // 「詳細」グループ内の「OK」ボタン
120
121                 Assert.Equal(new[] { "#゛t゛e゛s゛a゛b゛u゛" }, hashDialog.HistoryHashList.Items.Cast<string>());
122                 Assert.Equal(new[] { "#゛t゛e゛s゛a゛b゛u゛" }, hashDialog.HashHistories);
123             }
124         }
125
126         [Fact]
127         public void AddHashtag_MultipleTest()
128         {
129             using (var atDialog = new AtIdSupplement())
130             using (var hashDialog = new HashtagManage(atDialog, new string[0], "", false, false, false))
131             {
132                 hashDialog.RunSilent = true;
133
134                 TestUtils.FireEvent(hashDialog.AddButton, "Click"); // 「新規 (&N)」ボタン
135
136                 hashDialog.UseHashText.Text = "#foo #bar";
137
138                 TestUtils.FireEvent(hashDialog.PermOK_Button, "Click"); // 「詳細」グループ内の「OK」ボタン
139
140                 Assert.Equal(new[] { "#foo #bar" }, hashDialog.HistoryHashList.Items.Cast<string>());
141                 Assert.Equal(new[] { "#foo #bar" }, hashDialog.HashHistories);
142             }
143         }
144
145         [Fact]
146         public void AddHashtag_InvalidTest()
147         {
148             using (var atDialog = new AtIdSupplement())
149             using (var hashDialog = new HashtagManage(atDialog, new string[0], "", false, false, false))
150             {
151                 hashDialog.RunSilent = true;
152
153                 TestUtils.FireEvent(hashDialog.AddButton, "Click"); // 「新規 (&N)」ボタン
154
155                 hashDialog.UseHashText.Text = "hogehoge";
156
157                 TestUtils.FireEvent(hashDialog.PermOK_Button, "Click"); // 「詳細」グループ内の「OK」ボタン
158                 // 実際にはここでエラーメッセージが出る
159
160                 Assert.Empty(hashDialog.HistoryHashList.Items);
161                 Assert.Empty(hashDialog.HashHistories);
162             }
163         }
164
165         [Fact]
166         public void EditHashtag_Test()
167         {
168             var hashtags = new[] { "#foo", "#bar" };
169
170             using (var atDialog = new AtIdSupplement())
171             using (var hashDialog = new HashtagManage(atDialog, hashtags, "", false, false, false))
172             {
173                 hashDialog.RunSilent = true;
174
175                 hashDialog.HistoryHashList.SelectedIndices.Add(0);
176
177                 TestUtils.FireEvent(hashDialog.EditButton, "Click"); // 「編集(&E)」ボタン
178
179                 hashDialog.UseHashText.Text = "#hoge";
180
181                 TestUtils.FireEvent(hashDialog.PermOK_Button, "Click"); // 「詳細」グループ内の「OK」ボタン
182
183                 Assert.Equal(new[] { "#hoge", "#bar" }, hashDialog.HistoryHashList.Items.Cast<string>());
184                 Assert.Equal(new[] { "#hoge", "#bar" }, hashDialog.HashHistories);
185             }
186         }
187
188         [Fact]
189         public void DeleteHashtag_Test()
190         {
191             var hashtags = new[] { "#foo", "#bar" };
192
193             using (var atDialog = new AtIdSupplement())
194             using (var hashDialog = new HashtagManage(atDialog, hashtags, "", false, false, false))
195             {
196                 hashDialog.RunSilent = true;
197
198                 hashDialog.HistoryHashList.SelectedIndices.Add(1);
199
200                 TestUtils.FireEvent(hashDialog.DeleteButton, "Click"); // 「削除(&D)」ボタン
201
202                 Assert.Equal(new[] { "#foo" }, hashDialog.HistoryHashList.Items.Cast<string>());
203                 Assert.Equal(new[] { "#foo" }, hashDialog.HashHistories);
204             }
205         }
206
207         [Fact]
208         public void DeleteHashtag_MultipleTest()
209         {
210             var hashtags = new[] { "#foo", "#bar", "#baz" };
211
212             using (var atDialog = new AtIdSupplement())
213             using (var hashDialog = new HashtagManage(atDialog, hashtags, "", false, false, false))
214             {
215                 hashDialog.RunSilent = true;
216
217                 hashDialog.HistoryHashList.SelectedIndices.Add(2);
218                 hashDialog.HistoryHashList.SelectedIndices.Add(1);
219
220                 TestUtils.FireEvent(hashDialog.DeleteButton, "Click"); // 「削除(&D)」ボタン
221
222                 Assert.Equal(new[] { "#foo" }, hashDialog.HistoryHashList.Items.Cast<string>());
223                 Assert.Equal(new[] { "#foo" }, hashDialog.HashHistories);
224             }
225         }
226
227         [Fact]
228         public void DeleteHashtag_NotSelectTest()
229         {
230             var hashtags = new[] { "#foo", "#bar" };
231
232             using (var atDialog = new AtIdSupplement())
233             using (var hashDialog = new HashtagManage(atDialog, hashtags, "", false, false, false))
234             {
235                 hashDialog.RunSilent = true;
236
237                 // ハッシュタグを選択していない状態
238
239                 TestUtils.FireEvent(hashDialog.DeleteButton, "Click"); // 「削除(&D)」ボタン
240
241                 Assert.Equal(new[] { "#foo", "#bar" }, hashDialog.HistoryHashList.Items.Cast<string>());
242                 Assert.Equal(new[] { "#foo", "#bar" }, hashDialog.HashHistories);
243             }
244         }
245
246         [Fact]
247         public void UnSelectButton_Test()
248         {
249             var hashtags = new[] { "#foo" };
250
251             using (var atDialog = new AtIdSupplement())
252             using (var hashDialog = new HashtagManage(atDialog, hashtags, "", false, false, false))
253             {
254                 hashDialog.RunSilent = true;
255
256                 hashDialog.HistoryHashList.SelectedIndices.Add(0);
257
258                 TestUtils.FireEvent(hashDialog.UnSelectButton, "Click"); // 「非使用(&U)」ボタン
259
260                 Assert.Empty(hashDialog.HistoryHashList.SelectedIndices);
261             }
262         }
263
264         [Fact]
265         public void EditModeSwitch_Test()
266         {
267             using (var atDialog = new AtIdSupplement())
268             using (var hashDialog = new HashtagManage(atDialog, new string[0], "", false, false, false))
269             {
270                 hashDialog.RunSilent = true;
271
272                 Assert.True(hashDialog.GroupHashtag.Enabled);
273                 Assert.True(hashDialog.TableLayoutButtons.Enabled);
274                 Assert.False(hashDialog.GroupDetail.Enabled);
275
276                 TestUtils.FireEvent(hashDialog.AddButton, "Click"); // 「新規 (&N)」ボタン
277
278                 // 編集モードに入る
279                 Assert.False(hashDialog.GroupHashtag.Enabled);
280                 Assert.False(hashDialog.TableLayoutButtons.Enabled);
281                 Assert.True(hashDialog.GroupDetail.Enabled);
282
283                 hashDialog.UseHashText.Text = "#hogehoge";
284
285                 TestUtils.FireEvent(hashDialog.PermOK_Button, "Click"); // 「詳細」グループ内の「OK」ボタン
286
287                 // 編集モードから抜ける
288                 Assert.True(hashDialog.GroupHashtag.Enabled);
289                 Assert.True(hashDialog.TableLayoutButtons.Enabled);
290                 Assert.False(hashDialog.GroupDetail.Enabled);
291             }
292         }
293     }
294 }