|
1 |
| -using System.ComponentModel; |
| 1 | +using System.Collections; |
| 2 | +using System.ComponentModel; |
2 | 3 | using MaterialDesignThemes.UITests.Samples.AutoSuggestBoxes;
|
3 | 4 | using MaterialDesignThemes.UITests.Samples.AutoSuggestTextBoxes;
|
4 | 5 | using Xunit.Sdk;
|
@@ -159,6 +160,47 @@ public async Task AutoSuggestBox_MovesFocusToNextElement_WhenPopupIsClosed()
|
159 | 160 | recorder.Success();
|
160 | 161 | }
|
161 | 162 |
|
| 163 | + [Fact] |
| 164 | + [Description("Issue 3815")] |
| 165 | + public async Task AutoSuggestBox_KeysUpAndDown_WrapAround() |
| 166 | + { |
| 167 | + await using var recorder = new TestRecorder(App); |
| 168 | + |
| 169 | + //Arrange |
| 170 | + IVisualElement<AutoSuggestBox> suggestBox = (await LoadUserControl<AutoSuggestTextBoxWithTemplate>()).As<AutoSuggestBox>(); |
| 171 | + IVisualElement<Popup> popup = await suggestBox.GetElement<Popup>(); |
| 172 | + IVisualElement<ListBox> suggestionListBox = await popup.GetElement<ListBox>(); |
| 173 | + |
| 174 | + const int delay = 50; |
| 175 | + |
| 176 | + //Act & Assert |
| 177 | + await suggestBox.MoveKeyboardFocus(); |
| 178 | + await suggestBox.SendInput(new KeyboardInput("e")); |
| 179 | + await Task.Delay(delay); |
| 180 | + |
| 181 | + static int? GetSuggestionCount(AutoSuggestBox autoSuggestBox) |
| 182 | + { |
| 183 | + int? count = autoSuggestBox.Suggestions?.OfType<object>().Count(); |
| 184 | + return count; |
| 185 | + } |
| 186 | + |
| 187 | + int itemCount = await suggestBox.RemoteExecute(GetSuggestionCount) ?? 0; |
| 188 | + |
| 189 | + //Assert that initially the first item is selected |
| 190 | + int selectedIndex = await suggestionListBox.GetSelectedIndex(); |
| 191 | + Assert.Equal(0, selectedIndex); |
| 192 | + await Task.Delay(delay); |
| 193 | + |
| 194 | + //Assert that the last item is selected after pressing ArrowUp |
| 195 | + await suggestBox.SendInput(new KeyboardInput(Key.Up)); |
| 196 | + Assert.Equal(itemCount - 1, await suggestionListBox.GetSelectedIndex()); |
| 197 | + await Task.Delay(delay); |
| 198 | + |
| 199 | + //Assert that the first item is selected after pressing ArrowDown |
| 200 | + await suggestBox.SendInput(new KeyboardInput(Key.Down)); |
| 201 | + Assert.Equal(0, await suggestionListBox.GetSelectedIndex()); |
| 202 | + } |
| 203 | + |
162 | 204 | private static async Task AssertExists(IVisualElement<ListBox> suggestionListBox, string text, bool existsOrNotCheck = true)
|
163 | 205 | {
|
164 | 206 | try
|
|
0 commit comments