-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Expand file tree
/
Copy pathTestSceneFriendDisplay.cs
More file actions
264 lines (230 loc) · 9.49 KB
/
Copy pathTestSceneFriendDisplay.cs
File metadata and controls
264 lines (230 loc) · 9.49 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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
// 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.
#nullable disable
using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Extensions.TypeExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Testing;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Metadata;
using osu.Game.Overlays;
using osu.Game.Overlays.Dashboard.Friends;
using osu.Game.Tests.Resources;
using osu.Game.Tests.Visual.Metadata;
using osu.Game.Users;
namespace osu.Game.Tests.Visual.Online
{
public partial class TestSceneFriendDisplay : OsuTestScene
{
[Cached]
private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Purple);
private TestMetadataClient metadataClient;
[SetUp]
public void Setup() => Schedule(() =>
{
Child = new DependencyProvidingContainer
{
RelativeSizeAxes = Axes.Both,
CachedDependencies =
[
(typeof(MetadataClient), metadataClient = new TestMetadataClient())
],
Children = new Drawable[]
{
metadataClient,
new BasicScrollContainer
{
RelativeSizeAxes = Axes.Both,
Child = new FriendDisplay()
}
}
};
});
[Test]
public void TestAddAndRemoveFriends()
{
AddStep("set friends", () =>
{
DummyAPIAccess api = (DummyAPIAccess)API;
api.LocalUserState.Friends.Clear();
api.LocalUserState.Friends.AddRange(getUsers().Select(u => new APIRelation
{
RelationType = RelationType.Friend,
TargetID = u.OnlineID,
TargetUser = u
}));
});
waitForLoad();
assertVisiblePanelCount<UserPanel>(3);
AddStep("remove one friend", () =>
{
DummyAPIAccess api = (DummyAPIAccess)API;
api.LocalUserState.Friends.RemoveAt(0);
});
waitForLoad();
assertVisiblePanelCount<UserPanel>(2);
AddStep("add one friend", () =>
{
DummyAPIAccess api = (DummyAPIAccess)API;
api.LocalUserState.Friends.AddRange(getUsers().Take(1).Select(u => new APIRelation
{
RelationType = RelationType.Friend,
TargetID = u.OnlineID,
TargetUser = u
}));
});
waitForLoad();
assertVisiblePanelCount<UserPanel>(3);
}
[Test]
public void TestChangeDisplayStyle()
{
AddStep("set friends", () =>
{
DummyAPIAccess api = (DummyAPIAccess)API;
api.LocalUserState.Friends.Clear();
api.LocalUserState.Friends.AddRange(getUsers().Select(u => new APIRelation
{
RelationType = RelationType.Friend,
TargetID = u.OnlineID,
TargetUser = u
}));
});
waitForLoad();
assertVisiblePanelCount<UserGridPanel>(3);
AddStep("set list style", () => this.ChildrenOfType<UserListToolbar>().Single().DisplayStyle.Value = OverlayPanelDisplayStyle.List);
waitForLoad();
assertVisiblePanelCount<UserListPanel>(3);
AddStep("set brick style", () => this.ChildrenOfType<UserListToolbar>().Single().DisplayStyle.Value = OverlayPanelDisplayStyle.Brick);
waitForLoad();
assertVisiblePanelCount<UserBrickPanel>(3);
}
[Test]
public void TestOnlinePresence()
{
AddStep("set friends", () =>
{
DummyAPIAccess api = (DummyAPIAccess)API;
api.LocalUserState.Friends.Clear();
api.LocalUserState.Friends.AddRange(getUsers().Select(u => new APIRelation
{
RelationType = RelationType.Friend,
TargetID = u.OnlineID,
TargetUser = u
}));
});
waitForLoad();
assertVisiblePanelCount<UserPanel>(3);
AddStep("change to online stream", () => this.ChildrenOfType<FriendOnlineStreamControl>().Single().Current.Value = OnlineStatus.Online);
assertVisiblePanelCount<UserPanel>(0);
AddStep("bring a friend online", () =>
{
DummyAPIAccess api = (DummyAPIAccess)API;
metadataClient.FriendPresenceUpdated(api.LocalUserState.Friends[0].TargetID, new UserPresence { Status = UserStatus.Online });
});
assertVisiblePanelCount<UserPanel>(1);
AddStep("change to offline stream", () => this.ChildrenOfType<FriendOnlineStreamControl>().Single().Current.Value = OnlineStatus.Offline);
assertVisiblePanelCount<UserPanel>(2);
AddStep("bring a friend online", () =>
{
DummyAPIAccess api = (DummyAPIAccess)API;
metadataClient.FriendPresenceUpdated(api.LocalUserState.Friends[1].TargetID, new UserPresence { Status = UserStatus.Online });
});
assertVisiblePanelCount<UserPanel>(1);
AddStep("change to online stream", () => this.ChildrenOfType<FriendOnlineStreamControl>().Single().Current.Value = OnlineStatus.Online);
assertVisiblePanelCount<UserPanel>(2);
AddStep("take friend offline", () =>
{
DummyAPIAccess api = (DummyAPIAccess)API;
metadataClient.FriendPresenceUpdated(api.LocalUserState.Friends[1].TargetID, null);
});
assertVisiblePanelCount<UserPanel>(1);
AddStep("change to all stream", () => this.ChildrenOfType<FriendOnlineStreamControl>().Single().Current.Value = OnlineStatus.All);
assertVisiblePanelCount<UserPanel>(3);
}
[Test]
public void TestLoadFriendsBeforeDisplay()
{
AddStep("set friends", () =>
{
DummyAPIAccess api = (DummyAPIAccess)API;
api.LocalUserState.Friends.Clear();
api.LocalUserState.Friends.AddRange(getUsers().Select(u => new APIRelation
{
RelationType = RelationType.Friend,
TargetID = u.OnlineID,
TargetUser = u
}));
});
AddStep("load new display", () =>
{
Child = new DependencyProvidingContainer
{
RelativeSizeAxes = Axes.Both,
CachedDependencies =
[
(typeof(MetadataClient), metadataClient = new TestMetadataClient())
],
Children = new Drawable[]
{
metadataClient,
new BasicScrollContainer
{
RelativeSizeAxes = Axes.Both,
Child = new FriendDisplay()
}
}
};
});
waitForLoad();
assertVisiblePanelCount<UserPanel>(3);
}
private void waitForLoad()
=> AddUntilStep("wait for panels to load", () => this.ChildrenOfType<UserPanel>().Any());
private void assertVisiblePanelCount<T>(int expectedVisible)
where T : UserPanel
{
AddUntilStep($"{typeof(T).ReadableName()}s in list", () => this.ChildrenOfType<FriendsList>().Last().ChildrenOfType<UserPanel>().All(p => p is T));
AddUntilStep($"{expectedVisible} panels visible", () => this.ChildrenOfType<FriendsList>().Last().ChildrenOfType<FriendsList.FilterableUserPanel>().Count(p => p.IsPresent),
() => Is.EqualTo(expectedVisible));
}
private List<APIUser> getUsers() => new List<APIUser>
{
new APIUser
{
Username = "flyte",
Id = 3103765,
WasRecentlyOnline = true,
Statistics = new UserStatistics { GlobalRank = 1111 },
CountryCode = CountryCode.JP,
CoverUrl = TestResources.COVER_IMAGE_4
},
new APIUser
{
Username = "peppy",
Id = 2,
WasRecentlyOnline = false,
Statistics = new UserStatistics { GlobalRank = 2222 },
CountryCode = CountryCode.AU,
CoverUrl = TestResources.COVER_IMAGE_3,
IsSupporter = true,
SupportLevel = 3,
},
new APIUser
{
Username = "Evast",
Id = 8195163,
CountryCode = CountryCode.BY,
CoverUrl = "https://assets.ppy.sh/user-profile-covers/8195163/4a8e2ad5a02a2642b631438cfa6c6bd7e2f9db289be881cb27df18331f64144c.jpeg",
WasRecentlyOnline = false,
LastVisit = DateTimeOffset.Now
}
};
}
}