1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 12:57:36 +08:00

Add test coverage for new display (and remove live version for now)

This commit is contained in:
Dean Herbert 2020-11-02 20:41:14 +09:00
parent c6de0544d2
commit ed30756c19
4 changed files with 77 additions and 4 deletions

View File

@ -3,8 +3,10 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Screens;
using osu.Framework.Testing;
@ -231,8 +233,15 @@ namespace osu.Game.Tests.Visual.Gameplay
{
public readonly User StreamingUser = new User { Id = 1234, Username = "Test user" };
public new BindableList<int> PlayingUsers => (BindableList<int>)base.PlayingUsers;
private int beatmapId;
protected override Task Connect()
{
return Task.CompletedTask;
}
public void StartPlay(int beatmapId)
{
this.beatmapId = beatmapId;

View File

@ -0,0 +1,64 @@
// 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 NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Testing;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Online.Spectator;
using osu.Game.Overlays.Dashboard;
using osu.Game.Tests.Visual.Gameplay;
using osu.Game.Users;
namespace osu.Game.Tests.Visual.Online
{
public class TestSceneCurrentlyPlayingDisplay : OsuTestScene
{
[Cached(typeof(SpectatorStreamingClient))]
private TestSceneSpectator.TestSpectatorStreamingClient testSpectatorStreamingClient = new TestSceneSpectator.TestSpectatorStreamingClient();
private CurrentlyPlayingDisplay currentlyPlaying;
private DummyAPIAccess dummyAPI => (DummyAPIAccess)API;
[SetUpSteps]
public void SetUpSteps()
{
AddStep("register request handling", () => ((DummyAPIAccess)API).HandleRequest = req =>
{
switch (req)
{
case GetUserRequest cRequest:
cRequest.TriggerSuccess(new User { Username = "peppy", Id = 2 });
break;
}
});
AddStep("add streaming client", () =>
{
Remove(testSpectatorStreamingClient);
Children = new Drawable[]
{
testSpectatorStreamingClient,
currentlyPlaying = new CurrentlyPlayingDisplay
{
RelativeSizeAxes = Axes.Both,
}
};
});
}
[Test]
public void TestBasicDisplay()
{
AddStep("Add playing user", () => testSpectatorStreamingClient.PlayingUsers.Add(2));
AddUntilStep("Panel loaded", () => currentlyPlaying.ChildrenOfType<UserGridPanel>()?.FirstOrDefault()?.User.Id == 2);
AddStep("Remove playing user", () => testSpectatorStreamingClient.PlayingUsers.Remove(2));
AddUntilStep("Panel no longer present", () => !currentlyPlaying.ChildrenOfType<UserGridPanel>().Any());
}
}
}

View File

@ -92,14 +92,14 @@ namespace osu.Game.Online.Spectator
break;
case APIState.Online:
Task.Run(connect);
Task.Run(Connect);
break;
}
}
private const string endpoint = "https://spectator.ppy.sh/spectator";
private async Task connect()
protected virtual async Task Connect()
{
if (connection != null)
return;

View File

@ -78,7 +78,7 @@ namespace osu.Game.Overlays.Dashboard
}), true);
}
[Resolved]
[Resolved(canBeNull: true)]
private OsuGame game { get; set; }
private UserPanel createUserPanel(User user)
@ -89,7 +89,7 @@ namespace osu.Game.Overlays.Dashboard
panel.Origin = Anchor.TopCentre;
panel.Width = 290;
panel.ShowProfileOnClick = false;
panel.Action = () => game.PerformFromScreen(s => s.Push(new Spectator(user)));
panel.Action = () => game?.PerformFromScreen(s => s.Push(new Spectator(user)));
});
}
}