Skip to content

Commit 9f01895

Browse files
Remove invalid binding - add failing tests to show problems for #4749
Think we maybe used to bind to the text directly, but there's no Text property directly on the TokenizingTextBoxItem, so this binding is meaningless. It doesn't effect the behavior of the textbox in practical usage, but somehow was doing something which was masking the problem for us to be able to detect within a test case. Removing it to reduce confusion. The text sync between the parent TokenizingTextBox collection of items (and the current edit) and the item is maintained through code-behind with text changing events. Though work is being done to resolve issues in this sync process. See issue #4749
1 parent 39925b9 commit 9f01895

File tree

2 files changed

+79
-1
lines changed

2 files changed

+79
-1
lines changed

Microsoft.Toolkit.Uwp.UI.Controls.Input/TokenizingTextBox/TokenizingTextBoxItem.AutoSuggestBox.xaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,6 @@
314314
ItemsSource="{Binding Path=Owner.SuggestedItemsSource, RelativeSource={RelativeSource Mode=TemplatedParent}}"
315315
PlaceholderText="{Binding Path=Owner.PlaceholderText, RelativeSource={RelativeSource Mode=TemplatedParent}}"
316316
Style="{StaticResource SystemAutoSuggestBoxStyle}"
317-
Text="{Binding Text, Mode=TwoWay}"
318317
TextBoxStyle="{StaticResource TokenizingTextBoxTextBoxStyle}"/>
319318
</ControlTemplate>
320319
</Setter.Value>

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

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,5 +164,84 @@ await App.DispatcherQueue.EnqueueAsync(async () =>
164164
Assert.AreEqual("TokenItem1", tokenBox.Items[0]);
165165
});
166166
}
167+
168+
[TestCategory("Test_TokenizingTextBox_General")]
169+
[TestMethod]
170+
public async Task Test_SetInitialText()
171+
{
172+
await App.DispatcherQueue.EnqueueAsync(async () =>
173+
{
174+
var treeRoot = XamlReader.Load(
175+
@"<Page
176+
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
177+
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""
178+
xmlns:controls=""using:Microsoft.Toolkit.Uwp.UI.Controls"">
179+
180+
<controls:TokenizingTextBox x:Name=""tokenboxname"" Text=""Some Text""/>
181+
182+
</Page>") as FrameworkElement;
183+
184+
Assert.IsNotNull(treeRoot, "Could not load XAML tree.");
185+
186+
await SetTestContentAsync(treeRoot);
187+
188+
var tokenBox = treeRoot.FindChild("tokenboxname") as TokenizingTextBox;
189+
190+
Assert.IsNotNull(tokenBox, "Could not find TokenizingTextBox in tree.");
191+
Assert.AreEqual(1, tokenBox.Items.Count, "Token default items failed"); // AutoSuggestBox
192+
193+
// Test initial value of property
194+
Assert.AreEqual("Some Text", tokenBox.Text, "Token text not equal to starting value.");
195+
196+
// Reach into AutoSuggestBox's text to check it was set properly
197+
var autoSuggestBox = tokenBox.FindDescendant<AutoSuggestBox>();
198+
199+
Assert.IsNotNull(autoSuggestBox, "Could not find inner autosuggestbox");
200+
Assert.AreEqual("Some Text", autoSuggestBox.Text, "Inner text not set based on initial value of TokenizingTextBox");
201+
});
202+
}
203+
204+
[TestCategory("Test_TokenizingTextBox_General")]
205+
[TestMethod]
206+
public async Task Test_ClearText()
207+
{
208+
await App.DispatcherQueue.EnqueueAsync(async () =>
209+
{
210+
var treeRoot = XamlReader.Load(
211+
@"<Page
212+
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
213+
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""
214+
xmlns:controls=""using:Microsoft.Toolkit.Uwp.UI.Controls"">
215+
216+
<controls:TokenizingTextBox x:Name=""tokenboxname"" Text=""Some Text""/>
217+
218+
</Page>") as FrameworkElement;
219+
220+
Assert.IsNotNull(treeRoot, "Could not load XAML tree.");
221+
222+
await SetTestContentAsync(treeRoot);
223+
224+
var tokenBox = treeRoot.FindChild("tokenboxname") as TokenizingTextBox;
225+
226+
Assert.IsNotNull(tokenBox, "Could not find TokenizingTextBox in tree.");
227+
Assert.AreEqual(1, tokenBox.Items.Count, "Token default items failed"); // AutoSuggestBox
228+
229+
// TODO: When in Labs, we should inject text via keyboard here vs. setting an initial value (more independent of SetInitialText test).
230+
231+
// Test initial value of property
232+
Assert.AreEqual("Some Text", tokenBox.Text, "Token text not equal to starting value.");
233+
234+
// Reach into AutoSuggestBox's text to check it was set properly
235+
var autoSuggestBox = tokenBox.FindDescendant<AutoSuggestBox>();
236+
237+
Assert.IsNotNull(autoSuggestBox, "Could not find inner autosuggestbox");
238+
Assert.AreEqual("Some Text", autoSuggestBox.Text, "Inner text not set based on initial value of TokenizingTextBox");
239+
240+
await tokenBox.ClearAsync();
241+
242+
Assert.AreEqual(string.Empty, autoSuggestBox.Text, "Inner text was not cleared.");
243+
Assert.AreEqual(string.Empty, tokenBox.Text, "TokenizingTextBox text was not cleared.");
244+
});
245+
}
167246
}
168247
}

0 commit comments

Comments
 (0)