OSDN Git Service

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