-
Notifications
You must be signed in to change notification settings - Fork 691
/
Given_TreeView.cs
73 lines (60 loc) · 2.24 KB
/
Given_TreeView.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using System;
using System.Linq;
using Windows.UI;
using System.Threading.Tasks;
using Private.Infrastructure;
using Uno.UI.RuntimeTests.Helpers;
using Windows.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TreeView = Microsoft.UI.Xaml.Controls.TreeView;
using TreeViewItem = Microsoft.UI.Xaml.Controls.TreeViewItem;
using Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Controls.TreeViewTests;
using System.Collections.Generic;
namespace Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Controls;
[TestClass]
[RunsOnUIThread]
public class Given_TreeView
{
// Test method that create a tree of three nested items from a itemssource and that will open and close a single treeview item twice and validate that the container is still containing the same property values
[TestMethod]
public async Task When_Open_Close_Twice()
{
var SUT = new When_Open_Close_Twice();
TestServices.WindowHelper.WindowContent = SUT;
var root = new MyNode();
root.Name = "root";
root.Children = new List<MyNode>();
var child1 = new MyNode { Name = "Child 1" };
var child2 = new MyNode { Name = "Child 2" };
root.Children.Add(child1);
root.Children.Add(child2);
SUT.myTree.ItemsSource = new[] { root };
await TestServices.WindowHelper.WaitForIdle();
var rootNode = (TreeViewItem)SUT.FindName("root");
rootNode.IsExpanded = true;
await TestServices.WindowHelper.WaitForIdle();
var child1Node = (TreeViewItem)SUT.FindName("Child 1");
Assert.IsNotNull(child1Node);
Assert.AreEqual("Child 1", child1Node.Content);
rootNode.IsExpanded = false;
await TestServices.WindowHelper.WaitForIdle();
rootNode.IsExpanded = true;
await TestServices.WindowHelper.WaitForIdle();
var child1NodeAfter = (TreeViewItem)SUT.FindName("Child 1");
Assert.IsNotNull(child1NodeAfter);
Assert.AreEqual("Child 1", child1NodeAfter.Content);
var child2NodeAfter = (TreeViewItem)SUT.FindName("Child 2");
Assert.IsNotNull(child2NodeAfter);
Assert.AreEqual("Child 2", child2NodeAfter.Content);
}
private class MyNode
{
public string Name { get; set; }
public List<MyNode> Children { get; set; }
}
}