Add steps and asserts to TestCaseScreenBreadcrumbs.

This commit is contained in:
DrabWeb 2018-05-10 21:52:26 -03:00
parent b9adeeb063
commit a294f187ee

View File

@ -17,6 +17,7 @@ namespace osu.Game.Tests.Visual
public class TestCaseScreenBreadcrumbs : OsuTestCase public class TestCaseScreenBreadcrumbs : OsuTestCase
{ {
private readonly ScreenBreadcrumbControl<TestScreen> breadcrumbs; private readonly ScreenBreadcrumbControl<TestScreen> breadcrumbs;
private TestScreen currentScreen, changedScreen = null;
public TestCaseScreenBreadcrumbs() public TestCaseScreenBreadcrumbs()
{ {
@ -40,11 +41,29 @@ namespace osu.Game.Tests.Visual
titleText = new OsuSpriteText(), titleText = new OsuSpriteText(),
}, },
}, },
startScreen = new TestScreenOne(), currentScreen = startScreen = new TestScreenOne(),
}; };
breadcrumbs.OnScreenChanged += s => titleText.Text = $"Changed to {s.ToString()}"; breadcrumbs.OnScreenChanged += s =>
breadcrumbs.CurrentScreen = startScreen; {
titleText.Text = $"Changed to {s.ToString()}";
changedScreen = s;
};
AddStep(@"make start current", () => breadcrumbs.CurrentScreen = startScreen);
assertCurrent();
pushNext();
assertCurrent();
pushNext();
assertCurrent();
AddStep(@"make start current", () =>
{
startScreen.MakeCurrent();
currentScreen = startScreen;
});
assertCurrent();
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
@ -53,6 +72,9 @@ namespace osu.Game.Tests.Visual
breadcrumbs.StripColour = colours.Blue; breadcrumbs.StripColour = colours.Blue;
} }
private void pushNext() => AddStep(@"push next screen", () => currentScreen = currentScreen.PushNext());
private void assertCurrent() => AddAssert(@"assert the current screen is correct", () => currentScreen == changedScreen);
private abstract class TestScreen : OsuScreen private abstract class TestScreen : OsuScreen
{ {
protected abstract string Title { get; } protected abstract string Title { get; }
@ -61,6 +83,14 @@ namespace osu.Game.Tests.Visual
public override string ToString() => Title; public override string ToString() => Title;
public TestScreen PushNext()
{
TestScreen screen = CreateNextScreen();
Push(screen);
return screen;
}
protected TestScreen() protected TestScreen()
{ {
Child = new FillFlowContainer Child = new FillFlowContainer
@ -84,7 +114,7 @@ namespace osu.Game.Tests.Visual
Origin = Anchor.TopCentre, Origin = Anchor.TopCentre,
Width = 100, Width = 100,
Text = $"Push {NextTitle}", Text = $"Push {NextTitle}",
Action = () => Push(CreateNextScreen()), Action = () => PushNext(),
}, },
}, },
}; };