2020-11-02 19:41:14 +08:00
|
|
|
// 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.
|
|
|
|
|
2021-08-03 17:16:58 +08:00
|
|
|
using System;
|
2020-11-02 19:41:14 +08:00
|
|
|
using System.Linq;
|
2020-11-06 17:41:05 +08:00
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
2020-11-02 19:41:14 +08:00
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Testing;
|
2020-11-06 17:41:05 +08:00
|
|
|
using osu.Game.Database;
|
2021-11-04 17:02:44 +08:00
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2020-11-02 19:41:14 +08:00
|
|
|
using osu.Game.Online.Spectator;
|
2022-05-27 22:38:54 +08:00
|
|
|
using osu.Game.Overlays;
|
2020-11-02 19:41:14 +08:00
|
|
|
using osu.Game.Overlays.Dashboard;
|
2021-05-12 11:17:42 +08:00
|
|
|
using osu.Game.Tests.Visual.Spectator;
|
2020-11-02 19:41:14 +08:00
|
|
|
using osu.Game.Users;
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.Online
|
|
|
|
{
|
2022-11-24 13:32:20 +08:00
|
|
|
public partial class TestSceneCurrentlyPlayingDisplay : OsuTestScene
|
2020-11-02 19:41:14 +08:00
|
|
|
{
|
2021-11-04 17:02:44 +08:00
|
|
|
private readonly APIUser streamingUser = new APIUser { Id = 2, Username = "Test user" };
|
2021-05-20 16:41:46 +08:00
|
|
|
|
2023-06-09 19:47:50 +08:00
|
|
|
private TestSpectatorClient spectatorClient = null!;
|
|
|
|
private CurrentlyPlayingDisplay currentlyPlaying = null!;
|
2020-11-02 19:41:14 +08:00
|
|
|
|
|
|
|
[SetUpSteps]
|
|
|
|
public void SetUpSteps()
|
|
|
|
{
|
|
|
|
AddStep("add streaming client", () =>
|
|
|
|
{
|
2021-08-03 17:16:58 +08:00
|
|
|
spectatorClient = new TestSpectatorClient();
|
|
|
|
var lookupCache = new TestUserLookupCache();
|
2020-11-02 19:41:14 +08:00
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
2020-11-06 17:41:05 +08:00
|
|
|
lookupCache,
|
2021-08-03 17:16:58 +08:00
|
|
|
spectatorClient,
|
|
|
|
new DependencyProvidingContainer
|
2020-11-02 19:41:14 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2021-08-03 17:16:58 +08:00
|
|
|
CachedDependencies = new (Type, object)[]
|
2020-11-06 17:41:05 +08:00
|
|
|
{
|
2021-08-03 17:16:58 +08:00
|
|
|
(typeof(SpectatorClient), spectatorClient),
|
2022-05-27 22:38:54 +08:00
|
|
|
(typeof(UserLookupCache), lookupCache),
|
|
|
|
(typeof(OverlayColourProvider), new OverlayColourProvider(OverlayColourScheme.Purple)),
|
2021-08-03 17:16:58 +08:00
|
|
|
},
|
|
|
|
Child = currentlyPlaying = new CurrentlyPlayingDisplay
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2020-11-06 17:41:05 +08:00
|
|
|
}
|
|
|
|
},
|
2020-11-02 19:41:14 +08:00
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestBasicDisplay()
|
|
|
|
{
|
2022-02-22 16:56:07 +08:00
|
|
|
AddStep("Add playing user", () => spectatorClient.SendStartPlay(streamingUser.Id, 0));
|
2023-06-24 08:48:16 +08:00
|
|
|
AddUntilStep("Panel loaded", () => currentlyPlaying.ChildrenOfType<UserGridPanel>().FirstOrDefault()?.User.Id == 2);
|
2022-02-22 16:56:07 +08:00
|
|
|
AddStep("Remove playing user", () => spectatorClient.SendEndPlay(streamingUser.Id));
|
2020-11-02 19:41:14 +08:00
|
|
|
AddUntilStep("Panel no longer present", () => !currentlyPlaying.ChildrenOfType<UserGridPanel>().Any());
|
|
|
|
}
|
2020-11-06 17:41:05 +08:00
|
|
|
|
2022-11-24 13:32:20 +08:00
|
|
|
internal partial class TestUserLookupCache : UserLookupCache
|
2020-11-06 17:41:05 +08:00
|
|
|
{
|
2020-12-16 14:53:05 +08:00
|
|
|
private static readonly string[] usernames =
|
|
|
|
{
|
|
|
|
"fieryrage",
|
|
|
|
"Kerensa",
|
|
|
|
"MillhioreF",
|
|
|
|
"Player01",
|
|
|
|
"smoogipoo",
|
|
|
|
"Ephemeral",
|
|
|
|
"BTMC",
|
|
|
|
"Cilvery",
|
|
|
|
"m980",
|
|
|
|
"HappyStick",
|
|
|
|
"LittleEndu",
|
|
|
|
"frenzibyte",
|
|
|
|
"Zallius",
|
|
|
|
"BanchoBot",
|
|
|
|
"rocketminer210",
|
|
|
|
"pishifat"
|
|
|
|
};
|
|
|
|
|
2023-06-09 19:47:50 +08:00
|
|
|
protected override Task<APIUser?> ComputeValueAsync(int lookup, CancellationToken token = default)
|
2020-12-28 19:30:08 +08:00
|
|
|
{
|
|
|
|
// tests against failed lookups
|
|
|
|
if (lookup == 13)
|
2023-06-09 19:47:50 +08:00
|
|
|
return Task.FromResult<APIUser?>(null);
|
2020-12-28 19:30:08 +08:00
|
|
|
|
2023-06-09 19:47:50 +08:00
|
|
|
return Task.FromResult<APIUser?>(new APIUser
|
2020-12-16 14:53:05 +08:00
|
|
|
{
|
2020-12-20 02:00:05 +08:00
|
|
|
Id = lookup,
|
2020-12-18 15:50:25 +08:00
|
|
|
Username = usernames[lookup % usernames.Length],
|
2020-12-16 14:53:05 +08:00
|
|
|
});
|
2020-12-28 19:30:08 +08:00
|
|
|
}
|
2020-11-06 17:41:05 +08:00
|
|
|
}
|
2020-11-02 19:41:14 +08:00
|
|
|
}
|
|
|
|
}
|