1 // OpenTween - Client of Twitter
2 // Copyright (c) 2014 kim_upsilon (@kim_upsilon) <https://upsilo.net/~upsilon/>
3 // All rights reserved.
5 // This file is part of OpenTween.
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)
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
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.
23 using System.Collections.Generic;
26 using System.Windows.Forms;
28 using Xunit.Extensions;
32 public class HashtagManageTest
34 // _isPermanent絡みの挙動が謎すぎて全然網羅できてない
37 public void InitHashtagHistory_Test()
39 var hashtags = new[] { "#foo", "#bar" };
41 using (var atDialog = new AtIdSupplement())
42 using (var hashDialog = new HashtagManage(atDialog, hashtags, "", false, false, false))
44 hashDialog.RunSilent = true;
46 Assert.Equal(new[] { "#foo", "#bar" }, hashDialog.HistoryHashList.Items.Cast<string>());
47 Assert.Equal(new[] { "#foo", "#bar" }, hashDialog.HashHistories);
52 public void InitHashtagHistory_EmptyTest()
54 var hashtags = new string[0];
56 using (var atDialog = new AtIdSupplement())
57 using (var hashDialog = new HashtagManage(atDialog, hashtags, "", false, false, false))
59 hashDialog.RunSilent = true;
61 Assert.Empty(hashDialog.HistoryHashList.Items);
62 Assert.Empty(hashDialog.HashHistories);
67 public void AddHashtag_Test()
69 using (var atDialog = new AtIdSupplement())
70 using (var hashDialog = new HashtagManage(atDialog, new string[0], "", false, false, false))
72 hashDialog.RunSilent = true;
74 TestUtils.FireEvent(hashDialog.AddButton, "Click"); // 「新規 (&N)」ボタン
76 hashDialog.UseHashText.Text = "#OpenTween";
78 TestUtils.FireEvent(hashDialog.PermOK_Button, "Click"); // 「詳細」グループ内の「OK」ボタン
80 Assert.Equal(new[] { "#OpenTween" }, hashDialog.HistoryHashList.Items.Cast<string>());
81 Assert.Equal(new[] { "#OpenTween" }, hashDialog.HashHistories);
86 public void AddHashtag_FullWidthTest()
88 using (var atDialog = new AtIdSupplement())
89 using (var hashDialog = new HashtagManage(atDialog, new string[0], "", false, false, false))
91 hashDialog.RunSilent = true;
93 TestUtils.FireEvent(hashDialog.AddButton, "Click"); // 「新規 (&N)」ボタン
95 hashDialog.UseHashText.Text = "#ほげほげ";
97 TestUtils.FireEvent(hashDialog.PermOK_Button, "Click"); // 「詳細」グループ内の「OK」ボタン
99 Assert.Equal(new[] { "#ほげほげ" }, hashDialog.HistoryHashList.Items.Cast<string>());
100 Assert.Equal(new[] { "#ほげほげ" }, hashDialog.HashHistories);
105 public void AddHashtag_CombiningCharacterSequenceTest()
107 // ハッシュタグを表す「#」の直後に結合文字 (濁点など) が続いた場合に対するテスト
109 using (var atDialog = new AtIdSupplement())
110 using (var hashDialog = new HashtagManage(atDialog, new string[0], "", false, false, false))
112 hashDialog.RunSilent = true;
114 TestUtils.FireEvent(hashDialog.AddButton, "Click"); // 「新規 (&N)」ボタン
116 // どんちき└(^ω^ )┐♫ ┌( ^ω^)┘♫どんちき
117 hashDialog.UseHashText.Text = "#゛t゛e゛s゛a゛b゛u゛";
119 TestUtils.FireEvent(hashDialog.PermOK_Button, "Click"); // 「詳細」グループ内の「OK」ボタン
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);
127 public void AddHashtag_MultipleTest()
129 using (var atDialog = new AtIdSupplement())
130 using (var hashDialog = new HashtagManage(atDialog, new string[0], "", false, false, false))
132 hashDialog.RunSilent = true;
134 TestUtils.FireEvent(hashDialog.AddButton, "Click"); // 「新規 (&N)」ボタン
136 hashDialog.UseHashText.Text = "#foo #bar";
138 TestUtils.FireEvent(hashDialog.PermOK_Button, "Click"); // 「詳細」グループ内の「OK」ボタン
140 Assert.Equal(new[] { "#foo #bar" }, hashDialog.HistoryHashList.Items.Cast<string>());
141 Assert.Equal(new[] { "#foo #bar" }, hashDialog.HashHistories);
146 public void AddHashtag_InvalidTest()
148 using (var atDialog = new AtIdSupplement())
149 using (var hashDialog = new HashtagManage(atDialog, new string[0], "", false, false, false))
151 hashDialog.RunSilent = true;
153 TestUtils.FireEvent(hashDialog.AddButton, "Click"); // 「新規 (&N)」ボタン
155 hashDialog.UseHashText.Text = "hogehoge";
157 TestUtils.FireEvent(hashDialog.PermOK_Button, "Click"); // 「詳細」グループ内の「OK」ボタン
158 // 実際にはここでエラーメッセージが出る
160 Assert.Empty(hashDialog.HistoryHashList.Items);
161 Assert.Empty(hashDialog.HashHistories);
166 public void EditHashtag_Test()
168 var hashtags = new[] { "#foo", "#bar" };
170 using (var atDialog = new AtIdSupplement())
171 using (var hashDialog = new HashtagManage(atDialog, hashtags, "", false, false, false))
173 hashDialog.RunSilent = true;
175 hashDialog.HistoryHashList.SelectedIndices.Add(0);
177 TestUtils.FireEvent(hashDialog.EditButton, "Click"); // 「編集(&E)」ボタン
179 hashDialog.UseHashText.Text = "#hoge";
181 TestUtils.FireEvent(hashDialog.PermOK_Button, "Click"); // 「詳細」グループ内の「OK」ボタン
183 Assert.Equal(new[] { "#hoge", "#bar" }, hashDialog.HistoryHashList.Items.Cast<string>());
184 Assert.Equal(new[] { "#hoge", "#bar" }, hashDialog.HashHistories);
189 public void DeleteHashtag_Test()
191 var hashtags = new[] { "#foo", "#bar" };
193 using (var atDialog = new AtIdSupplement())
194 using (var hashDialog = new HashtagManage(atDialog, hashtags, "", false, false, false))
196 hashDialog.RunSilent = true;
198 hashDialog.HistoryHashList.SelectedIndices.Add(1);
200 TestUtils.FireEvent(hashDialog.DeleteButton, "Click"); // 「削除(&D)」ボタン
202 Assert.Equal(new[] { "#foo" }, hashDialog.HistoryHashList.Items.Cast<string>());
203 Assert.Equal(new[] { "#foo" }, hashDialog.HashHistories);
208 public void DeleteHashtag_MultipleTest()
210 var hashtags = new[] { "#foo", "#bar", "#baz" };
212 using (var atDialog = new AtIdSupplement())
213 using (var hashDialog = new HashtagManage(atDialog, hashtags, "", false, false, false))
215 hashDialog.RunSilent = true;
217 hashDialog.HistoryHashList.SelectedIndices.Add(2);
218 hashDialog.HistoryHashList.SelectedIndices.Add(1);
220 TestUtils.FireEvent(hashDialog.DeleteButton, "Click"); // 「削除(&D)」ボタン
222 Assert.Equal(new[] { "#foo" }, hashDialog.HistoryHashList.Items.Cast<string>());
223 Assert.Equal(new[] { "#foo" }, hashDialog.HashHistories);
228 public void DeleteHashtag_NotSelectTest()
230 var hashtags = new[] { "#foo", "#bar" };
232 using (var atDialog = new AtIdSupplement())
233 using (var hashDialog = new HashtagManage(atDialog, hashtags, "", false, false, false))
235 hashDialog.RunSilent = true;
239 TestUtils.FireEvent(hashDialog.DeleteButton, "Click"); // 「削除(&D)」ボタン
241 Assert.Equal(new[] { "#foo", "#bar" }, hashDialog.HistoryHashList.Items.Cast<string>());
242 Assert.Equal(new[] { "#foo", "#bar" }, hashDialog.HashHistories);
247 public void UnSelectButton_Test()
249 var hashtags = new[] { "#foo" };
251 using (var atDialog = new AtIdSupplement())
252 using (var hashDialog = new HashtagManage(atDialog, hashtags, "", false, false, false))
254 hashDialog.RunSilent = true;
256 hashDialog.HistoryHashList.SelectedIndices.Add(0);
258 TestUtils.FireEvent(hashDialog.UnSelectButton, "Click"); // 「非使用(&U)」ボタン
260 Assert.Empty(hashDialog.HistoryHashList.SelectedIndices);
265 public void EditModeSwitch_Test()
267 using (var atDialog = new AtIdSupplement())
268 using (var hashDialog = new HashtagManage(atDialog, new string[0], "", false, false, false))
270 hashDialog.RunSilent = true;
272 Assert.True(hashDialog.GroupHashtag.Enabled);
273 Assert.True(hashDialog.TableLayoutButtons.Enabled);
274 Assert.False(hashDialog.GroupDetail.Enabled);
276 TestUtils.FireEvent(hashDialog.AddButton, "Click"); // 「新規 (&N)」ボタン
279 Assert.False(hashDialog.GroupHashtag.Enabled);
280 Assert.False(hashDialog.TableLayoutButtons.Enabled);
281 Assert.True(hashDialog.GroupDetail.Enabled);
283 hashDialog.UseHashText.Text = "#hogehoge";
285 TestUtils.FireEvent(hashDialog.PermOK_Button, "Click"); // 「詳細」グループ内の「OK」ボタン
288 Assert.True(hashDialog.GroupHashtag.Enabled);
289 Assert.True(hashDialog.TableLayoutButtons.Enabled);
290 Assert.False(hashDialog.GroupDetail.Enabled);