mirror of
https://github.com/ppy/osu.git
synced 2025-02-21 12:43:09 +08:00
Adjust tests in line with new expectations
This commit is contained in:
parent
d73f275143
commit
d505c529cd
@ -2,6 +2,7 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
@ -20,6 +21,7 @@ using osu.Game.Screens.Select;
|
|||||||
using osu.Game.Screens.SelectV2;
|
using osu.Game.Screens.SelectV2;
|
||||||
using osu.Game.Tests.Beatmaps;
|
using osu.Game.Tests.Beatmaps;
|
||||||
using osu.Game.Tests.Resources;
|
using osu.Game.Tests.Resources;
|
||||||
|
using osuTK;
|
||||||
using osuTK.Graphics;
|
using osuTK.Graphics;
|
||||||
using osuTK.Input;
|
using osuTK.Input;
|
||||||
using BeatmapCarousel = osu.Game.Screens.SelectV2.BeatmapCarousel;
|
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)
|
protected void ClickVisiblePanel<T>(int index)
|
||||||
where T : Drawable
|
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>
|
/// <summary>
|
||||||
/// Add requested beatmap sets count to list.
|
/// Add requested beatmap sets count to list.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Framework.Testing;
|
using osu.Framework.Testing;
|
||||||
@ -10,7 +9,6 @@ using osu.Game.Screens.Select;
|
|||||||
using osu.Game.Screens.Select.Filter;
|
using osu.Game.Screens.Select.Filter;
|
||||||
using osu.Game.Screens.SelectV2;
|
using osu.Game.Screens.SelectV2;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
using osuTK.Input;
|
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual.SongSelect
|
namespace osu.Game.Tests.Visual.SongSelect
|
||||||
{
|
{
|
||||||
@ -153,60 +151,24 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestInputHandlingWithinGaps()
|
public void TestInputHandlingWithinGaps()
|
||||||
{
|
{
|
||||||
AddBeatmaps(5, 2);
|
AddAssert("no beatmaps visible", () => !GetVisiblePanels<BeatmapPanel>().Any());
|
||||||
WaitForDrawablePanels();
|
|
||||||
SelectNextGroup();
|
|
||||||
|
|
||||||
clickOnPanel(0, 1, p => p.LayoutRectangle.TopLeft + new Vector2(20f, -1f));
|
// Clicks just above the first group panel should not actuate any action.
|
||||||
WaitForGroupSelection(0, 1);
|
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);
|
WaitForGroupSelection(0, 0);
|
||||||
|
|
||||||
SelectNextPanel();
|
ClickVisiblePanelWithOffset<BeatmapPanel>(1, new Vector2(0, (CarouselItem.DEFAULT_HEIGHT / 2 + 1)));
|
||||||
Select();
|
|
||||||
WaitForGroupSelection(0, 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);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Framework.Testing;
|
using osu.Framework.Testing;
|
||||||
@ -209,31 +208,34 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
[Solo]
|
||||||
public void TestInputHandlingWithinGaps()
|
public void TestInputHandlingWithinGaps()
|
||||||
{
|
{
|
||||||
AddBeatmaps(2, 5);
|
AddBeatmaps(2, 5);
|
||||||
WaitForDrawablePanels();
|
WaitForDrawablePanels();
|
||||||
SelectNextGroup();
|
|
||||||
|
|
||||||
clickOnDifficulty(0, 1, p => p.LayoutRectangle.TopLeft + new Vector2(20f, -1f));
|
AddAssert("no beatmaps visible", () => !GetVisiblePanels<BeatmapPanel>().Any());
|
||||||
WaitForSelection(0, 1);
|
|
||||||
|
|
||||||
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);
|
WaitForSelection(0, 0);
|
||||||
|
|
||||||
SelectNextPanel();
|
// Beatmap panels expand their selection area to cover holes from spacing.
|
||||||
Select();
|
ClickVisiblePanelWithOffset<BeatmapPanel>(1, new Vector2(0, -(CarouselItem.DEFAULT_HEIGHT / 2 + 1)));
|
||||||
WaitForSelection(0, 1);
|
|
||||||
|
|
||||||
clickOnSet(0, p => p.LayoutRectangle.BottomLeft + new Vector2(20f, 1f));
|
|
||||||
WaitForSelection(0, 0);
|
WaitForSelection(0, 0);
|
||||||
|
|
||||||
AddStep("scroll to end", () => Scroll.ScrollToEnd(false));
|
// Panels with higher depth will handle clicks in the gutters for simplicity.
|
||||||
clickOnDifficulty(0, 4, p => p.LayoutRectangle.BottomLeft + new Vector2(20f, 1f));
|
ClickVisiblePanelWithOffset<BeatmapPanel>(2, new Vector2(0, (CarouselItem.DEFAULT_HEIGHT / 2 + 1)));
|
||||||
WaitForSelection(0, 4);
|
WaitForSelection(0, 2);
|
||||||
|
|
||||||
clickOnSet(1, p => p.LayoutRectangle.TopLeft + new Vector2(20f, -1f));
|
ClickVisiblePanelWithOffset<BeatmapPanel>(3, new Vector2(0, (CarouselItem.DEFAULT_HEIGHT / 2 + 1)));
|
||||||
WaitForSelection(1, 0);
|
WaitForSelection(0, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkSelectionIterating(bool isIterating)
|
private void checkSelectionIterating(bool isIterating)
|
||||||
@ -249,27 +251,5 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
AddUntilStep("selection not changed", () => Carousel.CurrentSelection == selection);
|
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);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user