From 1298b98534246c5dc325a2cb9aae3333f1f38eeb Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Sun, 23 Jun 2024 08:22:54 +0300 Subject: [PATCH] Update test coverage --- .../TestSceneFreeModSelectOverlay.cs | 2 +- .../TestSceneModSelectOverlay.cs | 63 +++++++++++-------- .../UserInterface/TestSceneModSettingsArea.cs | 42 ------------- 3 files changed, 38 insertions(+), 69 deletions(-) delete mode 100644 osu.Game.Tests/Visual/UserInterface/TestSceneModSettingsArea.cs diff --git a/osu.Game.Tests/Visual/Multiplayer/TestSceneFreeModSelectOverlay.cs b/osu.Game.Tests/Visual/Multiplayer/TestSceneFreeModSelectOverlay.cs index a4feffddfb..938ab1e9f4 100644 --- a/osu.Game.Tests/Visual/Multiplayer/TestSceneFreeModSelectOverlay.cs +++ b/osu.Game.Tests/Visual/Multiplayer/TestSceneFreeModSelectOverlay.cs @@ -58,7 +58,7 @@ namespace osu.Game.Tests.Visual.Multiplayer AddStep("select difficulty adjust", () => freeModSelectOverlay.SelectedMods.Value = new[] { new OsuModDifficultyAdjust() }); AddWaitStep("wait some", 3); - AddAssert("customisation area not expanded", () => this.ChildrenOfType().Single().Height == 0); + AddAssert("customisation area not expanded", () => !this.ChildrenOfType().Single().Expanded.Value); } [Test] diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneModSelectOverlay.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneModSelectOverlay.cs index a1452ddb31..39017298ac 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneModSelectOverlay.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneModSelectOverlay.cs @@ -7,7 +7,6 @@ using System.Linq; using NUnit.Framework; using osu.Framework.Allocation; using osu.Framework.Bindables; -using osu.Framework.Extensions.ObjectExtensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Input; @@ -26,7 +25,6 @@ using osu.Game.Rulesets.Osu; using osu.Game.Rulesets.Osu.Mods; using osu.Game.Rulesets.Taiko.Mods; using osu.Game.Tests.Mods; -using osuTK; using osuTK.Input; namespace osu.Game.Tests.Visual.UserInterface @@ -225,7 +223,7 @@ namespace osu.Game.Tests.Visual.UserInterface AddStep("dismiss mod customisation via toggle", () => { - InputManager.MoveMouseTo(modSelectOverlay.CustomisationButton.AsNonNull()); + InputManager.MoveMouseTo(modSelectOverlay.ChildrenOfType().Single()); InputManager.Click(MouseButton.Left); }); assertCustomisationToggleState(disabled: false, active: false); @@ -258,7 +256,7 @@ namespace osu.Game.Tests.Visual.UserInterface } [Test] - public void TestDismissCustomisationViaDimmedArea() + public void TestDismissCustomisationViaClickingAway() { createScreen(); assertCustomisationToggleState(disabled: true, active: false); @@ -266,18 +264,23 @@ namespace osu.Game.Tests.Visual.UserInterface AddStep("select difficulty adjust via panel", () => getPanelForMod(typeof(OsuModDifficultyAdjust)).TriggerClick()); assertCustomisationToggleState(disabled: false, active: true); - AddStep("move mouse to settings area", () => InputManager.MoveMouseTo(this.ChildrenOfType().Single())); - AddStep("move mouse to dimmed area", () => - { - InputManager.MoveMouseTo(new Vector2( - modSelectOverlay.ScreenSpaceDrawQuad.TopLeft.X, - (modSelectOverlay.ScreenSpaceDrawQuad.TopLeft.Y + modSelectOverlay.ScreenSpaceDrawQuad.BottomLeft.Y) / 2)); - }); + AddStep("move mouse to search bar", () => InputManager.MoveMouseTo(modSelectOverlay.ChildrenOfType().Single())); AddStep("click", () => InputManager.Click(MouseButton.Left)); assertCustomisationToggleState(disabled: false, active: false); + } - AddStep("move mouse to first mod panel", () => InputManager.MoveMouseTo(modSelectOverlay.ChildrenOfType().First())); - AddAssert("first mod panel is hovered", () => modSelectOverlay.ChildrenOfType().First().IsHovered); + [Test] + public void TestDismissCustomisationWhenHidingOverlay() + { + createScreen(); + assertCustomisationToggleState(disabled: true, active: false); + + AddStep("select difficulty adjust via panel", () => getPanelForMod(typeof(OsuModDifficultyAdjust)).TriggerClick()); + assertCustomisationToggleState(disabled: false, active: true); + + AddStep("hide overlay", () => modSelectOverlay.Hide()); + AddStep("show overlay again", () => modSelectOverlay.Show()); + assertCustomisationToggleState(disabled: false, active: false); } /// @@ -339,7 +342,7 @@ namespace osu.Game.Tests.Visual.UserInterface createScreen(); changeRuleset(0); - AddStep("Select all fun mods", () => + AddStep("Select all difficulty-increase mods", () => { modSelectOverlay.ChildrenOfType() .Single(c => c.ModType == ModType.DifficultyIncrease) @@ -641,13 +644,16 @@ namespace osu.Game.Tests.Visual.UserInterface AddStep("select DT", () => SelectedMods.Value = new Mod[] { new OsuModDoubleTime() }); AddAssert("DT selected", () => modSelectOverlay.ChildrenOfType().Count(panel => panel.Active.Value), () => Is.EqualTo(1)); - AddStep("open customisation area", () => modSelectOverlay.CustomisationButton!.TriggerClick()); - assertCustomisationToggleState(false, true); + // todo: rewrite + AddStep("open customisation area", () => modSelectOverlay.ChildrenOfType().Single().TriggerClick()); + assertCustomisationToggleState(disabled: false, active: true); + AddStep("hover over mod settings slider", () => { - var slider = modSelectOverlay.ChildrenOfType().Single().ChildrenOfType>().First(); + var slider = modSelectOverlay.ChildrenOfType().Single().ChildrenOfType>().First(); InputManager.MoveMouseTo(slider); }); + AddStep("press right arrow", () => InputManager.PressKey(Key.Right)); AddAssert("DT speed changed", () => !SelectedMods.Value.OfType().Single().SpeedChange.IsDefault); @@ -744,9 +750,10 @@ namespace osu.Game.Tests.Visual.UserInterface AddStep("select difficulty adjust via panel", () => getPanelForMod(typeof(OsuModDifficultyAdjust)).TriggerClick()); assertCustomisationToggleState(disabled: false, active: true); - AddAssert("back button disabled", () => !modSelectOverlay.BackButton.Enabled.Value); AddStep("dismiss customisation area", () => InputManager.Key(Key.Escape)); + AddAssert("mod select still visible", () => modSelectOverlay.State.Value == Visibility.Visible); + AddStep("click back button", () => { InputManager.MoveMouseTo(modSelectOverlay.BackButton); @@ -870,8 +877,8 @@ namespace osu.Game.Tests.Visual.UserInterface // it is instrumental in the reproduction of the failure scenario that this test is supposed to cover. AddStep("force collection", GC.Collect); - AddStep("open customisation area", () => modSelectOverlay.CustomisationButton!.TriggerClick()); - AddStep("reset half time speed to default", () => modSelectOverlay.ChildrenOfType().Single() + AddStep("open customisation area", () => modSelectOverlay.ChildrenOfType().Single().TriggerClick()); + AddStep("reset half time speed to default", () => modSelectOverlay.ChildrenOfType().Single() .ChildrenOfType>().Single().TriggerClick()); AddUntilStep("difficulty multiplier display shows correct value", () => modSelectOverlay.ChildrenOfType().Single().ModMultiplier.Value, () => Is.EqualTo(0.3).Within(Precision.DOUBLE_EPSILON)); @@ -883,18 +890,23 @@ namespace osu.Game.Tests.Visual.UserInterface createScreen(); AddStep("select DT + HD + DF", () => SelectedMods.Value = new Mod[] { new OsuModDoubleTime(), new OsuModHidden(), new OsuModDeflate() }); + AddStep("open customisation panel", () => this.ChildrenOfType().Single().TriggerClick()); AddAssert("mod settings order: DT, HD, DF", () => { - var columns = this.ChildrenOfType().Single().ChildrenOfType(); + var columns = this.ChildrenOfType(); return columns.ElementAt(0).Mod is OsuModDoubleTime && columns.ElementAt(1).Mod is OsuModHidden && columns.ElementAt(2).Mod is OsuModDeflate; }); - AddStep("replace DT with NC", () => SelectedMods.Value = SelectedMods.Value.Where(m => m is not ModDoubleTime).Append(new OsuModNightcore()).ToList()); + AddStep("replace DT with NC", () => + { + SelectedMods.Value = SelectedMods.Value.Where(m => m is not ModDoubleTime).Append(new OsuModNightcore()).ToList(); + this.ChildrenOfType().Single().TriggerClick(); + }); AddAssert("mod settings order: NC, HD, DF", () => { - var columns = this.ChildrenOfType().Single().ChildrenOfType(); + var columns = this.ChildrenOfType(); return columns.ElementAt(0).Mod is OsuModNightcore && columns.ElementAt(1).Mod is OsuModHidden && columns.ElementAt(2).Mod is OsuModDeflate; @@ -915,8 +927,8 @@ namespace osu.Game.Tests.Visual.UserInterface private void assertCustomisationToggleState(bool disabled, bool active) { - AddAssert($"customisation toggle is {(disabled ? "" : "not ")}disabled", () => modSelectOverlay.CustomisationButton.AsNonNull().Active.Disabled == disabled); - AddAssert($"customisation toggle is {(active ? "" : "not ")}active", () => modSelectOverlay.CustomisationButton.AsNonNull().Active.Value == active); + AddUntilStep($"customisation panel is {(disabled ? "" : "not ")}disabled", () => modSelectOverlay.ChildrenOfType().Single().State.Value == (disabled ? Visibility.Hidden : Visibility.Visible)); + AddAssert($"customisation panel is {(active ? "" : "not ")}active", () => modSelectOverlay.ChildrenOfType().Single().Expanded.Value == active); } private T getSelectedMod() where T : Mod => SelectedMods.Value.OfType().Single(); @@ -929,7 +941,6 @@ namespace osu.Game.Tests.Visual.UserInterface protected override bool ShowPresets => true; public new ShearedButton BackButton => base.BackButton; - public new ShearedToggleButton? CustomisationButton => base.CustomisationButton; } private class TestUnimplementedMod : Mod diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneModSettingsArea.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneModSettingsArea.cs deleted file mode 100644 index dac1f94c28..0000000000 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneModSettingsArea.cs +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. -// See the LICENCE file in the repository root for full licence text. - -#nullable disable - -using System; -using NUnit.Framework; -using osu.Framework.Allocation; -using osu.Framework.Graphics; -using osu.Framework.Graphics.Containers; -using osu.Game.Overlays; -using osu.Game.Overlays.Mods; -using osu.Game.Rulesets.Mods; -using osu.Game.Rulesets.Osu.Mods; - -namespace osu.Game.Tests.Visual.UserInterface -{ - [TestFixture] - public partial class TestSceneModSettingsArea : OsuTestScene - { - [Cached] - private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Green); - - [Test] - public void TestModToggleArea() - { - ModSettingsArea modSettingsArea = null; - - AddStep("create content", () => Child = new Container - { - RelativeSizeAxes = Axes.Both, - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - Child = modSettingsArea = new ModSettingsArea() - }); - AddStep("set DT", () => modSettingsArea.SelectedMods.Value = new[] { new OsuModDoubleTime() }); - AddStep("set DA", () => modSettingsArea.SelectedMods.Value = new Mod[] { new OsuModDifficultyAdjust() }); - AddStep("set FL+WU+DA+AD", () => modSettingsArea.SelectedMods.Value = new Mod[] { new OsuModFlashlight(), new ModWindUp(), new OsuModDifficultyAdjust(), new OsuModApproachDifferent() }); - AddStep("set empty", () => modSettingsArea.SelectedMods.Value = Array.Empty()); - } - } -}