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);
43 hashDialog.RunSilent = true;
45 Assert.Equal(new[] { "#foo", "#bar" }, hashDialog.HistoryHashList.Items.Cast<string>());
46 Assert.Equal(new[] { "#foo", "#bar" }, hashDialog.HashHistories);
50 public void InitHashtagHistory_EmptyTest()
52 var hashtags = Array.Empty<string>();
54 using var atDialog = new AtIdSupplement();
55 using var hashDialog = new HashtagManage(atDialog, hashtags, "", false, false, false);
56 hashDialog.RunSilent = true;
58 Assert.Empty(hashDialog.HistoryHashList.Items);
59 Assert.Empty(hashDialog.HashHistories);
63 public void AddHashtag_Test()
65 using var atDialog = new AtIdSupplement();
66 using var hashDialog = new HashtagManage(atDialog, Array.Empty<string>(), "", false, false, false);
67 hashDialog.RunSilent = true;
69 TestUtils.FireEvent(hashDialog.AddButton, "Click"); // 「新規 (&N)」ボタン
71 hashDialog.UseHashText.Text = "#OpenTween";
73 TestUtils.FireEvent(hashDialog.PermOK_Button, "Click"); // 「詳細」グループ内の「OK」ボタン
75 Assert.Equal(new[] { "#OpenTween" }, hashDialog.HistoryHashList.Items.Cast<string>());
76 Assert.Equal(new[] { "#OpenTween" }, hashDialog.HashHistories);
80 public void AddHashtag_FullWidthTest()
82 using var atDialog = new AtIdSupplement();
83 using var hashDialog = new HashtagManage(atDialog, Array.Empty<string>(), "", false, false, false);
84 hashDialog.RunSilent = true;
86 TestUtils.FireEvent(hashDialog.AddButton, "Click"); // 「新規 (&N)」ボタン
88 hashDialog.UseHashText.Text = "#ほげほげ";
90 TestUtils.FireEvent(hashDialog.PermOK_Button, "Click"); // 「詳細」グループ内の「OK」ボタン
92 Assert.Equal(new[] { "#ほげほげ" }, hashDialog.HistoryHashList.Items.Cast<string>());
93 Assert.Equal(new[] { "#ほげほげ" }, hashDialog.HashHistories);
97 public void AddHashtag_CombiningCharacterSequenceTest()
99 // ハッシュタグを表す「#」の直後に結合文字 (濁点など) が続いた場合に対するテスト
101 using var atDialog = new AtIdSupplement();
102 using var hashDialog = new HashtagManage(atDialog, Array.Empty<string>(), "", false, false, false);
103 hashDialog.RunSilent = true;
105 TestUtils.FireEvent(hashDialog.AddButton, "Click"); // 「新規 (&N)」ボタン
107 // どんちき└(^ω^ )┐♫ ┌( ^ω^)┘♫どんちき
108 hashDialog.UseHashText.Text = "#゛t゛e゛s゛a゛b゛u゛";
110 TestUtils.FireEvent(hashDialog.PermOK_Button, "Click"); // 「詳細」グループ内の「OK」ボタン
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);
117 public void AddHashtag_MultipleTest()
119 using var atDialog = new AtIdSupplement();
120 using var hashDialog = new HashtagManage(atDialog, Array.Empty<string>(), "", false, false, false);
121 hashDialog.RunSilent = true;
123 TestUtils.FireEvent(hashDialog.AddButton, "Click"); // 「新規 (&N)」ボタン
125 hashDialog.UseHashText.Text = "#foo #bar";
127 TestUtils.FireEvent(hashDialog.PermOK_Button, "Click"); // 「詳細」グループ内の「OK」ボタン
129 Assert.Equal(new[] { "#foo #bar" }, hashDialog.HistoryHashList.Items.Cast<string>());
130 Assert.Equal(new[] { "#foo #bar" }, hashDialog.HashHistories);
134 public void AddHashtag_InvalidTest()
136 using var atDialog = new AtIdSupplement();
137 using var hashDialog = new HashtagManage(atDialog, Array.Empty<string>(), "", false, false, false);
138 hashDialog.RunSilent = true;
140 TestUtils.FireEvent(hashDialog.AddButton, "Click"); // 「新規 (&N)」ボタン
142 hashDialog.UseHashText.Text = "hogehoge";
144 TestUtils.FireEvent(hashDialog.PermOK_Button, "Click"); // 「詳細」グループ内の「OK」ボタン
145 // 実際にはここでエラーメッセージが出る
147 Assert.Empty(hashDialog.HistoryHashList.Items);
148 Assert.Empty(hashDialog.HashHistories);
152 public void EditHashtag_Test()
154 var hashtags = new[] { "#foo", "#bar" };
156 using var atDialog = new AtIdSupplement();
157 using var hashDialog = new HashtagManage(atDialog, hashtags, "", false, false, false);
158 hashDialog.RunSilent = true;
160 hashDialog.HistoryHashList.SelectedIndices.Add(0);
162 TestUtils.FireEvent(hashDialog.EditButton, "Click"); // 「編集(&E)」ボタン
164 hashDialog.UseHashText.Text = "#hoge";
166 TestUtils.FireEvent(hashDialog.PermOK_Button, "Click"); // 「詳細」グループ内の「OK」ボタン
168 Assert.Equal(new[] { "#hoge", "#bar" }, hashDialog.HistoryHashList.Items.Cast<string>());
169 Assert.Equal(new[] { "#hoge", "#bar" }, hashDialog.HashHistories);
173 public void DeleteHashtag_Test()
175 var hashtags = new[] { "#foo", "#bar" };
177 using var atDialog = new AtIdSupplement();
178 using var hashDialog = new HashtagManage(atDialog, hashtags, "", false, false, false);
179 hashDialog.RunSilent = true;
181 hashDialog.HistoryHashList.SelectedIndices.Add(1);
183 TestUtils.FireEvent(hashDialog.DeleteButton, "Click"); // 「削除(&D)」ボタン
185 Assert.Equal(new[] { "#foo" }, hashDialog.HistoryHashList.Items.Cast<string>());
186 Assert.Equal(new[] { "#foo" }, hashDialog.HashHistories);
190 public void DeleteHashtag_MultipleTest()
192 var hashtags = new[] { "#foo", "#bar", "#baz" };
194 using var atDialog = new AtIdSupplement();
195 using var hashDialog = new HashtagManage(atDialog, hashtags, "", false, false, false);
196 hashDialog.RunSilent = true;
198 hashDialog.HistoryHashList.SelectedIndices.Add(2);
199 hashDialog.HistoryHashList.SelectedIndices.Add(1);
201 TestUtils.FireEvent(hashDialog.DeleteButton, "Click"); // 「削除(&D)」ボタン
203 Assert.Equal(new[] { "#foo" }, hashDialog.HistoryHashList.Items.Cast<string>());
204 Assert.Equal(new[] { "#foo" }, hashDialog.HashHistories);
208 public void DeleteHashtag_NotSelectTest()
210 var hashtags = new[] { "#foo", "#bar" };
212 using var atDialog = new AtIdSupplement();
213 using var hashDialog = new HashtagManage(atDialog, hashtags, "", false, false, false);
214 hashDialog.RunSilent = true;
218 TestUtils.FireEvent(hashDialog.DeleteButton, "Click"); // 「削除(&D)」ボタン
220 Assert.Equal(new[] { "#foo", "#bar" }, hashDialog.HistoryHashList.Items.Cast<string>());
221 Assert.Equal(new[] { "#foo", "#bar" }, hashDialog.HashHistories);
225 public void UnSelectButton_Test()
227 var hashtags = new[] { "#foo" };
229 using var atDialog = new AtIdSupplement();
230 using var hashDialog = new HashtagManage(atDialog, hashtags, "", false, false, false);
231 hashDialog.RunSilent = true;
233 hashDialog.HistoryHashList.SelectedIndices.Add(0);
235 TestUtils.FireEvent(hashDialog.UnSelectButton, "Click"); // 「非使用(&U)」ボタン
237 Assert.Empty(hashDialog.HistoryHashList.SelectedIndices);
241 public void EditModeSwitch_Test()
243 using var atDialog = new AtIdSupplement();
244 using var hashDialog = new HashtagManage(atDialog, Array.Empty<string>(), "", false, false, false);
245 hashDialog.RunSilent = true;
247 Assert.True(hashDialog.GroupHashtag.Enabled);
248 Assert.True(hashDialog.TableLayoutButtons.Enabled);
249 Assert.False(hashDialog.GroupDetail.Enabled);
251 TestUtils.FireEvent(hashDialog.AddButton, "Click"); // 「新規 (&N)」ボタン
254 Assert.False(hashDialog.GroupHashtag.Enabled);
255 Assert.False(hashDialog.TableLayoutButtons.Enabled);
256 Assert.True(hashDialog.GroupDetail.Enabled);
258 hashDialog.UseHashText.Text = "#hogehoge";
260 TestUtils.FireEvent(hashDialog.PermOK_Button, "Click"); // 「詳細」グループ内の「OK」ボタン
263 Assert.True(hashDialog.GroupHashtag.Enabled);
264 Assert.True(hashDialog.TableLayoutButtons.Enabled);
265 Assert.False(hashDialog.GroupDetail.Enabled);