Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove fetching logic from leaderboard #31355

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
20 changes: 14 additions & 6 deletions osu.Game.Tests/Visual/Multiplayer/TestSceneMatchLeaderboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,21 @@ public override void SetUpSteps()
{
SelectedRoom.Value = new Room { RoomID = 3 };

Child = new MatchLeaderboard(SelectedRoom.Value)
MatchLeaderboardScoresProvider scoresProvider;

AddRange(new Drawable[]
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Size = new Vector2(550f, 450f),
Scope = MatchLeaderboardScope.Overall,
};
scoresProvider = new MatchLeaderboardScoresProvider(SelectedRoom.Value)
{
Scope = MatchLeaderboardScope.Overall,
},
new MatchLeaderboard(scoresProvider)
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Size = new Vector2(550f, 450f),
}
});
});
}
}
Expand Down
51 changes: 30 additions & 21 deletions osu.Game.Tests/Visual/SongSelect/TestSceneBeatmapLeaderboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ namespace osu.Game.Tests.Visual.SongSelect
{
public partial class TestSceneBeatmapLeaderboard : OsuTestScene
{
private readonly FailableLeaderboard leaderboard;
private readonly BeatmapLeaderboard leaderboard;
private readonly FailableScoresProvider scoresProvider;

[Cached(typeof(IDialogOverlay))]
private readonly DialogOverlay dialogOverlay;
Expand Down Expand Up @@ -58,12 +59,15 @@ public TestSceneBeatmapLeaderboard()
{
Depth = -1
},
leaderboard = new FailableLeaderboard
scoresProvider = new FailableScoresProvider
{
Scope = BeatmapLeaderboardScope.Global
},
leaderboard = new BeatmapLeaderboard(scoresProvider)
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Size = new Vector2(550f, 450f),
Scope = BeatmapLeaderboardScope.Global,
}
});
}
Expand All @@ -73,14 +77,14 @@ public void TestLocalScoresDisplay()
{
BeatmapInfo beatmapInfo = null!;

AddStep(@"Set scope", () => leaderboard.Scope = BeatmapLeaderboardScope.Local);
AddStep(@"Set scope", () => scoresProvider.Scope = BeatmapLeaderboardScope.Local);

AddStep(@"Set beatmap", () =>
{
beatmapManager.Import(TestResources.GetQuickTestBeatmapForImport()).WaitSafely();
beatmapInfo = beatmapManager.GetAllUsableBeatmapSets().First().Beatmaps.First();

leaderboard.BeatmapInfo = beatmapInfo;
scoresProvider.BeatmapInfo = beatmapInfo;
});

clearScores();
Expand All @@ -102,14 +106,14 @@ public void TestLocalScoresDisplayOnBeatmapEdit()
BeatmapInfo beatmapInfo = null!;
string originalHash = string.Empty;

AddStep(@"Set scope", () => leaderboard.Scope = BeatmapLeaderboardScope.Local);
AddStep(@"Set scope", () => scoresProvider.Scope = BeatmapLeaderboardScope.Local);

AddStep(@"Import beatmap", () =>
{
beatmapManager.Import(TestResources.GetQuickTestBeatmapForImport()).WaitSafely();
beatmapInfo = beatmapManager.GetAllUsableBeatmapSets().First().Beatmaps.First();

leaderboard.BeatmapInfo = beatmapInfo;
scoresProvider.BeatmapInfo = beatmapInfo;
});

clearScores();
Expand Down Expand Up @@ -163,8 +167,8 @@ public void TestLocalScoresDisplayOnBeatmapEdit()
[Test]
public void TestGlobalScoresDisplay()
{
AddStep(@"Set scope", () => leaderboard.Scope = BeatmapLeaderboardScope.Global);
AddStep(@"New Scores", () => leaderboard.SetScores(generateSampleScores(new BeatmapInfo())));
AddStep(@"Set scope", () => scoresProvider.Scope = BeatmapLeaderboardScope.Global);
AddStep(@"New Scores", () => scoresProvider.SetScores(generateSampleScores(new BeatmapInfo())));
}

[Test]
Expand All @@ -177,19 +181,19 @@ public void TestPersonalBest()
[Test]
public void TestPlaceholderStates()
{
AddStep("ensure no scores displayed", () => leaderboard.SetScores(null));

AddStep(@"Network failure", () => leaderboard.SetErrorState(LeaderboardState.NetworkFailure));
AddStep(@"No supporter", () => leaderboard.SetErrorState(LeaderboardState.NotSupporter));
AddStep(@"Not logged in", () => leaderboard.SetErrorState(LeaderboardState.NotLoggedIn));
AddStep(@"Ruleset unavailable", () => leaderboard.SetErrorState(LeaderboardState.RulesetUnavailable));
AddStep(@"Beatmap unavailable", () => leaderboard.SetErrorState(LeaderboardState.BeatmapUnavailable));
AddStep(@"None selected", () => leaderboard.SetErrorState(LeaderboardState.NoneSelected));
AddStep("ensure no scores displayed", () => scoresProvider.SetScores(null));

AddStep(@"Network failure", () => scoresProvider.SetErrorState(LeaderboardState.NetworkFailure));
AddStep(@"No supporter", () => scoresProvider.SetErrorState(LeaderboardState.NotSupporter));
AddStep(@"Not logged in", () => scoresProvider.SetErrorState(LeaderboardState.NotLoggedIn));
AddStep(@"Ruleset unavailable", () => scoresProvider.SetErrorState(LeaderboardState.RulesetUnavailable));
AddStep(@"Beatmap unavailable", () => scoresProvider.SetErrorState(LeaderboardState.BeatmapUnavailable));
AddStep(@"None selected", () => scoresProvider.SetErrorState(LeaderboardState.NoneSelected));
}

private void showPersonalBestWithNullPosition()
{
leaderboard.SetScores(leaderboard.Scores, new ScoreInfo
scoresProvider.SetScores(scoresProvider.Scores, new ScoreInfo
{
Rank = ScoreRank.XH,
Accuracy = 1,
Expand All @@ -208,7 +212,7 @@ private void showPersonalBestWithNullPosition()

private void showPersonalBest()
{
leaderboard.SetScores(leaderboard.Scores, new ScoreInfo
scoresProvider.SetScores(scoresProvider.Scores, new ScoreInfo
{
Position = 999,
Rank = ScoreRank.XH,
Expand Down Expand Up @@ -458,10 +462,15 @@ private static ScoreInfo[] generateSampleScores(BeatmapInfo beatmapInfo)
};
}

private partial class FailableLeaderboard : BeatmapLeaderboard
private partial class FailableScoresProvider : BeatmapLeaderboardScoresProvider
{
public new void SetErrorState(LeaderboardState state) => base.SetErrorState(state);
public new void SetScores(IEnumerable<ScoreInfo>? scores, ScoreInfo? userScore = null) => base.SetScores(scores, userScore);

public new void SetScores(IEnumerable<ScoreInfo>? scores, ScoreInfo? userScore = null)
{
SetState(LeaderboardState.Retrieving);
base.SetScores(scores, userScore);
}
}
}
}
31 changes: 19 additions & 12 deletions osu.Game.Tests/Visual/UserInterface/TestSceneDeleteLocalScore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ namespace osu.Game.Tests.Visual.UserInterface
public partial class TestSceneDeleteLocalScore : OsuManualInputManagerTestScene
{
private readonly ContextMenuContainer contextMenuContainer;
private readonly BeatmapLeaderboardScoresProvider scoresProvider;
private readonly BeatmapLeaderboard leaderboard;

private BeatmapManager beatmapManager;
Expand All @@ -54,13 +55,19 @@ public TestSceneDeleteLocalScore()
contextMenuContainer = new OsuContextMenuContainer
{
RelativeSizeAxes = Axes.Both,
Child = leaderboard = new BeatmapLeaderboard
Children = new Drawable[]
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Size = new Vector2(550f, 450f),
Scope = BeatmapLeaderboardScope.Local,
BeatmapInfo = TestResources.CreateTestBeatmapSetInfo().Beatmaps.First()
scoresProvider = new BeatmapLeaderboardScoresProvider
{
Scope = BeatmapLeaderboardScope.Local,
BeatmapInfo = TestResources.CreateTestBeatmapSetInfo().Beatmaps.First()
},
leaderboard = new BeatmapLeaderboard(scoresProvider)
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Size = new Vector2(550f, 450f),
}
}
},
dialogOverlay = new DialogOverlay()
Expand Down Expand Up @@ -123,8 +130,8 @@ public void SetupSteps()
});
AddStep("set up leaderboard", () =>
{
leaderboard.BeatmapInfo = beatmapInfo;
leaderboard.RefetchScores(); // Required in the case that the beatmap hasn't changed
scoresProvider.BeatmapInfo = beatmapInfo;
scoresProvider.RefetchScores(); // Required in the case that the beatmap hasn't changed
});

// Ensure the leaderboard items have finished showing up
Expand Down Expand Up @@ -164,8 +171,8 @@ public void TestDeleteViaRightClick()
InputManager.PressButton(MouseButton.Left);
});

AddUntilStep("wait for fetch", () => leaderboard.Scores.Any());
AddUntilStep("score removed from leaderboard", () => leaderboard.Scores.All(s => s.OnlineID != scoreBeingDeleted.OnlineID));
AddUntilStep("wait for fetch", () => scoresProvider.Scores.Any());
AddUntilStep("score removed from leaderboard", () => scoresProvider.Scores.All(s => s.OnlineID != scoreBeingDeleted.OnlineID));

// "Clean up"
AddStep("release left mouse button", () => InputManager.ReleaseButton(MouseButton.Left));
Expand All @@ -175,8 +182,8 @@ public void TestDeleteViaRightClick()
public void TestDeleteViaDatabase()
{
AddStep("delete top score", () => scoreManager.Delete(importedScores[0]));
AddUntilStep("wait for fetch", () => leaderboard.Scores.Any());
AddUntilStep("score removed from leaderboard", () => leaderboard.Scores.All(s => s.OnlineID != importedScores[0].OnlineID));
AddUntilStep("wait for fetch", () => scoresProvider.Scores.Any());
AddUntilStep("score removed from leaderboard", () => scoresProvider.Scores.All(s => s.OnlineID != importedScores[0].OnlineID));
}
}
}
Loading
Loading