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;
|
|
|
|
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
|
|
|
|
{
|
|
|
|
public class TestSceneCurrentlyPlayingDisplay : OsuTestScene
|
|
|
|
{
|
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
|
|
|
|
2021-08-03 17:16:58 +08:00
|
|
|
private TestSpectatorClient spectatorClient;
|
2020-11-02 19:41:14 +08:00
|
|
|
private CurrentlyPlayingDisplay currentlyPlaying;
|
|
|
|
|
|
|
|
[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),
|
|
|
|
(typeof(UserLookupCache), lookupCache)
|
|
|
|
},
|
|
|
|
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()
|
|
|
|
{
|
2021-08-03 17:16:58 +08:00
|
|
|
AddStep("Add playing user", () => spectatorClient.StartPlay(streamingUser.Id, 0));
|
2020-11-02 19:41:14 +08:00
|
|
|
AddUntilStep("Panel loaded", () => currentlyPlaying.ChildrenOfType<UserGridPanel>()?.FirstOrDefault()?.User.Id == 2);
|
2021-08-03 17:16:58 +08:00
|
|
|
AddStep("Remove playing user", () => spectatorClient.EndPlay(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
|
|
|
|
|
|
|
internal class TestUserLookupCache : UserLookupCache
|
|
|
|
{
|
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"
|
|
|
|
};
|
|
|
|
|
2021-11-04 17:02:44 +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)
|
2021-11-04 17:02:44 +08:00
|
|
|
return Task.FromResult<APIUser>(null);
|
2020-12-28 19:30:08 +08:00
|
|
|
|
2021-11-04 17:02:44 +08:00
|
|
|
return Task.FromResult(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
|
|
|
}
|
|
|
|
}
|