1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-19 19:33:22 +08:00

Adjust tests in line with new expectations

This commit is contained in:
Dean Herbert 2025-02-07 15:06:21 +09:00
parent d73f275143
commit d505c529cd
No known key found for this signature in database
3 changed files with 58 additions and 88 deletions

View File

@ -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<T> GetVisiblePanels<T>()
where T : Drawable
{
return Carousel.ChildrenOfType<UserTrackingScrollContainer>().Single()
.ChildrenOfType<T>()
.Where(p => ((ICarouselPanel)p).Item?.IsVisible == true)
.OrderBy(p => p.Y);
}
protected void ClickVisiblePanel<T>(int index)
where T : Drawable
{
@ -178,6 +189,23 @@ namespace osu.Game.Tests.Visual.SongSelect
});
}
protected void ClickVisiblePanelWithOffset<T>(int index, Vector2 positionOffsetFromCentre)
where T : Drawable
{
AddStep($"move mouse to panel {index} with offset {positionOffsetFromCentre}", () =>
{
var panel = Carousel.ChildrenOfType<UserTrackingScrollContainer>().Single()
.ChildrenOfType<T>()
.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));
}
/// <summary>
/// Add requested beatmap sets count to list.
/// </summary>

View File

@ -1,7 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. 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<BeatmapPanel>().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<GroupPanel>(0, new Vector2(0, -(GroupPanel.HEIGHT / 2 + 1)));
clickOnPanel(0, 0, p => p.LayoutRectangle.BottomLeft + new Vector2(20f, 1f));
AddAssert("no beatmaps visible", () => !GetVisiblePanels<BeatmapPanel>().Any());
ClickVisiblePanelWithOffset<GroupPanel>(0, new Vector2(0, -(GroupPanel.HEIGHT / 2)));
AddUntilStep("wait for beatmaps visible", () => GetVisiblePanels<BeatmapPanel>().Any());
CheckNoSelection();
// Beatmap panels expand their selection area to cover holes from spacing.
ClickVisiblePanelWithOffset<BeatmapPanel>(0, new Vector2(0, -(CarouselItem.DEFAULT_HEIGHT / 2 + 1)));
WaitForGroupSelection(0, 0);
SelectNextPanel();
Select();
ClickVisiblePanelWithOffset<BeatmapPanel>(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<GroupPanel>().OrderBy(g => g.Y).ElementAt(0).Expanded.Value, () => Is.False);
clickOnGroup(0, p => p.LayoutRectangle.Centre);
AddAssert("group 0 expanded", () => this.ChildrenOfType<GroupPanel>().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<GroupPanel>().OrderBy(g => g.Y).ElementAt(1).Expanded.Value, () => Is.True);
}
private void clickOnGroup(int group, Func<GroupPanel, Vector2> pos)
{
AddStep($"click on group{group}", () =>
{
var groupingFilter = Carousel.Filters.OfType<BeatmapCarouselFilterGrouping>().Single();
var model = groupingFilter.GroupItems.Keys.ElementAt(group);
var panel = this.ChildrenOfType<GroupPanel>().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<BeatmapPanel, Vector2> pos)
{
AddStep($"click on group{group} panel{panel}", () =>
{
var groupingFilter = Carousel.Filters.OfType<BeatmapCarouselFilterGrouping>().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<BeatmapPanel>().Single(b => ReferenceEquals(b.Item!.Model, model));
InputManager.MoveMouseTo(p.ToScreenSpace(pos(p)));
InputManager.Click(MouseButton.Left);
});
}
}
}

View File

@ -1,7 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. 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<BeatmapPanel>().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<BeatmapSetPanel>(0, new Vector2(0, -(BeatmapSetPanel.HEIGHT / 2 + 1)));
AddAssert("no beatmaps visible", () => !GetVisiblePanels<BeatmapPanel>().Any());
ClickVisiblePanelWithOffset<BeatmapSetPanel>(0, new Vector2(0, -(BeatmapSetPanel.HEIGHT / 2)));
AddUntilStep("wait for beatmaps visible", () => GetVisiblePanels<BeatmapPanel>().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<BeatmapPanel>(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<BeatmapPanel>(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<BeatmapPanel>(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<BeatmapSetPanel, Vector2> pos)
{
AddStep($"click on set{set}", () =>
{
var model = BeatmapSets[set];
var panel = this.ChildrenOfType<BeatmapSetPanel>().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<BeatmapPanel, Vector2> pos)
{
AddStep($"click on set{set} diff{diff}", () =>
{
var model = BeatmapSets[set].Beatmaps[diff];
var panel = this.ChildrenOfType<BeatmapPanel>().Single(b => ReferenceEquals(b.Item!.Model, model));
InputManager.MoveMouseTo(panel.ToScreenSpace(pos(panel)));
InputManager.Click(MouseButton.Left);
});
}
}
}