Skip to content

Commit 39fe384

Browse files
committed
Updated TTB Xaml Islands tests.
1 parent d446586 commit 39fe384

File tree

3 files changed

+63
-12
lines changed

3 files changed

+63
-12
lines changed

Microsoft.Toolkit.Uwp.UI.Controls/TokenizingTextBox/TokenizingTextBox.cs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,12 @@ private void TokenizingTextBox_ItemClick(object sender, ItemClickEventArgs e)
9999

100100
private void TokenizingTextBox_PreviewKeyUp(object sender, KeyRoutedEventArgs e)
101101
{
102-
switch (e.Key)
102+
TokenizingTextBox_PreviewKeyUp(e.Key);
103+
}
104+
105+
internal void TokenizingTextBox_PreviewKeyUp(VirtualKey key)
106+
{
107+
switch (key)
103108
{
104109
case VirtualKey.Escape:
105110
{
@@ -123,15 +128,20 @@ private void FocusPrimaryAutoSuggestBox()
123128
}
124129

125130
private async void TokenizingTextBox_PreviewKeyDown(object sender, KeyRoutedEventArgs e)
131+
{
132+
e.Handled = await TokenizingTextBox_PreviewKeyDown(e.Key);
133+
}
134+
135+
internal async Task<bool> TokenizingTextBox_PreviewKeyDown(VirtualKey key)
126136
{
127137
// Global handlers on control regardless if focused on item or in textbox.
128-
switch (e.Key)
138+
switch (key)
129139
{
130140
case VirtualKey.C:
131141
if (IsControlPressed)
132142
{
133143
CopySelectedToClipboard();
134-
e.Handled = true;
144+
return true;
135145
}
136146

137147
break;
@@ -148,24 +158,24 @@ private async void TokenizingTextBox_PreviewKeyDown(object sender, KeyRoutedEven
148158
break;
149159

150160
// For moving between tokens
151-
case Windows.System.VirtualKey.Left:
152-
e.Handled = MoveFocusAndSelection(MoveDirection.Previous);
153-
break;
161+
case VirtualKey.Left:
162+
return MoveFocusAndSelection(MoveDirection.Previous);
154163

155-
case Windows.System.VirtualKey.Right:
156-
e.Handled = MoveFocusAndSelection(MoveDirection.Next);
157-
break;
164+
case VirtualKey.Right:
165+
return MoveFocusAndSelection(MoveDirection.Next);
158166

159167
case VirtualKey.A:
160168
// modify the select-all behaviour to ensure the text in the edit box gets selected.
161169
if (IsControlPressed)
162170
{
163171
this.SelectAllTokensAndText();
164-
e.Handled = true;
172+
return true;
165173
}
166174

167175
break;
168176
}
177+
178+
return false;
169179
}
170180

171181
/// <inheritdoc/>

UnitTests/UnitTests.XamlIslands.UWPApp/XamlIslandsTest_TextToolbar.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ public async Task TextToobar_PopupShowsInCorrectXamlRoot()
6565
{
6666
await App.Dispatcher.ExecuteOnUIThreadAsync(async () =>
6767
{
68+
await Task.Delay(500);
69+
6870
var args = new ShortcutKeyRequestArgs(Windows.System.VirtualKey.K, false, null);
6971

7072
_textToolbar.GetDefaultButton(Microsoft.Toolkit.Uwp.UI.Controls.TextToolbarButtons.ButtonType.Link).ShortcutRequested(ref args);

UnitTests/UnitTests.XamlIslands.UWPApp/XamlIslandsTest_TokenizingTextBox.cs

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
using Microsoft.Toolkit.Uwp.UI;
99
using Microsoft.Toolkit.Uwp.UI.Controls;
1010
using Microsoft.VisualStudio.TestTools.UnitTesting;
11-
using Windows.UI.Xaml;
1211
using Windows.UI.Xaml.Controls;
1312
using Windows.UI.Xaml.Markup;
1413

@@ -101,6 +100,35 @@ await App.Dispatcher.ExecuteOnUIThreadAsync(() =>
101100
_tokenizingTextBox.SuggestedItemsSource = _acv;
102101

103102
TestsPage.Instance.SetMainTestContent(_tokenizingTextBox);
103+
104+
_tokenizingTextBox.AddTokenItem(_samples[0], true);
105+
_tokenizingTextBox.AddTokenItem(_samples[1], true);
106+
_tokenizingTextBox.AddTokenItem(_samples[2], true);
107+
});
108+
}
109+
110+
[TestMethod]
111+
public async Task TokenizingTextBox_GetFocusedElement_RemoveAllSelectedTokens()
112+
{
113+
await App.Dispatcher.ExecuteOnUIThreadAsync(async () =>
114+
{
115+
await Task.Delay(500);
116+
117+
_tokenizingTextBox.SelectedIndex = 1;
118+
119+
await Task.Delay(500);
120+
121+
await _tokenizingTextBox.TokenizingTextBox_PreviewKeyDown(Windows.System.VirtualKey.Left);
122+
123+
await Task.Delay(500);
124+
125+
Assert.AreEqual(4, _tokenizingTextBox.Items.Count);
126+
127+
await _tokenizingTextBox.RemoveAllSelectedTokens();
128+
129+
await Task.Delay(500);
130+
131+
Assert.AreEqual(3, _tokenizingTextBox.Items.Count);
104132
});
105133
}
106134

@@ -109,7 +137,18 @@ public async Task TokenizingTextBox_PopupShowsInCorrectXamlRoot()
109137
{
110138
await App.Dispatcher.ExecuteOnUIThreadAsync(async () =>
111139
{
112-
await Task.Delay(10000);
140+
await Task.Delay(500);
141+
142+
_tokenizingTextBox.SelectedIndex = 1;
143+
144+
await Task.Delay(500);
145+
146+
await _tokenizingTextBox.TokenizingTextBox_PreviewKeyDown(Windows.System.VirtualKey.Left);
147+
148+
var tokenizingTextBoxItem = _tokenizingTextBox.ContainerFromItem(_tokenizingTextBox.SelectedItem) as TokenizingTextBoxItem;
149+
tokenizingTextBoxItem.ContextFlyout.ShowAt(tokenizingTextBoxItem);
150+
151+
await Task.Delay(1000);
113152
});
114153
}
115154
}

0 commit comments

Comments
 (0)