From d505c529cd217abfbf697a5e9f9f8c1ebb2da14c Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 7 Feb 2025 15:06:21 +0900 Subject: [PATCH] Adjust tests in line with new expectations --- .../SongSelect/BeatmapCarouselV2TestScene.cs | 28 ++++++++ ...ceneBeatmapCarouselV2DifficultyGrouping.cs | 64 ++++--------------- .../TestSceneBeatmapCarouselV2NoGrouping.cs | 54 +++++----------- 3 files changed, 58 insertions(+), 88 deletions(-) diff --git a/osu.Game.Tests/Visual/SongSelect/BeatmapCarouselV2TestScene.cs b/osu.Game.Tests/Visual/SongSelect/BeatmapCarouselV2TestScene.cs index f17f312e9f..be0d0bf79a 100644 --- a/osu.Game.Tests/Visual/SongSelect/BeatmapCarouselV2TestScene.cs +++ b/osu.Game.Tests/Visual/SongSelect/BeatmapCarouselV2TestScene.cs @@ -2,6 +2,7 @@ // See the LICENCE file in the repository root for full licence text. using System; +using System.Collections.Generic; using System.Linq; using NUnit.Framework; using osu.Framework.Allocation; @@ -20,6 +21,7 @@ using osu.Game.Screens.Select; using osu.Game.Screens.SelectV2; using osu.Game.Tests.Beatmaps; using osu.Game.Tests.Resources; +using osuTK; using osuTK.Graphics; using osuTK.Input; using BeatmapCarousel = osu.Game.Screens.SelectV2.BeatmapCarousel; @@ -164,6 +166,15 @@ namespace osu.Game.Tests.Visual.SongSelect }); } + protected IEnumerable GetVisiblePanels() + where T : Drawable + { + return Carousel.ChildrenOfType().Single() + .ChildrenOfType() + .Where(p => ((ICarouselPanel)p).Item?.IsVisible == true) + .OrderBy(p => p.Y); + } + protected void ClickVisiblePanel(int index) where T : Drawable { @@ -178,6 +189,23 @@ namespace osu.Game.Tests.Visual.SongSelect }); } + protected void ClickVisiblePanelWithOffset(int index, Vector2 positionOffsetFromCentre) + where T : Drawable + { + AddStep($"move mouse to panel {index} with offset {positionOffsetFromCentre}", () => + { + var panel = Carousel.ChildrenOfType().Single() + .ChildrenOfType() + .Where(p => ((ICarouselPanel)p).Item?.IsVisible == true) + .OrderBy(p => p.Y) + .ElementAt(index); + + InputManager.MoveMouseTo(panel.ScreenSpaceDrawQuad.Centre + panel.ToScreenSpace(positionOffsetFromCentre) - panel.ToScreenSpace(Vector2.Zero)); + }); + + AddStep("click", () => InputManager.Click(MouseButton.Left)); + } + /// /// Add requested beatmap sets count to list. /// diff --git a/osu.Game.Tests/Visual/SongSelect/TestSceneBeatmapCarouselV2DifficultyGrouping.cs b/osu.Game.Tests/Visual/SongSelect/TestSceneBeatmapCarouselV2DifficultyGrouping.cs index 83e0e77fa6..f631dfc562 100644 --- a/osu.Game.Tests/Visual/SongSelect/TestSceneBeatmapCarouselV2DifficultyGrouping.cs +++ b/osu.Game.Tests/Visual/SongSelect/TestSceneBeatmapCarouselV2DifficultyGrouping.cs @@ -1,7 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using System; using System.Linq; using NUnit.Framework; using osu.Framework.Testing; @@ -10,7 +9,6 @@ using osu.Game.Screens.Select; using osu.Game.Screens.Select.Filter; using osu.Game.Screens.SelectV2; using osuTK; -using osuTK.Input; namespace osu.Game.Tests.Visual.SongSelect { @@ -153,60 +151,24 @@ namespace osu.Game.Tests.Visual.SongSelect [Test] public void TestInputHandlingWithinGaps() { - AddBeatmaps(5, 2); - WaitForDrawablePanels(); - SelectNextGroup(); + AddAssert("no beatmaps visible", () => !GetVisiblePanels().Any()); - clickOnPanel(0, 1, p => p.LayoutRectangle.TopLeft + new Vector2(20f, -1f)); - WaitForGroupSelection(0, 1); + // Clicks just above the first group panel should not actuate any action. + ClickVisiblePanelWithOffset(0, new Vector2(0, -(GroupPanel.HEIGHT / 2 + 1))); - clickOnPanel(0, 0, p => p.LayoutRectangle.BottomLeft + new Vector2(20f, 1f)); + AddAssert("no beatmaps visible", () => !GetVisiblePanels().Any()); + + ClickVisiblePanelWithOffset(0, new Vector2(0, -(GroupPanel.HEIGHT / 2))); + + AddUntilStep("wait for beatmaps visible", () => GetVisiblePanels().Any()); + CheckNoSelection(); + + // Beatmap panels expand their selection area to cover holes from spacing. + ClickVisiblePanelWithOffset(0, new Vector2(0, -(CarouselItem.DEFAULT_HEIGHT / 2 + 1))); WaitForGroupSelection(0, 0); - SelectNextPanel(); - Select(); + ClickVisiblePanelWithOffset(1, new Vector2(0, (CarouselItem.DEFAULT_HEIGHT / 2 + 1))); WaitForGroupSelection(0, 1); - - clickOnGroup(0, p => p.LayoutRectangle.BottomLeft + new Vector2(20f, 1f)); - AddAssert("group 0 collapsed", () => this.ChildrenOfType().OrderBy(g => g.Y).ElementAt(0).Expanded.Value, () => Is.False); - clickOnGroup(0, p => p.LayoutRectangle.Centre); - AddAssert("group 0 expanded", () => this.ChildrenOfType().OrderBy(g => g.Y).ElementAt(0).Expanded.Value, () => Is.True); - - AddStep("scroll to end", () => Scroll.ScrollToEnd(false)); - clickOnPanel(0, 4, p => p.LayoutRectangle.BottomLeft + new Vector2(20f, 1f)); - WaitForGroupSelection(0, 4); - - clickOnGroup(1, p => p.LayoutRectangle.TopLeft + new Vector2(20f, -1f)); - AddAssert("group 1 expanded", () => this.ChildrenOfType().OrderBy(g => g.Y).ElementAt(1).Expanded.Value, () => Is.True); - } - - private void clickOnGroup(int group, Func pos) - { - AddStep($"click on group{group}", () => - { - var groupingFilter = Carousel.Filters.OfType().Single(); - var model = groupingFilter.GroupItems.Keys.ElementAt(group); - - var panel = this.ChildrenOfType().Single(b => ReferenceEquals(b.Item!.Model, model)); - InputManager.MoveMouseTo(panel.ToScreenSpace(pos(panel))); - InputManager.Click(MouseButton.Left); - }); - } - - private void clickOnPanel(int group, int panel, Func pos) - { - AddStep($"click on group{group} panel{panel}", () => - { - var groupingFilter = Carousel.Filters.OfType().Single(); - - var g = groupingFilter.GroupItems.Keys.ElementAt(group); - // offset by one because the group itself is included in the items list. - object model = groupingFilter.GroupItems[g].ElementAt(panel + 1).Model; - - var p = this.ChildrenOfType().Single(b => ReferenceEquals(b.Item!.Model, model)); - InputManager.MoveMouseTo(p.ToScreenSpace(pos(p))); - InputManager.Click(MouseButton.Left); - }); } } } diff --git a/osu.Game.Tests/Visual/SongSelect/TestSceneBeatmapCarouselV2NoGrouping.cs b/osu.Game.Tests/Visual/SongSelect/TestSceneBeatmapCarouselV2NoGrouping.cs index 566c2f1798..1359b5c58e 100644 --- a/osu.Game.Tests/Visual/SongSelect/TestSceneBeatmapCarouselV2NoGrouping.cs +++ b/osu.Game.Tests/Visual/SongSelect/TestSceneBeatmapCarouselV2NoGrouping.cs @@ -1,7 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using System; using System.Linq; using NUnit.Framework; using osu.Framework.Testing; @@ -209,31 +208,34 @@ namespace osu.Game.Tests.Visual.SongSelect } [Test] + [Solo] public void TestInputHandlingWithinGaps() { AddBeatmaps(2, 5); WaitForDrawablePanels(); - SelectNextGroup(); - clickOnDifficulty(0, 1, p => p.LayoutRectangle.TopLeft + new Vector2(20f, -1f)); - WaitForSelection(0, 1); + AddAssert("no beatmaps visible", () => !GetVisiblePanels().Any()); - clickOnDifficulty(0, 0, p => p.LayoutRectangle.BottomLeft + new Vector2(20f, 1f)); + // Clicks just above the first group panel should not actuate any action. + ClickVisiblePanelWithOffset(0, new Vector2(0, -(BeatmapSetPanel.HEIGHT / 2 + 1))); + + AddAssert("no beatmaps visible", () => !GetVisiblePanels().Any()); + + ClickVisiblePanelWithOffset(0, new Vector2(0, -(BeatmapSetPanel.HEIGHT / 2))); + + AddUntilStep("wait for beatmaps visible", () => GetVisiblePanels().Any()); WaitForSelection(0, 0); - SelectNextPanel(); - Select(); - WaitForSelection(0, 1); - - clickOnSet(0, p => p.LayoutRectangle.BottomLeft + new Vector2(20f, 1f)); + // Beatmap panels expand their selection area to cover holes from spacing. + ClickVisiblePanelWithOffset(1, new Vector2(0, -(CarouselItem.DEFAULT_HEIGHT / 2 + 1))); WaitForSelection(0, 0); - AddStep("scroll to end", () => Scroll.ScrollToEnd(false)); - clickOnDifficulty(0, 4, p => p.LayoutRectangle.BottomLeft + new Vector2(20f, 1f)); - WaitForSelection(0, 4); + // Panels with higher depth will handle clicks in the gutters for simplicity. + ClickVisiblePanelWithOffset(2, new Vector2(0, (CarouselItem.DEFAULT_HEIGHT / 2 + 1))); + WaitForSelection(0, 2); - clickOnSet(1, p => p.LayoutRectangle.TopLeft + new Vector2(20f, -1f)); - WaitForSelection(1, 0); + ClickVisiblePanelWithOffset(3, new Vector2(0, (CarouselItem.DEFAULT_HEIGHT / 2 + 1))); + WaitForSelection(0, 3); } private void checkSelectionIterating(bool isIterating) @@ -249,27 +251,5 @@ namespace osu.Game.Tests.Visual.SongSelect AddUntilStep("selection not changed", () => Carousel.CurrentSelection == selection); } } - - private void clickOnSet(int set, Func pos) - { - AddStep($"click on set{set}", () => - { - var model = BeatmapSets[set]; - var panel = this.ChildrenOfType().Single(b => ReferenceEquals(b.Item!.Model, model)); - InputManager.MoveMouseTo(panel.ToScreenSpace(pos(panel))); - InputManager.Click(MouseButton.Left); - }); - } - - private void clickOnDifficulty(int set, int diff, Func pos) - { - AddStep($"click on set{set} diff{diff}", () => - { - var model = BeatmapSets[set].Beatmaps[diff]; - var panel = this.ChildrenOfType().Single(b => ReferenceEquals(b.Item!.Model, model)); - InputManager.MoveMouseTo(panel.ToScreenSpace(pos(panel))); - InputManager.Click(MouseButton.Left); - }); - } } }