mirror of
https://github.com/ppy/osu
synced 2024-12-11 17:42:28 +00:00
9d07749959
There was a lot of weirdness here, such as storing the playing users, clearing the playing users from test scenes (!!), and storing the users being wathed. This was all a thing because the previous implementation overrode the base method implementations, which is no longer a thing.
109 lines
3.6 KiB
C#
109 lines
3.6 KiB
C#
// 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 System.Threading;
|
|
using System.Threading.Tasks;
|
|
using NUnit.Framework;
|
|
using osu.Framework.Allocation;
|
|
using osu.Framework.Graphics;
|
|
using osu.Framework.Graphics.Containers;
|
|
using osu.Framework.Testing;
|
|
using osu.Game.Database;
|
|
using osu.Game.Online.Spectator;
|
|
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 User streamingUser = new User { Id = 2, Username = "Test user" };
|
|
|
|
[Cached(typeof(SpectatorClient))]
|
|
private TestSpectatorClient testSpectatorClient = new TestSpectatorClient();
|
|
|
|
private CurrentlyPlayingDisplay currentlyPlaying;
|
|
|
|
[Cached(typeof(UserLookupCache))]
|
|
private UserLookupCache lookupCache = new TestUserLookupCache();
|
|
|
|
private Container nestedContainer;
|
|
|
|
[SetUpSteps]
|
|
public void SetUpSteps()
|
|
{
|
|
AddStep("add streaming client", () =>
|
|
{
|
|
nestedContainer?.Remove(testSpectatorClient);
|
|
Remove(lookupCache);
|
|
|
|
Children = new Drawable[]
|
|
{
|
|
lookupCache,
|
|
nestedContainer = new Container
|
|
{
|
|
RelativeSizeAxes = Axes.Both,
|
|
Children = new Drawable[]
|
|
{
|
|
testSpectatorClient,
|
|
currentlyPlaying = new CurrentlyPlayingDisplay
|
|
{
|
|
RelativeSizeAxes = Axes.Both,
|
|
}
|
|
}
|
|
},
|
|
};
|
|
});
|
|
|
|
AddStep("Reset players", () => testSpectatorClient.EndPlay(streamingUser.Id));
|
|
}
|
|
|
|
[Test]
|
|
public void TestBasicDisplay()
|
|
{
|
|
AddStep("Add playing user", () => testSpectatorClient.StartPlay(streamingUser.Id, 0));
|
|
AddUntilStep("Panel loaded", () => currentlyPlaying.ChildrenOfType<UserGridPanel>()?.FirstOrDefault()?.User.Id == 2);
|
|
AddStep("Remove playing user", () => testSpectatorClient.EndPlay(streamingUser.Id));
|
|
AddUntilStep("Panel no longer present", () => !currentlyPlaying.ChildrenOfType<UserGridPanel>().Any());
|
|
}
|
|
|
|
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<User> ComputeValueAsync(int lookup, CancellationToken token = default)
|
|
{
|
|
// tests against failed lookups
|
|
if (lookup == 13)
|
|
return Task.FromResult<User>(null);
|
|
|
|
return Task.FromResult(new User
|
|
{
|
|
Id = lookup,
|
|
Username = usernames[lookup % usernames.Length],
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|