2019-09-07 12:31:07 +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.
|
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2022-01-04 17:46:44 +08:00
|
|
|
|
using System.Linq;
|
2020-01-05 00:03:39 +08:00
|
|
|
|
using NUnit.Framework;
|
2022-01-04 17:14:42 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2019-09-07 12:31:07 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
2022-01-04 17:46:44 +08:00
|
|
|
|
using osu.Framework.Testing;
|
2020-01-05 00:03:39 +08:00
|
|
|
|
using osu.Game.Graphics.UserInterface.PageSelector;
|
2022-01-04 17:14:42 +08:00
|
|
|
|
using osu.Game.Overlays;
|
2019-09-07 12:31:07 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.UserInterface
|
|
|
|
|
{
|
|
|
|
|
public class TestScenePageSelector : OsuTestScene
|
|
|
|
|
{
|
2022-01-04 17:14:42 +08:00
|
|
|
|
[Cached]
|
|
|
|
|
private OverlayColourProvider provider { get; } = new OverlayColourProvider(OverlayColourScheme.Green);
|
|
|
|
|
|
2019-09-10 06:36:25 +08:00
|
|
|
|
private readonly PageSelector pageSelector;
|
|
|
|
|
|
2019-09-07 12:31:07 +08:00
|
|
|
|
public TestScenePageSelector()
|
|
|
|
|
{
|
2020-01-05 00:03:39 +08:00
|
|
|
|
AddRange(new Drawable[]
|
2019-09-07 12:31:07 +08:00
|
|
|
|
{
|
2020-01-05 00:03:39 +08:00
|
|
|
|
pageSelector = new PageSelector
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
2020-01-05 00:36:05 +08:00
|
|
|
|
},
|
2020-01-05 00:03:39 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
2019-09-08 05:27:40 +08:00
|
|
|
|
|
2020-01-05 00:03:39 +08:00
|
|
|
|
[Test]
|
2022-01-04 17:46:44 +08:00
|
|
|
|
public void TestOmittedPages()
|
2020-01-05 00:03:39 +08:00
|
|
|
|
{
|
2022-01-04 17:46:44 +08:00
|
|
|
|
setAvailablePages(100);
|
|
|
|
|
|
2022-01-04 18:05:14 +08:00
|
|
|
|
selectPageIndex(0);
|
|
|
|
|
checkVisiblePageNumbers(new[] { 1, 2, 3, 100 });
|
|
|
|
|
|
|
|
|
|
selectPageIndex(6);
|
|
|
|
|
checkVisiblePageNumbers(new[] { 1, 5, 6, 7, 8, 9, 100 });
|
|
|
|
|
|
|
|
|
|
selectPageIndex(49);
|
|
|
|
|
checkVisiblePageNumbers(new[] { 1, 48, 49, 50, 51, 52, 100 });
|
|
|
|
|
|
|
|
|
|
selectPageIndex(99);
|
|
|
|
|
checkVisiblePageNumbers(new[] { 1, 98, 99, 100 });
|
2020-01-05 03:25:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2022-01-04 17:46:44 +08:00
|
|
|
|
public void TestResetCurrentPage()
|
2020-01-05 03:25:08 +08:00
|
|
|
|
{
|
2022-01-04 17:46:44 +08:00
|
|
|
|
setAvailablePages(10);
|
2022-01-04 18:05:14 +08:00
|
|
|
|
selectPageIndex(6);
|
2022-01-04 17:46:44 +08:00
|
|
|
|
setAvailablePages(11);
|
|
|
|
|
AddAssert("Page 1 is current", () => pageSelector.CurrentPage.Value == 0);
|
2020-01-05 03:25:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2022-01-04 17:46:44 +08:00
|
|
|
|
public void TestOutOfBoundsSelection()
|
2020-01-05 03:25:08 +08:00
|
|
|
|
{
|
2022-01-04 17:46:44 +08:00
|
|
|
|
setAvailablePages(10);
|
2022-01-04 18:05:14 +08:00
|
|
|
|
selectPageIndex(11);
|
2022-01-04 17:46:44 +08:00
|
|
|
|
AddAssert("Page 10 is current", () => pageSelector.CurrentPage.Value == pageSelector.AvailablePages.Value - 1);
|
|
|
|
|
|
2022-01-04 18:05:14 +08:00
|
|
|
|
selectPageIndex(-1);
|
2022-01-04 17:46:44 +08:00
|
|
|
|
AddAssert("Page 1 is current", () => pageSelector.CurrentPage.Value == 0);
|
2019-09-10 06:36:25 +08:00
|
|
|
|
}
|
2019-09-08 05:27:40 +08:00
|
|
|
|
|
2022-01-04 18:05:14 +08:00
|
|
|
|
private void checkVisiblePageNumbers(int[] expected) => AddAssert($"Sequence is {string.Join(',', expected.Select(i => i.ToString()))}", () => pageSelector.ChildrenOfType<PageSelectorPageButton>().Select(p => p.PageNumber).SequenceEqual(expected));
|
|
|
|
|
|
|
|
|
|
private void selectPageIndex(int pageIndex) =>
|
2022-01-04 17:46:44 +08:00
|
|
|
|
AddStep($"Select page {pageIndex}", () => pageSelector.CurrentPage.Value = pageIndex);
|
2019-09-08 05:27:40 +08:00
|
|
|
|
|
2022-01-04 17:46:44 +08:00
|
|
|
|
private void setAvailablePages(int availablePages) =>
|
|
|
|
|
AddStep($"Set available pages to {availablePages}", () => pageSelector.AvailablePages.Value = availablePages);
|
2019-09-07 12:31:07 +08:00
|
|
|
|
}
|
|
|
|
|
}
|