2025-01-23 16:19:09 +08:00
|
|
|
// 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 NUnit.Framework;
|
|
|
|
using osu.Framework.Testing;
|
|
|
|
using osu.Game.Beatmaps;
|
2025-02-06 13:38:51 +08:00
|
|
|
using osu.Game.Screens.Select;
|
|
|
|
using osu.Game.Screens.Select.Filter;
|
2025-01-23 16:19:09 +08:00
|
|
|
using osuTK.Input;
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.SongSelect
|
|
|
|
{
|
|
|
|
[TestFixture]
|
2025-02-06 13:38:51 +08:00
|
|
|
public partial class TestSceneBeatmapCarouselV2NoGrouping : BeatmapCarouselV2TestScene
|
2025-01-23 16:19:09 +08:00
|
|
|
{
|
2025-02-06 13:38:51 +08:00
|
|
|
[SetUpSteps]
|
|
|
|
public void SetUpSteps()
|
|
|
|
{
|
|
|
|
RemoveAllBeatmaps();
|
|
|
|
CreateCarousel();
|
|
|
|
SortBy(new FilterCriteria { Sort = SortMode.Title });
|
|
|
|
}
|
|
|
|
|
2025-01-23 16:19:09 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Keyboard selection via up and down arrows doesn't actually change the selection until
|
|
|
|
/// the select key is pressed.
|
|
|
|
/// </summary>
|
|
|
|
[Test]
|
|
|
|
public void TestKeyboardSelectionKeyRepeat()
|
|
|
|
{
|
|
|
|
AddBeatmaps(10);
|
|
|
|
WaitForDrawablePanels();
|
2025-02-01 13:55:48 +08:00
|
|
|
CheckNoSelection();
|
2025-01-23 16:19:09 +08:00
|
|
|
|
2025-02-01 13:55:48 +08:00
|
|
|
Select();
|
|
|
|
CheckNoSelection();
|
2025-01-23 16:19:09 +08:00
|
|
|
|
|
|
|
AddStep("press down arrow", () => InputManager.PressKey(Key.Down));
|
|
|
|
checkSelectionIterating(false);
|
|
|
|
|
|
|
|
AddStep("press up arrow", () => InputManager.PressKey(Key.Up));
|
|
|
|
checkSelectionIterating(false);
|
|
|
|
|
|
|
|
AddStep("release down arrow", () => InputManager.ReleaseKey(Key.Down));
|
|
|
|
checkSelectionIterating(false);
|
|
|
|
|
|
|
|
AddStep("release up arrow", () => InputManager.ReleaseKey(Key.Up));
|
|
|
|
checkSelectionIterating(false);
|
|
|
|
|
2025-02-01 13:55:48 +08:00
|
|
|
Select();
|
|
|
|
CheckHasSelection();
|
2025-01-23 16:19:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Keyboard selection via left and right arrows moves between groups, updating the selection
|
|
|
|
/// immediately.
|
|
|
|
/// </summary>
|
|
|
|
[Test]
|
|
|
|
public void TestGroupSelectionKeyRepeat()
|
|
|
|
{
|
|
|
|
AddBeatmaps(10);
|
|
|
|
WaitForDrawablePanels();
|
2025-02-01 13:55:48 +08:00
|
|
|
CheckNoSelection();
|
2025-01-23 16:19:09 +08:00
|
|
|
|
|
|
|
AddStep("press right arrow", () => InputManager.PressKey(Key.Right));
|
|
|
|
checkSelectionIterating(true);
|
|
|
|
|
|
|
|
AddStep("press left arrow", () => InputManager.PressKey(Key.Left));
|
|
|
|
checkSelectionIterating(true);
|
|
|
|
|
|
|
|
AddStep("release right arrow", () => InputManager.ReleaseKey(Key.Right));
|
|
|
|
checkSelectionIterating(true);
|
|
|
|
|
|
|
|
AddStep("release left arrow", () => InputManager.ReleaseKey(Key.Left));
|
|
|
|
checkSelectionIterating(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestCarouselRemembersSelection()
|
|
|
|
{
|
|
|
|
AddBeatmaps(10);
|
|
|
|
WaitForDrawablePanels();
|
|
|
|
|
2025-02-01 13:55:48 +08:00
|
|
|
SelectNextGroup();
|
2025-01-23 16:19:09 +08:00
|
|
|
|
|
|
|
object? selection = null;
|
|
|
|
|
2025-02-06 14:41:57 +08:00
|
|
|
AddStep("store drawable selection", () => selection = GetSelectedPanel()?.Item?.Model);
|
2025-01-23 16:19:09 +08:00
|
|
|
|
2025-02-01 13:55:48 +08:00
|
|
|
CheckHasSelection();
|
2025-01-23 16:19:09 +08:00
|
|
|
AddAssert("drawable selection non-null", () => selection, () => Is.Not.Null);
|
|
|
|
AddAssert("drawable selection matches carousel selection", () => selection, () => Is.EqualTo(Carousel.CurrentSelection));
|
|
|
|
|
|
|
|
RemoveAllBeatmaps();
|
2025-02-06 14:41:57 +08:00
|
|
|
AddUntilStep("no drawable selection", GetSelectedPanel, () => Is.Null);
|
2025-01-23 16:19:09 +08:00
|
|
|
|
|
|
|
AddBeatmaps(10);
|
|
|
|
WaitForDrawablePanels();
|
|
|
|
|
2025-02-01 13:55:48 +08:00
|
|
|
CheckHasSelection();
|
2025-02-06 14:41:57 +08:00
|
|
|
AddAssert("no drawable selection", GetSelectedPanel, () => Is.Null);
|
2025-01-23 16:19:09 +08:00
|
|
|
|
|
|
|
AddStep("add previous selection", () => BeatmapSets.Add(((BeatmapInfo)selection!).BeatmapSet!));
|
|
|
|
|
2025-02-01 13:55:48 +08:00
|
|
|
AddAssert("selection matches original carousel selection", () => selection, () => Is.EqualTo(Carousel.CurrentSelection));
|
2025-02-06 14:41:57 +08:00
|
|
|
AddUntilStep("drawable selection restored", () => GetSelectedPanel()?.Item?.Model, () => Is.EqualTo(selection));
|
|
|
|
AddAssert("carousel item is visible", () => GetSelectedPanel()?.Item?.IsVisible, () => Is.True);
|
2025-01-23 16:19:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestTraversalBeyondStart()
|
|
|
|
{
|
|
|
|
const int total_set_count = 200;
|
|
|
|
|
|
|
|
AddBeatmaps(total_set_count);
|
|
|
|
WaitForDrawablePanels();
|
|
|
|
|
2025-02-01 13:55:48 +08:00
|
|
|
SelectNextGroup();
|
|
|
|
WaitForSelection(0, 0);
|
|
|
|
SelectPrevGroup();
|
|
|
|
WaitForSelection(total_set_count - 1, 0);
|
2025-01-23 16:19:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestTraversalBeyondEnd()
|
|
|
|
{
|
|
|
|
const int total_set_count = 200;
|
|
|
|
|
|
|
|
AddBeatmaps(total_set_count);
|
|
|
|
WaitForDrawablePanels();
|
|
|
|
|
2025-02-01 13:55:48 +08:00
|
|
|
SelectPrevGroup();
|
|
|
|
WaitForSelection(total_set_count - 1, 0);
|
|
|
|
SelectNextGroup();
|
|
|
|
WaitForSelection(0, 0);
|
2025-01-23 16:19:09 +08:00
|
|
|
}
|
|
|
|
|
2025-02-04 01:41:56 +08:00
|
|
|
[Test]
|
|
|
|
public void TestGroupSelectionOnHeader()
|
|
|
|
{
|
|
|
|
AddBeatmaps(10, 3);
|
|
|
|
WaitForDrawablePanels();
|
|
|
|
|
|
|
|
SelectNextGroup();
|
|
|
|
SelectNextGroup();
|
|
|
|
WaitForSelection(1, 0);
|
|
|
|
|
|
|
|
SelectPrevPanel();
|
|
|
|
SelectPrevGroup();
|
|
|
|
WaitForSelection(0, 0);
|
|
|
|
}
|
|
|
|
|
2025-01-23 16:19:09 +08:00
|
|
|
[Test]
|
|
|
|
public void TestKeyboardSelection()
|
|
|
|
{
|
|
|
|
AddBeatmaps(10, 3);
|
|
|
|
WaitForDrawablePanels();
|
|
|
|
|
2025-02-01 13:55:48 +08:00
|
|
|
SelectNextPanel();
|
|
|
|
SelectNextPanel();
|
|
|
|
SelectNextPanel();
|
|
|
|
SelectNextPanel();
|
|
|
|
CheckNoSelection();
|
2025-01-23 16:19:09 +08:00
|
|
|
|
2025-02-01 13:55:48 +08:00
|
|
|
Select();
|
|
|
|
WaitForSelection(3, 0);
|
2025-01-23 16:19:09 +08:00
|
|
|
|
2025-02-01 13:55:48 +08:00
|
|
|
SelectNextPanel();
|
|
|
|
WaitForSelection(3, 0);
|
2025-01-23 16:19:09 +08:00
|
|
|
|
2025-02-01 13:55:48 +08:00
|
|
|
Select();
|
|
|
|
WaitForSelection(3, 1);
|
2025-01-23 16:19:09 +08:00
|
|
|
|
2025-02-01 13:55:48 +08:00
|
|
|
SelectNextPanel();
|
|
|
|
WaitForSelection(3, 1);
|
2025-01-23 16:19:09 +08:00
|
|
|
|
2025-02-01 13:55:48 +08:00
|
|
|
Select();
|
|
|
|
WaitForSelection(3, 2);
|
2025-01-23 16:19:09 +08:00
|
|
|
|
2025-02-01 13:55:48 +08:00
|
|
|
SelectNextPanel();
|
|
|
|
WaitForSelection(3, 2);
|
2025-01-23 16:19:09 +08:00
|
|
|
|
2025-02-01 13:55:48 +08:00
|
|
|
Select();
|
|
|
|
WaitForSelection(4, 0);
|
2025-01-23 16:19:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestEmptyTraversal()
|
|
|
|
{
|
2025-02-01 13:55:48 +08:00
|
|
|
SelectNextPanel();
|
|
|
|
CheckNoSelection();
|
2025-01-23 16:19:09 +08:00
|
|
|
|
2025-02-01 13:55:48 +08:00
|
|
|
SelectNextGroup();
|
|
|
|
CheckNoSelection();
|
2025-01-23 16:19:09 +08:00
|
|
|
|
2025-02-01 13:55:48 +08:00
|
|
|
SelectPrevPanel();
|
|
|
|
CheckNoSelection();
|
2025-01-23 16:19:09 +08:00
|
|
|
|
2025-02-01 13:55:48 +08:00
|
|
|
SelectPrevGroup();
|
|
|
|
CheckNoSelection();
|
2025-01-23 16:19:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void checkSelectionIterating(bool isIterating)
|
|
|
|
{
|
|
|
|
object? selection = null;
|
|
|
|
|
|
|
|
for (int i = 0; i < 3; i++)
|
|
|
|
{
|
|
|
|
AddStep("store selection", () => selection = Carousel.CurrentSelection);
|
|
|
|
if (isIterating)
|
|
|
|
AddUntilStep("selection changed", () => Carousel.CurrentSelection != selection);
|
|
|
|
else
|
|
|
|
AddUntilStep("selection not changed", () => Carousel.CurrentSelection == selection);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|