1 // OpenTween - Client of Twitter
2 // Copyright (c) 2012 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;
25 using System.Reflection;
27 using System.Windows.Forms;
28 using OpenTween.Models;
30 using Xunit.Extensions;
34 public class TabsDialogTest
36 private TabInformations tabinfo;
38 public TabsDialogTest()
40 this.tabinfo = Activator.CreateInstance(typeof(TabInformations), true) as TabInformations;
43 this.tabinfo.AddTab(new HomeTabModel("Recent"));
44 this.tabinfo.AddTab(new MentionsTabModel("Reply"));
45 this.tabinfo.AddTab(new DirectMessagesTabModel("DM"));
46 this.tabinfo.AddTab(new FavoritesTabModel("Favorites"));
47 this.tabinfo.AddTab(new FilterTabModel("MyTab1"));
49 // 一応 TabInformation.GetInstance() でも取得できるようにする
50 var field = typeof(TabInformations).GetField("_instance",
51 BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.SetField);
52 field.SetValue(null, this.tabinfo);
56 public void OKButtonEnabledTest()
58 using (var dialog = new TabsDialog(this.tabinfo))
60 Assert.False(dialog.OK_Button.Enabled);
62 dialog.TabList.SelectedIndex = 0;
64 Assert.True(dialog.OK_Button.Enabled);
66 dialog.TabList.SelectedIndex = -1;
68 Assert.False(dialog.OK_Button.Enabled);
73 public void MultiSelectTest()
75 using (var dialog = new TabsDialog(this.tabinfo))
77 // MultiSelect = false (default)
78 var firstItem = dialog.TabList.Items[0] as TabsDialog.TabListItem;
79 Assert.Null(firstItem.Tab); // 「(新規タブ)」
80 Assert.Equal(SelectionMode.One, dialog.TabList.SelectionMode);
82 dialog.MultiSelect = true;
83 firstItem = dialog.TabList.Items[0] as TabsDialog.TabListItem;
84 Assert.NotNull(firstItem.Tab);
85 Assert.Equal(SelectionMode.MultiExtended, dialog.TabList.SelectionMode);
87 dialog.MultiSelect = false;
88 firstItem = dialog.TabList.Items[0] as TabsDialog.TabListItem;
89 Assert.Null(firstItem.Tab);
90 Assert.Equal(SelectionMode.One, dialog.TabList.SelectionMode);
95 public void DoubleClickTest()
97 using (var dialog = new TabsDialog(this.tabinfo))
99 dialog.TabList.SelectedIndex = -1;
100 TestUtils.FireEvent(dialog.TabList, "DoubleClick");
102 Assert.Equal(DialogResult.None, dialog.DialogResult);
103 Assert.False(dialog.IsDisposed);
105 dialog.TabList.SelectedIndex = 1;
106 TestUtils.FireEvent(dialog.TabList, "DoubleClick");
108 Assert.Equal(DialogResult.OK, dialog.DialogResult);
109 Assert.True(dialog.IsDisposed);
114 public void SelectableTabTest()
116 using (var dialog = new TabsDialog(this.tabinfo))
118 dialog.MultiSelect = false;
120 var item = dialog.TabList.Items[0] as TabsDialog.TabListItem;
121 Assert.Null(item.Tab);
123 item = dialog.TabList.Items[1] as TabsDialog.TabListItem;
124 Assert.Equal(this.tabinfo.Tabs["Reply"], item.Tab);
126 item = dialog.TabList.Items[2] as TabsDialog.TabListItem;
127 Assert.Equal(this.tabinfo.Tabs["MyTab1"], item.Tab);
132 public void SelectedTabTest()
134 using (var dialog = new TabsDialog(this.tabinfo))
136 dialog.MultiSelect = false;
138 dialog.TabList.SelectedIndex = 0;
139 Assert.Null(dialog.SelectedTab);
141 dialog.TabList.SelectedIndex = 1;
142 Assert.Equal(this.tabinfo.Tabs["Reply"], dialog.SelectedTab);
147 public void SelectedTabsTest()
149 using (var dialog = new TabsDialog(this.tabinfo))
151 dialog.MultiSelect = true;
153 dialog.TabList.SelectedIndices.Clear();
154 var selectedTabs = dialog.SelectedTabs;
155 Assert.Empty(selectedTabs);
157 dialog.TabList.SelectedIndices.Add(0);
158 selectedTabs = dialog.SelectedTabs;
159 Assert.Equal(new[] { this.tabinfo.Tabs["Reply"] }, selectedTabs);
161 dialog.TabList.SelectedIndices.Add(1);
162 selectedTabs = dialog.SelectedTabs;
163 Assert.Equal(new[] { this.tabinfo.Tabs["Reply"], this.tabinfo.Tabs["MyTab1"] }, selectedTabs);