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 https://github.com/CommunityToolkit/WindowsCommunityToolkit/issues/4749
This commit is contained in:
michael-hawker 2022-10-17 14:36:42 -07:00 коммит произвёл Michael Hawker MSFT (XAML Llama)
Родитель 39925b9982
Коммит 9f018956ea
2 изменённых файлов: 79 добавлений и 1 удалений

Просмотреть файл

@ -314,7 +314,6 @@
ItemsSource="{Binding Path=Owner.SuggestedItemsSource, RelativeSource={RelativeSource Mode=TemplatedParent}}"
PlaceholderText="{Binding Path=Owner.PlaceholderText, RelativeSource={RelativeSource Mode=TemplatedParent}}"
Style="{StaticResource SystemAutoSuggestBoxStyle}"
Text="{Binding Text, Mode=TwoWay}"
TextBoxStyle="{StaticResource TokenizingTextBoxTextBoxStyle}"/>
</ControlTemplate>
</Setter.Value>

Просмотреть файл

@ -164,5 +164,84 @@ namespace UnitTests.UWP.UI.Controls
Assert.AreEqual("TokenItem1", tokenBox.Items[0]);
});
}
[TestCategory("Test_TokenizingTextBox_General")]
[TestMethod]
public async Task Test_SetInitialText()
{
await App.DispatcherQueue.EnqueueAsync(async () =>
{
var treeRoot = XamlReader.Load(
@"<Page
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""
xmlns:controls=""using:Microsoft.Toolkit.Uwp.UI.Controls"">
<controls:TokenizingTextBox x:Name=""tokenboxname"" Text=""Some Text""/>
</Page>") 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("Some Text", tokenBox.Text, "Token text not equal to starting value.");
// Reach into AutoSuggestBox's text to check it was set properly
var autoSuggestBox = tokenBox.FindDescendant<AutoSuggestBox>();
Assert.IsNotNull(autoSuggestBox, "Could not find inner autosuggestbox");
Assert.AreEqual("Some Text", autoSuggestBox.Text, "Inner text not set based on initial value of TokenizingTextBox");
});
}
[TestCategory("Test_TokenizingTextBox_General")]
[TestMethod]
public async Task Test_ClearText()
{
await App.DispatcherQueue.EnqueueAsync(async () =>
{
var treeRoot = XamlReader.Load(
@"<Page
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""
xmlns:controls=""using:Microsoft.Toolkit.Uwp.UI.Controls"">
<controls:TokenizingTextBox x:Name=""tokenboxname"" Text=""Some Text""/>
</Page>") 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
// TODO: When in Labs, we should inject text via keyboard here vs. setting an initial value (more independent of SetInitialText test).
// Test initial value of property
Assert.AreEqual("Some Text", tokenBox.Text, "Token text not equal to starting value.");
// Reach into AutoSuggestBox's text to check it was set properly
var autoSuggestBox = tokenBox.FindDescendant<AutoSuggestBox>();
Assert.IsNotNull(autoSuggestBox, "Could not find inner autosuggestbox");
Assert.AreEqual("Some Text", autoSuggestBox.Text, "Inner text not set based on initial value of TokenizingTextBox");
await tokenBox.ClearAsync();
Assert.AreEqual(string.Empty, autoSuggestBox.Text, "Inner text was not cleared.");
Assert.AreEqual(string.Empty, tokenBox.Text, "TokenizingTextBox text was not cleared.");
});
}
}
}