1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-27 07:02:54 +08:00
osu-lazer/osu.Game.Tests/Visual/Online/TestSceneCurrentlyPlayingDisplay.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

106 lines
3.6 KiB
C#
Raw Normal View History

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