-
Notifications
You must be signed in to change notification settings - Fork 476
Expand file tree
/
Copy pathComboBoxTests.cs
More file actions
153 lines (134 loc) · 4.96 KB
/
ComboBoxTests.cs
File metadata and controls
153 lines (134 loc) · 4.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
using NUnit.Framework;
using System.Windows.Automation;
using TestStack.White.Configuration;
using TestStack.White.UIItems;
using TestStack.White.UIItems.Finders;
using TestStack.White.UIItems.ListBoxItems;
namespace TestStack.White.UITests.ControlTests.ListControls
{
[TestFixture(WindowsFramework.WinForms)]
[TestFixture(WindowsFramework.Wpf)]
public class ComboBoxTests : WhiteUITestBase
{
protected ComboBox ComboBoxUnderTest { get; set; }
public ComboBoxTests(WindowsFramework framework)
: base(framework)
{
}
[OneTimeSetUp]
public void Setup()
{
ComboBoxUnderTest = MainWindow.Get<ComboBox>(SearchCriteria.ByAutomationId("AComboBox"));
}
[Test]
public void ListItemInComboBoxWithoutTextAvailableInitiallyTest()
{
if (Framework != WindowsFramework.Wpf)
{
Assert.Ignore();
}
// Restart the application and reinitialize
Restart();
ComboBoxUnderTest = MainWindow.Get<ComboBox>(SearchCriteria.ByAutomationId("AComboBox"));
var config = CoreConfigurationLocator.Get();
var originalVal = config.ComboBoxItemsPopulatedWithoutDropDownOpen;
try
{
config.ComboBoxItemsPopulatedWithoutDropDownOpen = true;
Assert.That(ComboBoxUnderTest.Items, Has.Count.EqualTo(0));
}
finally
{
config.ComboBoxItemsPopulatedWithoutDropDownOpen = originalVal;
}
}
[Test]
public void ComboBoxOnlyCollapsesWhenExpansionWasForItemRetrievalTest()
{
// Arrange
var config = CoreConfigurationLocator.Get();
var originalVal = config.ComboBoxItemsPopulatedWithoutDropDownOpen;
config.ComboBoxItemsPopulatedWithoutDropDownOpen = false;
try
{
ComboBoxUnderTest.Expand();
// Act
#pragma warning disable 168
// ReSharper disable once UnusedVariable
var items = ComboBoxUnderTest.Items;
#pragma warning restore 168
// Assert
var expansionState = ComboBoxUnderTest.ExpandCollapseState;
Assert.That(expansionState, Is.EqualTo(ExpandCollapseState.Expanded));
}
finally
{
config.ComboBoxItemsPopulatedWithoutDropDownOpen = originalVal;
ComboBoxUnderTest.Collapse();
}
}
[Test]
public void ComboBoxWithAutoExpandCollapsedOnceItemsAreRetrievedTest()
{
// Arrange
var config = CoreConfigurationLocator.Get();
var originalVal = config.ComboBoxItemsPopulatedWithoutDropDownOpen;
config.ComboBoxItemsPopulatedWithoutDropDownOpen = false;
try
{
// Act
#pragma warning disable 168
// Required to force the expansion of the combobox
// ReSharper disable once UnusedVariable
var items = ComboBoxUnderTest.Items;
#pragma warning restore 168
// Assert
var expansionState = ComboBoxUnderTest.ExpandCollapseState;
// The combobox should have been collapsed after the items were retrieved
Assert.That(expansionState, Is.EqualTo(ExpandCollapseState.Collapsed));
}
finally
{
config.ComboBoxItemsPopulatedWithoutDropDownOpen = originalVal;
}
}
[Test]
public void CanSelectByIndexTest()
{
ComboBoxUnderTest.Select(4);
Assert.That(ComboBoxUnderTest.SelectedItemText, Is.EqualTo("Test5"));
}
[Test]
public void CanSelectItemAtBottomOfListTest()
{
ComboBoxUnderTest.Select("Test19");
Assert.That(ComboBoxUnderTest.SelectedItemText, Is.EqualTo("Test19"));
}
[Test]
public void CanGetAllItemsTest()
{
var items = ComboBoxUnderTest.Items;
Assert.That(items, Has.Count.EqualTo(21));
Assert.That(items[0].Name, Is.EqualTo("Test"));
Assert.That(items[19].Name, Is.EqualTo("Test20"));
}
[Test]
public void CanSelectItemAtTopOfListTest()
{
ComboBoxUnderTest.Select("Test2");
Assert.That(ComboBoxUnderTest.SelectedItemText, Is.EqualTo("Test2"));
}
[Test]
public void CanSelectReallyLongTextTest()
{
ComboBoxUnderTest.Select("ReallyReallyReallyLongTextHere");
Assert.That(ComboBoxUnderTest.SelectedItem.Text, Is.EqualTo("ReallyReallyReallyLongTextHere"));
}
[Test]
public void SetValueTest()
{
ComboBoxUnderTest.SetValue("Test4");
Assert.That(ComboBoxUnderTest.SelectedItem.Text, Is.EqualTo("Test4"));
}
}
}