From 1758c71101feab9d921d0f5579813ba8db770ce6 Mon Sep 17 00:00:00 2001
From: michael-hawker <24302614+michael-hawker@users.noreply.github.com>
Date: Mon, 17 Oct 2022 16:51:26 -0700
Subject: [PATCH] Add test to check changing the Text of a TokenizingTextBox
---
.../Test_TokenizingTextBox_General.cs | 46 +++++++++++++++++++
1 file changed, 46 insertions(+)
diff --git a/UnitTests/UnitTests.UWP/UI/Controls/Test_TokenizingTextBox_General.cs b/UnitTests/UnitTests.UWP/UI/Controls/Test_TokenizingTextBox_General.cs
index aa908ac5384..2fef71b8b57 100644
--- a/UnitTests/UnitTests.UWP/UI/Controls/Test_TokenizingTextBox_General.cs
+++ b/UnitTests/UnitTests.UWP/UI/Controls/Test_TokenizingTextBox_General.cs
@@ -5,6 +5,7 @@
using Microsoft.Toolkit.Uwp;
using Microsoft.Toolkit.Uwp.UI;
using Microsoft.Toolkit.Uwp.UI.Controls;
+using Microsoft.Toolkit.Uwp.UI.Helpers;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.VisualStudio.TestTools.UnitTesting.AppContainer;
using System.Threading.Tasks;
@@ -201,6 +202,51 @@ await App.DispatcherQueue.EnqueueAsync(async () =>
});
}
+ [TestCategory("Test_TokenizingTextBox_General")]
+ [TestMethod]
+ public async Task Test_ChangeText()
+ {
+ await App.DispatcherQueue.EnqueueAsync(async () =>
+ {
+ var treeRoot = XamlReader.Load(
+@"
+
+
+
+") as FrameworkElement;
+
+ Assert.IsNotNull(treeRoot, "Could not load XAML tree.");
+
+ await SetTestContentAsync(treeRoot);
+
+ var tokenBox = treeRoot.FindChild("tokenboxname") as TokenizingTextBox;
+
+ Assert.IsNotNull(tokenBox, "Could not find TokenizingTextBox in tree.");
+ Assert.AreEqual(1, tokenBox.Items.Count, "Token default items failed"); // AutoSuggestBox
+
+ // Test initial value of property
+ Assert.AreEqual(string.Empty, tokenBox.Text, "Text should start as empty.");
+
+ // Reach into AutoSuggestBox's text to check it was set properly
+ var autoSuggestBox = tokenBox.FindDescendant();
+
+ Assert.IsNotNull(autoSuggestBox, "Could not find inner autosuggestbox");
+ Assert.AreEqual(string.Empty, autoSuggestBox.Text, "Inner text not set based on initial value of TokenizingTextBox");
+
+ // Change Text
+ tokenBox.Text = "New Text";
+
+ // Wait for update
+ await CompositionTargetHelper.ExecuteAfterCompositionRenderingAsync(() => { });
+
+ Assert.AreEqual("New Text", tokenBox.Text, "Text should be changed now.");
+ Assert.AreEqual("New Text", autoSuggestBox.Text, "Inner text not set based on value of TokenizingTextBox");
+ });
+ }
+
[TestCategory("Test_TokenizingTextBox_General")]
[TestMethod]
public async Task Test_ClearText()