Skip to content

Commit 5844ec0

Browse files
committed
Added tests for TokenizingTextBoxAutomationPeer
1 parent abb3d6b commit 5844ec0

File tree

3 files changed

+60
-16
lines changed

3 files changed

+60
-16
lines changed

Microsoft.Toolkit.Uwp.UI.Controls.Input/TokenizingTextBox/TokenizingTextBoxAutomationPeer.cs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -70,22 +70,6 @@ protected override string GetNameCore()
7070
return base.GetNameCore();
7171
}
7272

73-
/// <summary>
74-
/// Gets the control pattern that is associated with the specified Windows.UI.Xaml.Automation.Peers.PatternInterface.
75-
/// </summary>
76-
/// <param name="patternInterface">A value from the Windows.UI.Xaml.Automation.Peers.PatternInterface enumeration.</param>
77-
/// <returns>The object that supports the specified pattern, or null if unsupported.</returns>
78-
protected override object GetPatternCore(PatternInterface patternInterface)
79-
{
80-
switch (patternInterface)
81-
{
82-
case PatternInterface.Selection:
83-
return this;
84-
}
85-
86-
return base.GetPatternCore(patternInterface);
87-
}
88-
8973
/// <summary>
9074
/// Gets the collection of elements that are represented in the UI Automation tree as immediate
9175
/// child elements of the automation peer.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System.Collections.ObjectModel;
6+
using System.Threading.Tasks;
7+
using Windows.UI.Xaml.Automation;
8+
using Microsoft.VisualStudio.TestTools.UnitTesting;
9+
using Windows.UI.Xaml.Automation.Peers;
10+
using Microsoft.Toolkit.Uwp;
11+
using Microsoft.Toolkit.Uwp.UI.Automation.Peers;
12+
using Microsoft.Toolkit.Uwp.UI.Controls;
13+
14+
namespace UnitTests.UWP.UI.Controls
15+
{
16+
[TestClass]
17+
[TestCategory("Test_TokenizingTextBox")]
18+
public class Test_TokenizingTextBox_AutomationPeer : VisualUITestBase
19+
{
20+
[TestMethod]
21+
public async Task ShouldConfigureTokenizingTextBoxAutomationPeerAsync()
22+
{
23+
await App.DispatcherQueue.EnqueueAsync(async () =>
24+
{
25+
const string expectedAutomationName = "MyAutomationName";
26+
const string expectedName = "MyName";
27+
28+
var items = new ObservableCollection<TokenizingTextBoxTestItem> { new() { Title = "Hello" }, new() { Title = "World" } };
29+
30+
var tokenizingTextBox = new TokenizingTextBox { ItemsSource = items };
31+
32+
await SetTestContentAsync(tokenizingTextBox);
33+
34+
var tokenizingTextBoxAutomationPeer =
35+
FrameworkElementAutomationPeer.CreatePeerForElement(tokenizingTextBox) as TokenizingTextBoxAutomationPeer;
36+
37+
Assert.IsNotNull(tokenizingTextBoxAutomationPeer, "Verify that the AutomationPeer is TokenizingTextBoxAutomationPeer.");
38+
39+
// Asserts the automation peer name based on the Automation Property Name value.
40+
tokenizingTextBox.SetValue(AutomationProperties.NameProperty, expectedAutomationName);
41+
Assert.IsTrue(tokenizingTextBoxAutomationPeer.GetName().Contains(expectedAutomationName), "Verify that the UIA name contains the given AutomationProperties.Name of the TokenizingTextBox.");
42+
43+
// Asserts the automation peer name based on the element Name property.
44+
tokenizingTextBox.Name = expectedName;
45+
Assert.IsTrue(tokenizingTextBoxAutomationPeer.GetName().Contains(expectedName), "Verify that the UIA name contains the given Name of the TokenizingTextBox.");
46+
});
47+
}
48+
49+
public class TokenizingTextBoxTestItem
50+
{
51+
public string Title { get; set; }
52+
53+
public override string ToString()
54+
{
55+
return Title;
56+
}
57+
}
58+
}
59+
}

UnitTests/UnitTests.UWP/UnitTests.UWP.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@
200200
<Compile Include="UI\Controls\Test_RadialGauge.cs" />
201201
<Compile Include="UI\Controls\Test_TextToolbar_Localization.cs" />
202202
<Compile Include="UI\Controls\Test_InfiniteCanvas_Regression.cs" />
203+
<Compile Include="UI\Controls\Test_TokenizingTextBox_AutomationPeer.cs" />
203204
<Compile Include="UI\Controls\Test_TokenizingTextBox_General.cs" />
204205
<Compile Include="UI\Controls\Test_TokenizingTextBox_InterspersedCollection.cs" />
205206
<Compile Include="UI\Controls\Test_ListDetailsView.cs" />

0 commit comments

Comments
 (0)