Skip to content

Commit 0224c68

Browse files
committed
added a first test case
1 parent 47e1c90 commit 0224c68

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

tests/MaterialDesignThemes.UITests/WPF/AutoSuggestBoxes/AutoSuggestTextBoxTests.cs

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using MaterialDesignThemes.UITests.Samples.AutoSuggestBoxes;
1+
using System.ComponentModel;
2+
using MaterialDesignThemes.UITests.Samples.AutoSuggestBoxes;
23
using MaterialDesignThemes.UITests.Samples.AutoSuggestTextBoxes;
34
using Xunit.Sdk;
45

@@ -47,7 +48,7 @@ public async Task CanFilterItems_WithSuggestionsAndDisplayMember_FiltersSuggesti
4748
public async Task CanChoiceItem_FromTheSuggestions_AssertTheTextUpdated()
4849
{
4950
await using var recorder = new TestRecorder(App);
50-
51+
5152
//Arrange
5253
IVisualElement<AutoSuggestBox> suggestBox = (await LoadUserControl<AutoSuggestTextBoxWithTemplate>()).As<AutoSuggestBox>();
5354
IVisualElement<Popup> popup = await suggestBox.GetElement<Popup>();
@@ -122,6 +123,41 @@ public async Task CanFilterItems_WithCollectionView_FiltersSuggestions()
122123
recorder.Success();
123124
}
124125

126+
[Fact]
127+
[Description("Issue 3761")]
128+
public async Task AutoSuggestBox_MovesFocusToNextElement_WhenPopupIsClosed()
129+
{
130+
await using var recorder = new TestRecorder(App);
131+
132+
// Arrange
133+
string xaml = """
134+
<StackPanel>
135+
<local:AutoSuggestTextBoxWithCollectionView x:Name="AutoSuggestBoxSample" />
136+
<TextBox x:Name="NextTextBox" />
137+
</StackPanel>
138+
""";
139+
140+
IVisualElement<StackPanel> stackPanel = await LoadXaml<StackPanel>(xaml, ("local", typeof(AutoSuggestTextBoxWithCollectionView)));
141+
var suggestBoxSample = await stackPanel.GetElement<AutoSuggestTextBoxWithCollectionView>("AutoSuggestBoxSample");
142+
IVisualElement<AutoSuggestBox> suggestBox = await suggestBoxSample.GetElement<AutoSuggestBox>();
143+
IVisualElement<TextBox> nextTextBox = await stackPanel.GetElement<TextBox>("NextTextBox");
144+
145+
// Act
146+
await suggestBox.MoveKeyboardFocus();
147+
await Task.Delay(50);
148+
await suggestBox.SendInput(new KeyboardInput("B"));
149+
await Task.Delay(50);
150+
await suggestBox.SendInput(new KeyboardInput(Key.Escape)); // Close the popup
151+
await Task.Delay(50);
152+
await suggestBox.SendInput(new KeyboardInput(Key.Tab)); // Press TAB to focus the next element (the TextBox)
153+
await Task.Delay(50);
154+
155+
// Assert
156+
Assert.True(await nextTextBox.GetIsFocused());
157+
158+
recorder.Success();
159+
}
160+
125161
private static async Task AssertExists(IVisualElement<ListBox> suggestionListBox, string text, bool existsOrNotCheck = true)
126162
{
127163
try

0 commit comments

Comments
 (0)