1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-13 12:43:16 +08:00

Fix TestSceneCurrentlyPlayingDisplay reusing cached spectator client

This commit is contained in:
smoogipoo 2021-08-03 18:16:58 +09:00
parent 20f2b9f722
commit 062207fcd9

View File

@ -1,13 +1,12 @@
// 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;
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;
@ -21,51 +20,44 @@ namespace osu.Game.Tests.Visual.Online
{
private readonly User streamingUser = new User { Id = 2, Username = "Test user" };
[Cached(typeof(SpectatorClient))]
private TestSpectatorClient testSpectatorClient = new TestSpectatorClient();
private TestSpectatorClient spectatorClient;
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);
spectatorClient = new TestSpectatorClient();
var lookupCache = new TestUserLookupCache();
Children = new Drawable[]
{
lookupCache,
nestedContainer = new Container
spectatorClient,
new DependencyProvidingContainer
{
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
CachedDependencies = new (Type, object)[]
{
testSpectatorClient,
currentlyPlaying = new CurrentlyPlayingDisplay
{
RelativeSizeAxes = Axes.Both,
}
(typeof(SpectatorClient), spectatorClient),
(typeof(UserLookupCache), lookupCache)
},
Child = 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));
AddStep("Add playing user", () => spectatorClient.StartPlay(streamingUser.Id, 0));
AddUntilStep("Panel loaded", () => currentlyPlaying.ChildrenOfType<UserGridPanel>()?.FirstOrDefault()?.User.Id == 2);
AddStep("Remove playing user", () => testSpectatorClient.EndPlay(streamingUser.Id));
AddStep("Remove playing user", () => spectatorClient.EndPlay(streamingUser.Id));
AddUntilStep("Panel no longer present", () => !currentlyPlaying.ChildrenOfType<UserGridPanel>().Any());
}