|
5 | 5 | using Microsoft.Toolkit.Uwp;
|
6 | 6 | using Microsoft.Toolkit.Uwp.UI;
|
7 | 7 | using Microsoft.Toolkit.Uwp.UI.Controls;
|
| 8 | +using Microsoft.Toolkit.Uwp.UI.Helpers; |
8 | 9 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
9 | 10 | using Microsoft.VisualStudio.TestTools.UnitTesting.AppContainer;
|
10 | 11 | using System.Threading.Tasks;
|
@@ -201,6 +202,51 @@ await App.DispatcherQueue.EnqueueAsync(async () =>
|
201 | 202 | });
|
202 | 203 | }
|
203 | 204 |
|
| 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 | + |
204 | 250 | [TestCategory("Test_TokenizingTextBox_General")]
|
205 | 251 | [TestMethod]
|
206 | 252 | public async Task Test_ClearText()
|
|
0 commit comments