TestScene improvements

This commit is contained in:
Andrei Zavatski
2020-01-04 22:25:08 +03:00
parent 37482b2ad4
commit d3c2dc43bd
3 changed files with 27 additions and 37 deletions

View File

@ -41,32 +41,30 @@ namespace osu.Game.Tests.Visual.UserInterface
} }
[Test] [Test]
public void TestPageSelectorValues() public void TestCurrentPageReset()
{ {
AddStep("10 max pages", () => setMaxPages(10)); AddStep("Set 10 pages", () => setMaxPages(10));
AddStep("11 max pages", () => setMaxPages(11)); AddStep("Select 5 page", () => setCurrentPage(5));
AddStep("200 max pages, current 199", () => AddStep("Set 11 pages", () => setMaxPages(11));
{ AddAssert("Check 1 page is current", () => pageSelector.CurrentPage.Value == 1);
setMaxPages(200); }
setCurrentPage(199);
}); [Test]
AddStep("200 max pages, current 201", () => public void TestUnexistingPageSelection()
{ {
setMaxPages(200); AddStep("Set 10 pages", () => setMaxPages(10));
setCurrentPage(201); AddStep("Select 11 page", () => setCurrentPage(11));
}); AddAssert("Check current equals max", () => pageSelector.CurrentPage.Value == pageSelector.MaxPages.Value);
AddAssert("Current equals max", () => pageSelector.CurrentPage.Value == pageSelector.MaxPages.Value);
AddStep("200 max pages, current -10", () => AddStep("Select -1 page", () => setCurrentPage(-1));
{ AddAssert("Check current is 1", () => pageSelector.CurrentPage.Value == 1);
setMaxPages(200); }
setCurrentPage(-10);
}); [Test]
AddAssert("Current is 1", () => pageSelector.CurrentPage.Value == 1); public void TestNegativeMaxPages()
AddStep("-10 max pages", () => {
{ AddStep("Set -10 pages", () => setMaxPages(-10));
setMaxPages(-10); AddAssert("Check current and max is 1", () => pageSelector.CurrentPage.Value == 1 && pageSelector.MaxPages.Value == 1);
});
AddAssert("Current is 1, max is 1", () => pageSelector.CurrentPage.Value == 1 && pageSelector.MaxPages.Value == 1);
} }
[Test] [Test]

View File

@ -86,19 +86,10 @@ namespace osu.Game.Graphics.UserInterface.PageSelector
for (int i = 1; i <= MaxPages.Value; i++) for (int i = 1; i <= MaxPages.Value; i++)
addDrawablePage(i); addDrawablePage(i);
if (CurrentPage.Value > MaxPages.Value) if (CurrentPage.Value == 1)
{ CurrentPage.TriggerChange();
CurrentPage.Value = MaxPages.Value; else
return;
}
if (CurrentPage.Value < 1)
{
CurrentPage.Value = 1; CurrentPage.Value = 1;
return;
}
CurrentPage.TriggerChange();
} }
private void updateButtonsState() private void updateButtonsState()

View File

@ -46,6 +46,7 @@ namespace osu.Game.Graphics.UserInterface.PageSelector
{ {
AutoSizeAxes = Axes.Both, AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal, Direction = FillDirection.Horizontal,
Spacing = new Vector2(3, 0),
Children = new Drawable[] Children = new Drawable[]
{ {
name = new OsuSpriteText name = new OsuSpriteText