forked from ppy/osu
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestSceneUserTagControl.cs
More file actions
221 lines (200 loc) · 9.2 KB
/
Copy pathTestSceneUserTagControl.cs
File metadata and controls
221 lines (200 loc) · 9.2 KB
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
// 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.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Testing;
using osu.Game.Beatmaps;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Overlays;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Taiko;
using osu.Game.Screens.Ranking;
using osuTK;
using osuTK.Input;
namespace osu.Game.Tests.Visual.Ranking
{
public partial class TestSceneUserTagControl : OsuManualInputManagerTestScene
{
[Cached]
private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Aquamarine);
private DummyAPIAccess dummyAPI => (DummyAPIAccess)API;
private int writeRequestCount;
[SetUpSteps]
public void SetUpSteps()
{
AddStep("reset mouse position", () => InputManager.MoveMouseTo(Vector2.Zero));
AddStep("set up network requests", () =>
{
writeRequestCount = 0;
dummyAPI.HandleRequest = request =>
{
switch (request)
{
case ListTagsRequest listTagsRequest:
{
Scheduler.AddDelayed(() => listTagsRequest.TriggerSuccess(new APITagCollection
{
Tags =
[
new APITag
{
Id = 0,
Name = "uncategorised tag",
Description = "This probably isn't real but could be and should be handled.",
},
new APITag
{
Id = 1,
Name = "song representation/simple",
Description = "Accessible and straightforward map design.",
},
new APITag
{
Id = 2,
Name = "style/clean",
Description = "Visually uncluttered and organised patterns, often involving few overlaps and equal visual spacing between objects.",
},
new APITag
{
Id = 3,
Name = "aim/aim control",
Description = "Patterns with velocity or direction changes which strongly go against a player's natural movement pattern.",
},
new APITag
{
Id = 4,
Name = "tap/bursts",
Description = "Patterns requiring continuous movement and alternating, typically 9 notes or less.",
},
new APITag
{
Id = 5,
Name = "style/mono-heavy",
Description = "Features monos used in large amounts.",
RulesetId = 1,
},
]
}), 500);
return true;
}
case GetBeatmapSetRequest getBeatmapSetRequest:
{
var beatmapSet = CreateAPIBeatmapSet(Beatmap.Value.BeatmapInfo);
beatmapSet.Beatmaps.Single().TopTags =
[
new APIBeatmapTag { TagId = 3, VoteCount = 4 },
new APIBeatmapTag { TagId = 2, VoteCount = 3 },
new APIBeatmapTag { TagId = 0, VoteCount = 2 },
];
Scheduler.AddDelayed(() => getBeatmapSetRequest.TriggerSuccess(beatmapSet), 500);
return true;
}
case AddBeatmapTagRequest:
case RemoveBeatmapTagRequest:
{
writeRequestCount++;
Scheduler.AddDelayed(request.TriggerSuccess, 500);
return true;
}
}
return false;
};
});
}
[Test]
public void TestRulesetSupport()
{
AddStep("show for osu! beatmap", () =>
{
var working = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo);
working.BeatmapInfo.OnlineID = 42;
Beatmap.Value = working;
recreateControl();
});
AddStep("show for taiko beatmap", () =>
{
var working = CreateWorkingBeatmap(new TaikoRuleset().RulesetInfo);
working.BeatmapInfo.OnlineID = 44;
Beatmap.Value = working;
recreateControl();
});
}
[Test]
public void TestNotWritable()
{
AddStep("show", () =>
{
var working = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo);
working.BeatmapInfo.OnlineID = 42;
Beatmap.Value = working;
recreateControl(writable: false);
});
AddUntilStep("click tag", () =>
{
var tag = this.ChildrenOfType<UserTagControl.DrawableUserTag>().FirstOrDefault(t => t.UserTag.Id == 2);
if (tag == null)
return false;
InputManager.MoveMouseTo(tag);
InputManager.Click(MouseButton.Left);
return true;
});
AddAssert("no vote requests send", () => writeRequestCount, () => Is.Zero);
}
[Test]
public void TestTagsDoNotMoveUntilMouseMovesAway()
{
AddStep("show", () =>
{
var working = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo);
working.BeatmapInfo.OnlineID = 42;
Beatmap.Value = working;
recreateControl();
});
AddUntilStep("wait for ready", () => getTagFlow().Count, () => Is.EqualTo(4));
AddAssert("tag 2 is second", () => getTagFlow().GetLayoutPosition(getDrawableTagById(2)), () => Is.EqualTo(1));
AddStep("vote for tag 2", () =>
{
InputManager.MoveMouseTo(getDrawableTagById(2));
InputManager.Click(MouseButton.Left);
});
AddUntilStep("tag 2 voted for", () => getDrawableTagById(2).UserTag.VoteCount.Value, () => Is.EqualTo(4));
AddStep("remove vote for tag 2", () =>
{
InputManager.MoveMouseTo(getDrawableTagById(2));
InputManager.Click(MouseButton.Left);
});
AddUntilStep("tag 2 not voted for", () => getDrawableTagById(2).UserTag.VoteCount.Value, () => Is.EqualTo(3));
AddAssert("tag 2 is still second", () => getTagFlow().GetLayoutPosition(getDrawableTagById(2)), () => Is.EqualTo(1));
AddStep("vote for tag 2", () =>
{
InputManager.MoveMouseTo(getDrawableTagById(2));
InputManager.Click(MouseButton.Left);
});
AddUntilStep("tag 2 voted for", () => getDrawableTagById(2).UserTag.VoteCount.Value, () => Is.EqualTo(4));
AddStep("move mouse away", () => InputManager.MoveMouseTo(Vector2.Zero));
AddAssert("tag 2 reordered to first", () => getTagFlow().GetLayoutPosition(getDrawableTagById(2)), () => Is.EqualTo(0));
FillFlowContainer<UserTagControl.DrawableUserTag> getTagFlow() => this.ChildrenOfType<FillFlowContainer<UserTagControl.DrawableUserTag>>().Single();
UserTagControl.DrawableUserTag getDrawableTagById(long id) => getTagFlow().Single(t => t.UserTag.Id == id);
}
private void recreateControl(bool writable = true)
{
Child = new PopoverContainer
{
RelativeSizeAxes = Axes.Both,
Child = new UserTagControl(Beatmap.Value.BeatmapInfo)
{
Writable = writable,
Width = 700,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
}
};
}
}
}