forked from ppy/osu-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestSceneTabControlEvents.cs
148 lines (128 loc) · 6 KB
/
TestSceneTabControlEvents.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input;
using osu.Framework.Testing;
using osuTK;
using osuTK.Input;
namespace osu.Framework.Tests.Visual.UserInterface
{
public partial class TestSceneTabControlEvents : ManualInputManagerTestScene
{
private EventQueuesTabControl tabControl = null!;
[SetUpSteps]
public void SetUpSteps()
{
AddStep("add tab control", () => Child = tabControl = new EventQueuesTabControl
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(150, 40),
Items = Enum.GetValues<TestEnum>(),
});
AddAssert("selected tab queue empty", () => tabControl.UserTabSelectionChangedQueue.Count == 0);
}
[Test]
public void TestClickSendsEvent()
{
AddStep("click second tab", () =>
{
InputManager.MoveMouseTo(this.ChildrenOfType<TabItem<TestEnum>>().ElementAt(1));
InputManager.Click(MouseButton.Left);
});
AddAssert("selected tab = second", () => tabControl.Current.Value == TestEnum.Second);
AddAssert("selected tab queue has \"second\"", () => tabControl.UserTabSelectionChangedQueue.Dequeue().Value == TestEnum.Second);
}
[Test]
public void TestClickSameTabDoesNotSendEvent()
{
AddAssert("first tab selected", () => tabControl.Current.Value == TestEnum.First);
AddStep("click first tab", () =>
{
InputManager.MoveMouseTo(this.ChildrenOfType<TabItem<TestEnum>>().First());
InputManager.Click(MouseButton.Left);
});
AddAssert("first tab still selected", () => tabControl.Current.Value == TestEnum.First);
AddAssert("selected tab queue empty", () => tabControl.UserTabSelectionChangedQueue.Count == 0);
}
[Test]
public void TestSelectItemMethodSendsEvent()
{
AddStep("call select item", () => tabControl.SelectItem(TestEnum.Second));
AddAssert("selected tab queue has \"second\"", () => tabControl.UserTabSelectionChangedQueue.Dequeue().Value == TestEnum.Second);
}
[Test]
public void TestSwitchTabMethodSendsEvent()
{
AddStep("set switchable", () => tabControl.IsSwitchable = true);
AddStep("call switch tab", () => tabControl.SwitchTab(1));
AddAssert("selected tab = second", () => tabControl.Current.Value == TestEnum.Second);
AddAssert("selected tab queue has \"second\"", () => tabControl.UserTabSelectionChangedQueue.Dequeue().Value == TestEnum.Second);
AddStep("call switch tab", () => tabControl.SwitchTab(-1));
AddAssert("selected tab = second", () => tabControl.Current.Value == TestEnum.First);
AddAssert("selected tab queue has \"second\"", () => tabControl.UserTabSelectionChangedQueue.Dequeue().Value == TestEnum.First);
}
[Test]
public void TestSwitchUsingKeyBindingSendsEvent()
{
AddStep("set switchable", () => tabControl.IsSwitchable = true);
AddStep("switch forward", () => InputManager.Keys(PlatformAction.DocumentNext));
AddAssert("selected tab = second", () => tabControl.Current.Value == TestEnum.Second);
AddAssert("selected tab queue has \"second\"", () => tabControl.UserTabSelectionChangedQueue.Dequeue().Value == TestEnum.Second);
AddStep("switch backward", () => InputManager.Keys(PlatformAction.DocumentPrevious));
AddAssert("selected tab = second", () => tabControl.Current.Value == TestEnum.First);
AddAssert("selected tab queue has \"second\"", () => tabControl.UserTabSelectionChangedQueue.Dequeue().Value == TestEnum.First);
}
[Test]
public void TestSwitchOnRemovalDoesNotSendEvent()
{
AddStep("set switchable", () => tabControl.IsSwitchable = true);
AddStep("remove first tab", () => tabControl.RemoveItem(TestEnum.First));
AddAssert("selected tab = second", () => tabControl.Current.Value == TestEnum.Second);
AddAssert("selected tab queue still empty", () => tabControl.UserTabSelectionChangedQueue.Count == 0);
}
[Test]
public void TestBindableChangeDoesNotSendEvent()
{
AddStep("set selected tab = second", () => tabControl.Current.Value = TestEnum.Second);
AddAssert("selected tab queue still empty", () => tabControl.UserTabSelectionChangedQueue.Count == 0);
}
[TearDownSteps]
public void TearDownSteps()
{
AddAssert("selected tab queue empty", () => tabControl.UserTabSelectionChangedQueue.Count == 0);
}
private partial class EventQueuesTabControl : BasicTabControl<TestEnum>
{
public readonly Queue<TabItem<TestEnum>> UserTabSelectionChangedQueue = new Queue<TabItem<TestEnum>>();
private Box background = null!;
[BackgroundDependencyLoader]
private void load()
{
AddInternal(background = new Box
{
RelativeSizeAxes = Axes.Both,
Colour = FrameworkColour.YellowGreen,
Alpha = 0,
});
}
protected override void OnUserTabSelectionChanged(TabItem<TestEnum> item)
{
UserTabSelectionChangedQueue.Enqueue(item);
background.FadeOutFromOne(500);
}
}
private enum TestEnum
{
First,
Second,
}
}
}