Skip to content

Commit 21e5a35

Browse files
Add test to check changing the Text of a TokenizingTextBox
1 parent ac1723d commit 21e5a35

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

UnitTests/UnitTests.UWP/UI/Controls/Test_TokenizingTextBox_General.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Microsoft.Toolkit.Uwp;
66
using Microsoft.Toolkit.Uwp.UI;
77
using Microsoft.Toolkit.Uwp.UI.Controls;
8+
using Microsoft.Toolkit.Uwp.UI.Helpers;
89
using Microsoft.VisualStudio.TestTools.UnitTesting;
910
using Microsoft.VisualStudio.TestTools.UnitTesting.AppContainer;
1011
using System.Threading.Tasks;
@@ -201,6 +202,51 @@ await App.DispatcherQueue.EnqueueAsync(async () =>
201202
});
202203
}
203204

205+
[TestCategory("Test_TokenizingTextBox_General")]
206+
[TestMethod]
207+
public async Task Test_ChangeText()
208+
{
209+
await App.DispatcherQueue.EnqueueAsync(async () =>
210+
{
211+
var treeRoot = XamlReader.Load(
212+
@"<Page
213+
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
214+
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""
215+
xmlns:controls=""using:Microsoft.Toolkit.Uwp.UI.Controls"">
216+
217+
<controls:TokenizingTextBox x:Name=""tokenboxname""/>
218+
219+
</Page>") as FrameworkElement;
220+
221+
Assert.IsNotNull(treeRoot, "Could not load XAML tree.");
222+
223+
await SetTestContentAsync(treeRoot);
224+
225+
var tokenBox = treeRoot.FindChild("tokenboxname") as TokenizingTextBox;
226+
227+
Assert.IsNotNull(tokenBox, "Could not find TokenizingTextBox in tree.");
228+
Assert.AreEqual(1, tokenBox.Items.Count, "Token default items failed"); // AutoSuggestBox
229+
230+
// Test initial value of property
231+
Assert.AreEqual(string.Empty, tokenBox.Text, "Text should start as empty.");
232+
233+
// Reach into AutoSuggestBox's text to check it was set properly
234+
var autoSuggestBox = tokenBox.FindDescendant<AutoSuggestBox>();
235+
236+
Assert.IsNotNull(autoSuggestBox, "Could not find inner autosuggestbox");
237+
Assert.AreEqual(string.Empty, autoSuggestBox.Text, "Inner text not set based on initial value of TokenizingTextBox");
238+
239+
// Change Text
240+
tokenBox.Text = "New Text";
241+
242+
// Wait for update
243+
await CompositionTargetHelper.ExecuteAfterCompositionRenderingAsync(() => { });
244+
245+
Assert.AreEqual("New Text", tokenBox.Text, "Text should be changed now.");
246+
Assert.AreEqual("New Text", autoSuggestBox.Text, "Inner text not set based on value of TokenizingTextBox");
247+
});
248+
}
249+
204250
[TestCategory("Test_TokenizingTextBox_General")]
205251
[TestMethod]
206252
public async Task Test_ClearText()

0 commit comments

Comments
 (0)