1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-25 11:22:55 +08:00
osu-lazer/osu.Game.Tests/Visual/UserInterface/TestScenePageSelector.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

80 lines
2.7 KiB
C#
Raw Normal View History

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.
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
2019-09-07 12:31:07 +08:00
using osu.Framework.Graphics;
using osu.Framework.Testing;
using osu.Game.Graphics.UserInterface.PageSelector;
using osu.Game.Overlays;
2019-09-07 12:31:07 +08:00
namespace osu.Game.Tests.Visual.UserInterface
{
public class TestScenePageSelector : OsuTestScene
{
[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()
{
AddRange(new Drawable[]
2019-09-07 12:31:07 +08:00
{
pageSelector = new PageSelector
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
},
});
}
2019-09-08 05:27:40 +08:00
[Test]
public void TestOmittedPages()
{
setAvailablePages(100);
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]
public void TestResetCurrentPage()
2020-01-05 03:25:08 +08:00
{
setAvailablePages(10);
selectPageIndex(6);
setAvailablePages(11);
AddAssert("Page 1 is current", () => pageSelector.CurrentPage.Value == 0);
2020-01-05 03:25:08 +08:00
}
[Test]
public void TestOutOfBoundsSelection()
2020-01-05 03:25:08 +08:00
{
setAvailablePages(10);
selectPageIndex(11);
AddAssert("Page 10 is current", () => pageSelector.CurrentPage.Value == pageSelector.AvailablePages.Value - 1);
selectPageIndex(-1);
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
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) =>
AddStep($"Select page {pageIndex}", () => pageSelector.CurrentPage.Value = pageIndex);
2019-09-08 05:27:40 +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
}
}