|
1 |
| -// Licensed to the .NET Foundation under one or more agreements. |
| 1 | +// Licensed to the .NET Foundation under one or more agreements. |
2 | 2 | // The .NET Foundation licenses this file to you under the MIT license.
|
3 | 3 | // See the LICENSE file in the project root for more information.
|
4 | 4 |
|
| 5 | +using System.Collections.Generic; |
5 | 6 | using System.Collections.ObjectModel;
|
| 7 | +using System.Linq; |
6 | 8 | using System.Threading.Tasks;
|
7 | 9 | using Windows.UI.Xaml.Automation;
|
8 | 10 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
@@ -50,6 +52,45 @@ await App.DispatcherQueue.EnqueueAsync(async () =>
|
50 | 52 | });
|
51 | 53 | }
|
52 | 54 |
|
| 55 | + [TestMethod] |
| 56 | + public async Task ShouldReturnTokensForTokenizingTextBoxAutomationPeerAsync() |
| 57 | + { |
| 58 | + await App.DispatcherQueue.EnqueueAsync(async () => |
| 59 | + { |
| 60 | + var items = new ObservableCollection<TokenizingTextBoxTestItem> |
| 61 | + { |
| 62 | + new() { Title = "Hello" }, new() { Title = "World" } |
| 63 | + }; |
| 64 | + |
| 65 | + var tokenizingTextBox = new TokenizingTextBox { ItemsSource = items }; |
| 66 | + |
| 67 | + await SetTestContentAsync(tokenizingTextBox); |
| 68 | + |
| 69 | + tokenizingTextBox |
| 70 | + .SelectAllTokensAndText(); // Will be 3 items due to the `AndText` that will select an empty text item. |
| 71 | + |
| 72 | + var tokenizingTextBoxAutomationPeer = |
| 73 | + FrameworkElementAutomationPeer.CreatePeerForElement(tokenizingTextBox) as |
| 74 | + TokenizingTextBoxAutomationPeer; |
| 75 | + |
| 76 | + Assert.IsNotNull( |
| 77 | + tokenizingTextBoxAutomationPeer, |
| 78 | + "Verify that the AutomationPeer is TokenizingTextBoxAutomationPeer."); |
| 79 | + |
| 80 | + var selectedItems = tokenizingTextBoxAutomationPeer |
| 81 | + .GetChildren() |
| 82 | + .Cast<ListViewItemAutomationPeer>() |
| 83 | + .Select(peer => peer.Owner as TokenizingTextBoxItem) |
| 84 | + .Select(item => item?.Content as TokenizingTextBoxTestItem) |
| 85 | + .ToList(); |
| 86 | + |
| 87 | + Assert.AreEqual(3, selectedItems.Count); |
| 88 | + Assert.AreEqual(items[0], selectedItems[0]); |
| 89 | + Assert.AreEqual(items[1], selectedItems[1]); |
| 90 | + Assert.IsNull(selectedItems[2]); // The 3rd item is the empty text item. |
| 91 | + }); |
| 92 | + } |
| 93 | + |
53 | 94 | [TestMethod]
|
54 | 95 | public async Task ShouldThrowElementNotEnabledExceptionIfValueSetWhenDisabled()
|
55 | 96 | {
|
|
0 commit comments