From e2ae3f2ad0287dccd8ffa89c266046cb6a1a7761 Mon Sep 17 00:00:00 2001 From: Salman Alshamrani Date: Tue, 13 May 2025 14:23:50 +0300 Subject: [PATCH] Add test coverage --- .../SongSelectV2/SongSelectTestScene.cs | 3 + .../SongSelectV2/TestSceneSongSelect.cs | 93 +++++++++++++++++++ 2 files changed, 96 insertions(+) diff --git a/osu.Game.Tests/Visual/SongSelectV2/SongSelectTestScene.cs b/osu.Game.Tests/Visual/SongSelectV2/SongSelectTestScene.cs index a2c3791f67..11e41c3a64 100644 --- a/osu.Game.Tests/Visual/SongSelectV2/SongSelectTestScene.cs +++ b/osu.Game.Tests/Visual/SongSelectV2/SongSelectTestScene.cs @@ -18,6 +18,7 @@ using osu.Game.Database; using osu.Game.Overlays; using osu.Game.Overlays.Toolbar; using osu.Game.Rulesets; +using osu.Game.Rulesets.Mods; using osu.Game.Screens; using osu.Game.Screens.Footer; using osu.Game.Screens.Menu; @@ -150,6 +151,8 @@ namespace osu.Game.Tests.Visual.SongSelectV2 AddUntilStep("wait for imported to arrive in carousel", () => Screen.IsNull() || Carousel.Filters.OfType().Single().SetItems.Count > beatmapsCount); } + protected void ChangeMods(params Mod[] mods) => AddStep($"change mods to {string.Join(", ", mods.Select(m => m.Acronym))}", () => SelectedMods.Value = mods); + protected void ChangeRuleset(int rulesetId) { AddStep($"change ruleset to {rulesetId}", () => Ruleset.Value = Rulesets.AvailableRulesets.First(r => r.OnlineID == rulesetId)); diff --git a/osu.Game.Tests/Visual/SongSelectV2/TestSceneSongSelect.cs b/osu.Game.Tests/Visual/SongSelectV2/TestSceneSongSelect.cs index 0939f8f3f3..a2ce824b5e 100644 --- a/osu.Game.Tests/Visual/SongSelectV2/TestSceneSongSelect.cs +++ b/osu.Game.Tests/Visual/SongSelectV2/TestSceneSongSelect.cs @@ -6,12 +6,14 @@ using System.Collections.Generic; using System.Linq; using NUnit.Framework; using osu.Framework.Graphics.Containers; +using osu.Framework.Screens; using osu.Framework.Testing; using osu.Game.Overlays.Dialog; using osu.Game.Overlays.Mods; using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Osu.Mods; using osu.Game.Screens.Footer; +using osu.Game.Screens.Play; using osu.Game.Screens.Select; using osuTK.Input; using FooterButtonMods = osu.Game.Screens.SelectV2.FooterButtonMods; @@ -172,6 +174,97 @@ namespace osu.Game.Tests.Visual.SongSelectV2 }); } + [Test] + public void TestAutoplayShortcut() + { + ImportBeatmapForRuleset(0); + + LoadSongSelect(); + + // song select should automatically select the beatmap for us but this is not implemented yet. + // todo: remove when that's the case. + AddAssert("no beatmap selected", () => Beatmap.IsDefault); + AddStep("select beatmap", () => Beatmap.Value = Beatmaps.GetWorkingBeatmap(Beatmaps.GetAllUsableBeatmapSets().Single().Beatmaps.First())); + AddAssert("beatmap selected", () => !Beatmap.IsDefault); + + AddStep("press ctrl+enter", () => + { + InputManager.PressKey(Key.ControlLeft); + InputManager.Key(Key.Enter); + InputManager.ReleaseKey(Key.ControlLeft); + }); + + AddUntilStep("wait for player", () => Stack.CurrentScreen is PlayerLoader); + + AddAssert("autoplay selected", () => Screen.Mods.Value.Single() is ModAutoplay); + + AddUntilStep("wait for return to ss", () => Screen.IsCurrentScreen()); + + AddAssert("no mods selected", () => Screen.Mods.Value.Count == 0); + } + + [Test] + public void TestAutoplayShortcutKeepsAutoplayIfSelectedAlready() + { + ImportBeatmapForRuleset(0); + + LoadSongSelect(); + + // song select should automatically select the beatmap for us but this is not implemented yet. + // todo: remove when that's the case. + AddAssert("no beatmap selected", () => Beatmap.IsDefault); + AddStep("select beatmap", () => Beatmap.Value = Beatmaps.GetWorkingBeatmap(Beatmaps.GetAllUsableBeatmapSets().Single().Beatmaps.First())); + AddAssert("beatmap selected", () => !Beatmap.IsDefault); + + ChangeMods(new OsuModAutoplay()); + + AddStep("press ctrl+enter", () => + { + InputManager.PressKey(Key.ControlLeft); + InputManager.Key(Key.Enter); + InputManager.ReleaseKey(Key.ControlLeft); + }); + + AddUntilStep("wait for player", () => Stack.CurrentScreen is PlayerLoader); + + AddAssert("autoplay selected", () => Screen.Mods.Value.Single() is ModAutoplay); + + AddUntilStep("wait for return to ss", () => Screen.IsCurrentScreen()); + + AddAssert("autoplay still selected", () => Screen.Mods.Value.Single() is ModAutoplay); + } + + [Test] + public void TestAutoplayShortcutReturnsInitialModsOnExit() + { + ImportBeatmapForRuleset(0); + + LoadSongSelect(); + + // song select should automatically select the beatmap for us but this is not implemented yet. + // todo: remove when that's the case. + AddAssert("no beatmap selected", () => Beatmap.IsDefault); + AddStep("select beatmap", () => Beatmap.Value = Beatmaps.GetWorkingBeatmap(Beatmaps.GetAllUsableBeatmapSets().Single().Beatmaps.First())); + AddAssert("beatmap selected", () => !Beatmap.IsDefault); + + ChangeMods(new OsuModRelax()); + + AddStep("press ctrl+enter", () => + { + InputManager.PressKey(Key.ControlLeft); + InputManager.Key(Key.Enter); + InputManager.ReleaseKey(Key.ControlLeft); + }); + + AddUntilStep("wait for player", () => Stack.CurrentScreen is PlayerLoader); + + AddAssert("only autoplay selected", () => Screen.Mods.Value.Single() is ModAutoplay); + + AddUntilStep("wait for return to ss", () => Screen.IsCurrentScreen()); + + AddAssert("relax returned", () => Screen.Mods.Value.Single() is ModRelax); + } + #endregion #region Footer