From 3d61a217ecee2dfb7b90b29f7772aadb1dcc09d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Tue, 2 Jul 2024 14:21:05 +0200 Subject: [PATCH] Add test coverage --- .../Editing/TestSceneEditorTestGameplay.cs | 111 ++++++++++++++++++ 1 file changed, 111 insertions(+) diff --git a/osu.Game.Tests/Visual/Editing/TestSceneEditorTestGameplay.cs b/osu.Game.Tests/Visual/Editing/TestSceneEditorTestGameplay.cs index 7dcb8766dd..23efb40d3f 100644 --- a/osu.Game.Tests/Visual/Editing/TestSceneEditorTestGameplay.cs +++ b/osu.Game.Tests/Visual/Editing/TestSceneEditorTestGameplay.cs @@ -16,6 +16,7 @@ using osu.Game.Configuration; using osu.Game.Rulesets; using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Osu; +using osu.Game.Rulesets.UI; using osu.Game.Screens.Backgrounds; using osu.Game.Screens.Edit; using osu.Game.Screens.Edit.Components.Timelines.Summary; @@ -224,6 +225,116 @@ namespace osu.Game.Tests.Visual.Editing AddAssert("time reverted to 00:01:00", () => EditorClock.CurrentTime, () => Is.EqualTo(60_000)); } + [Test] + public void TestAutoplayToggle() + { + AddStep("click test gameplay button", () => + { + var button = Editor.ChildrenOfType().Single(); + + InputManager.MoveMouseTo(button); + InputManager.Click(MouseButton.Left); + }); + + EditorPlayer editorPlayer = null; + AddUntilStep("player pushed", () => (editorPlayer = Stack.CurrentScreen as EditorPlayer) != null); + AddUntilStep("no replay active", () => editorPlayer.ChildrenOfType().Single().ReplayScore, () => Is.Null); + AddStep("press Tab", () => InputManager.Key(Key.Tab)); + AddUntilStep("replay active", () => editorPlayer.ChildrenOfType().Single().ReplayScore, () => Is.Not.Null); + AddStep("press Tab", () => InputManager.Key(Key.Tab)); + AddUntilStep("no replay active", () => editorPlayer.ChildrenOfType().Single().ReplayScore, () => Is.Null); + AddStep("exit player", () => editorPlayer.Exit()); + AddUntilStep("current screen is editor", () => Stack.CurrentScreen is Editor); + } + + [Test] + public void TestQuickPause() + { + AddStep("click test gameplay button", () => + { + var button = Editor.ChildrenOfType().Single(); + + InputManager.MoveMouseTo(button); + InputManager.Click(MouseButton.Left); + }); + + EditorPlayer editorPlayer = null; + AddUntilStep("player pushed", () => (editorPlayer = Stack.CurrentScreen as EditorPlayer) != null); + AddUntilStep("clock running", () => editorPlayer.ChildrenOfType().Single().IsPaused.Value, () => Is.False); + AddStep("press Ctrl-P", () => + { + InputManager.PressKey(Key.ControlLeft); + InputManager.Key(Key.P); + InputManager.ReleaseKey(Key.ControlLeft); + }); + AddUntilStep("clock not running", () => editorPlayer.ChildrenOfType().Single().IsPaused.Value, () => Is.True); + AddStep("press Ctrl-P", () => + { + InputManager.PressKey(Key.ControlLeft); + InputManager.Key(Key.P); + InputManager.ReleaseKey(Key.ControlLeft); + }); + AddUntilStep("clock running", () => editorPlayer.ChildrenOfType().Single().IsPaused.Value, () => Is.False); + AddStep("exit player", () => editorPlayer.Exit()); + AddUntilStep("current screen is editor", () => Stack.CurrentScreen is Editor); + } + + [Test] + public void TestQuickExitAtInitialPosition() + { + AddStep("seek to 00:01:00", () => EditorClock.Seek(60_000)); + AddStep("click test gameplay button", () => + { + var button = Editor.ChildrenOfType().Single(); + + InputManager.MoveMouseTo(button); + InputManager.Click(MouseButton.Left); + }); + + EditorPlayer editorPlayer = null; + AddUntilStep("player pushed", () => (editorPlayer = Stack.CurrentScreen as EditorPlayer) != null); + + GameplayClockContainer gameplayClockContainer = null; + AddStep("fetch gameplay clock", () => gameplayClockContainer = editorPlayer.ChildrenOfType().First()); + AddUntilStep("gameplay clock running", () => gameplayClockContainer.IsRunning); + // when the gameplay test is entered, the clock is expected to continue from where it was in the main editor... + AddAssert("gameplay time past 00:01:00", () => gameplayClockContainer.CurrentTime >= 60_000); + + AddWaitStep("wait some", 5); + + AddStep("exit player", () => InputManager.PressKey(Key.F1)); + AddUntilStep("current screen is editor", () => Stack.CurrentScreen is Editor); + AddAssert("time reverted to 00:01:00", () => EditorClock.CurrentTime, () => Is.EqualTo(60_000)); + } + + [Test] + public void TestQuickExitAtCurrentPosition() + { + AddStep("seek to 00:01:00", () => EditorClock.Seek(60_000)); + AddStep("click test gameplay button", () => + { + var button = Editor.ChildrenOfType().Single(); + + InputManager.MoveMouseTo(button); + InputManager.Click(MouseButton.Left); + }); + + EditorPlayer editorPlayer = null; + AddUntilStep("player pushed", () => (editorPlayer = Stack.CurrentScreen as EditorPlayer) != null); + + GameplayClockContainer gameplayClockContainer = null; + AddStep("fetch gameplay clock", () => gameplayClockContainer = editorPlayer.ChildrenOfType().First()); + AddUntilStep("gameplay clock running", () => gameplayClockContainer.IsRunning); + // when the gameplay test is entered, the clock is expected to continue from where it was in the main editor... + AddAssert("gameplay time past 00:01:00", () => gameplayClockContainer.CurrentTime >= 60_000); + + AddWaitStep("wait some", 5); + + AddStep("exit player", () => InputManager.PressKey(Key.F2)); + AddUntilStep("current screen is editor", () => Stack.CurrentScreen is Editor); + AddAssert("time moved forward", () => EditorClock.CurrentTime, () => Is.GreaterThan(60_000)); + } + public override void TearDownSteps() { base.TearDownSteps();