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;
|
|
|
|
|
using System.Collections.Generic;
|
2020-01-05 00:03:39 +08:00
|
|
|
|
using NUnit.Framework;
|
2019-09-07 12:31:07 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
2020-01-05 00:03:39 +08:00
|
|
|
|
using osu.Game.Graphics.UserInterface.PageSelector;
|
2019-09-07 12:31:07 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.UserInterface
|
|
|
|
|
{
|
|
|
|
|
public class TestScenePageSelector : OsuTestScene
|
|
|
|
|
{
|
|
|
|
|
public override IReadOnlyList<Type> RequiredTypes => new[]
|
|
|
|
|
{
|
2020-01-05 00:36:05 +08:00
|
|
|
|
typeof(PageSelector),
|
2020-01-05 02:14:56 +08:00
|
|
|
|
typeof(DrawablePage),
|
|
|
|
|
typeof(PageSelectorButton),
|
|
|
|
|
typeof(PageSelectorItem)
|
2019-09-07 12:31:07 +08:00
|
|
|
|
};
|
|
|
|
|
|
2019-09-10 06:36:25 +08:00
|
|
|
|
private readonly PageSelector pageSelector;
|
2020-01-05 00:36:05 +08:00
|
|
|
|
private readonly DrawablePage drawablePage;
|
2019-09-10 06:36:25 +08:00
|
|
|
|
|
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
|
|
|
|
},
|
|
|
|
|
drawablePage = new DrawablePage(1234)
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
Margin = new MarginPadding { Top = 50 },
|
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]
|
|
|
|
|
public void TestPageSelectorValues()
|
|
|
|
|
{
|
2019-09-10 06:36:25 +08:00
|
|
|
|
AddStep("10 max pages", () => setMaxPages(10));
|
2020-01-05 02:14:56 +08:00
|
|
|
|
AddStep("11 max pages", () => setMaxPages(11));
|
2019-09-10 06:36:25 +08:00
|
|
|
|
AddStep("200 max pages, current 199", () =>
|
2019-09-08 05:27:40 +08:00
|
|
|
|
{
|
2019-09-10 06:36:25 +08:00
|
|
|
|
setMaxPages(200);
|
|
|
|
|
setCurrentPage(199);
|
|
|
|
|
});
|
|
|
|
|
AddStep("200 max pages, current 201", () =>
|
|
|
|
|
{
|
|
|
|
|
setMaxPages(200);
|
|
|
|
|
setCurrentPage(201);
|
|
|
|
|
});
|
2019-09-19 21:45:38 +08:00
|
|
|
|
AddAssert("Current equals max", () => pageSelector.CurrentPage.Value == pageSelector.MaxPages.Value);
|
2019-09-10 06:36:25 +08:00
|
|
|
|
AddStep("200 max pages, current -10", () =>
|
|
|
|
|
{
|
|
|
|
|
setMaxPages(200);
|
|
|
|
|
setCurrentPage(-10);
|
|
|
|
|
});
|
2019-09-19 21:45:38 +08:00
|
|
|
|
AddAssert("Current is 1", () => pageSelector.CurrentPage.Value == 1);
|
2019-09-10 06:36:25 +08:00
|
|
|
|
AddStep("-10 max pages", () =>
|
|
|
|
|
{
|
|
|
|
|
setMaxPages(-10);
|
|
|
|
|
});
|
2019-09-19 21:45:38 +08:00
|
|
|
|
AddAssert("Current is 1, max is 1", () => pageSelector.CurrentPage.Value == 1 && pageSelector.MaxPages.Value == 1);
|
2019-09-10 06:36:25 +08:00
|
|
|
|
}
|
2019-09-08 05:27:40 +08:00
|
|
|
|
|
2020-01-05 00:36:05 +08:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestDrawablePage()
|
|
|
|
|
{
|
|
|
|
|
AddStep("Select", () => drawablePage.Selected = true);
|
|
|
|
|
AddStep("Deselect", () => drawablePage.Selected = false);
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-10 06:36:25 +08:00
|
|
|
|
private void setMaxPages(int maxPages) => pageSelector.MaxPages.Value = maxPages;
|
2019-09-08 05:27:40 +08:00
|
|
|
|
|
2019-09-10 06:36:25 +08:00
|
|
|
|
private void setCurrentPage(int currentPage) => pageSelector.CurrentPage.Value = currentPage;
|
2019-09-07 12:31:07 +08:00
|
|
|
|
}
|
|
|
|
|
}
|