From 397d2491b3e2b1f74b99bab0549c17ba96a2664d Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 1 Jul 2021 16:55:44 +0900 Subject: [PATCH] Update test scenes to actually cover submission logic --- .../TestScenePlayerScorePreparation.cs | 69 ----------------- .../TestScenePlayerScoreSubmission.cs | 74 +++++++++++++++++++ 2 files changed, 74 insertions(+), 69 deletions(-) delete mode 100644 osu.Game.Tests/Visual/Gameplay/TestScenePlayerScorePreparation.cs create mode 100644 osu.Game.Tests/Visual/Gameplay/TestScenePlayerScoreSubmission.cs diff --git a/osu.Game.Tests/Visual/Gameplay/TestScenePlayerScorePreparation.cs b/osu.Game.Tests/Visual/Gameplay/TestScenePlayerScorePreparation.cs deleted file mode 100644 index 8ea5f3f9ee..0000000000 --- a/osu.Game.Tests/Visual/Gameplay/TestScenePlayerScorePreparation.cs +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. -// See the LICENCE file in the repository root for full licence text. - -using System.Threading.Tasks; -using NUnit.Framework; -using osu.Framework.Screens; -using osu.Framework.Testing; -using osu.Game.Rulesets; -using osu.Game.Scoring; -using osu.Game.Screens.Ranking; - -namespace osu.Game.Tests.Visual.Gameplay -{ - public class TestScenePlayerScorePreparation : OsuPlayerTestScene - { - protected override bool AllowFail => false; - - protected new PreparingPlayer Player => (PreparingPlayer)base.Player; - - [SetUpSteps] - public override void SetUpSteps() - { - base.SetUpSteps(); - - // Ensure track has actually running before attempting to seek - AddUntilStep("wait for track to start running", () => Beatmap.Value.Track.IsRunning); - } - - [Test] - public void TestPreparationOnResults() - { - AddUntilStep("wait for preparation", () => Player.PreparationCompleted); - } - - [Test] - public void TestPreparationOnExit() - { - AddStep("exit", () => Player.Exit()); - AddUntilStep("wait for preparation", () => Player.PreparationCompleted); - } - - protected override TestPlayer CreatePlayer(Ruleset ruleset) => new PreparingPlayer(); - - public class PreparingPlayer : TestPlayer - { - public bool PreparationCompleted { get; private set; } - - public bool ResultsCreated { get; private set; } - - public PreparingPlayer() - : base(true, true) - { - } - - protected override ResultsScreen CreateResults(ScoreInfo score) - { - var results = base.CreateResults(score); - ResultsCreated = true; - return results; - } - - protected override Task PrepareScoreForResultsAsync(Score score) - { - PreparationCompleted = true; - return base.PrepareScoreForResultsAsync(score); - } - } - } -} diff --git a/osu.Game.Tests/Visual/Gameplay/TestScenePlayerScoreSubmission.cs b/osu.Game.Tests/Visual/Gameplay/TestScenePlayerScoreSubmission.cs new file mode 100644 index 0000000000..24f8227148 --- /dev/null +++ b/osu.Game.Tests/Visual/Gameplay/TestScenePlayerScoreSubmission.cs @@ -0,0 +1,74 @@ +// Copyright (c) ppy Pty Ltd . 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.Screens; +using osu.Framework.Testing; +using osu.Game.Online.API; +using osu.Game.Online.Rooms; +using osu.Game.Online.Solo; +using osu.Game.Rulesets; +using osu.Game.Rulesets.Mods; +using osu.Game.Rulesets.Objects; +using osu.Game.Screens.Ranking; + +namespace osu.Game.Tests.Visual.Gameplay +{ + public class TestScenePlayerScoreSubmission : OsuPlayerTestScene + { + protected override bool AllowFail => false; + + private DummyAPIAccess dummyAPI => (DummyAPIAccess)API; + + protected override TestPlayer CreatePlayer(Ruleset ruleset) + { + SelectedMods.Value = new[] { ruleset.GetAllMods().OfType().First() }; + return new TestPlayer(false); + } + + [SetUpSteps] + public override void SetUpSteps() + { + AddStep("Prepare test API", () => + { + dummyAPI.HandleRequest = request => + { + switch (request) + { + case CreateSoloScoreRequest tokenRequest: + tokenRequest.TriggerSuccess(new APIScoreToken { ID = 1234 }); + return true; + } + + return false; + }; + }); + + base.SetUpSteps(); + + // Ensure track has actually running before attempting to seek + AddUntilStep("wait for track to start running", () => Beatmap.Value.Track.IsRunning); + } + + [Test] + public void TestSubmissionOnResults() + { + AddUntilStep("wait for token request", () => Player.TokenCreationRequested); + + AddStep("seek to completion", () => Player.GameplayClockContainer.Seek(Player.DrawableRuleset.Objects.Last().GetEndTime())); + + AddUntilStep("results displayed", () => Player.GetChildScreen() is ResultsScreen); + + AddUntilStep("wait for submission", () => Player.SubmissionRequested); + } + + [Test] + public void TestSubmissionOnExit() + { + AddUntilStep("wait for token request", () => Player.TokenCreationRequested); + AddStep("exit", () => Player.Exit()); + AddUntilStep("wait for submission", () => Player.SubmissionRequested); + } + } +}