1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 05:22:54 +08:00

remove string param, move menu check to method, add const padding

This commit is contained in:
David Zhao 2019-08-13 12:26:06 +09:00
parent cf9a5baafa
commit aa6f8757eb

View File

@ -26,12 +26,14 @@ namespace osu.Game.Tests.Visual.Menus
{ {
public class TestSceneScreenNavigation : ManualInputManagerTestScene public class TestSceneScreenNavigation : ManualInputManagerTestScene
{ {
private const float click_padding = 25;
private GameHost gameHost; private GameHost gameHost;
private TestOsuGame osuGame; private TestOsuGame osuGame;
private Vector2 backButtonPosition => osuGame.ToScreenSpace(new Vector2(25, osuGame.LayoutRectangle.Bottom - 25)); private Vector2 backButtonPosition => osuGame.ToScreenSpace(new Vector2(click_padding, osuGame.LayoutRectangle.Bottom - click_padding));
private Vector2 optionsButtonPosition => osuGame.ToScreenSpace(new Vector2(25, 25)); private Vector2 optionsButtonPosition => osuGame.ToScreenSpace(new Vector2(click_padding, click_padding));
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(GameHost gameHost) private void load(GameHost gameHost)
@ -63,7 +65,7 @@ namespace osu.Game.Tests.Visual.Menus
}); });
AddUntilStep("Wait for load", () => osuGame.IsLoaded); AddUntilStep("Wait for load", () => osuGame.IsLoaded);
AddUntilStep("Wait for intro", () => osuGame.ScreenStack.CurrentScreen is IntroScreen); AddUntilStep("Wait for intro", () => osuGame.ScreenStack.CurrentScreen is IntroScreen);
AddUntilStep("Wait for main menu", () => osuGame.ScreenStack.CurrentScreen is MainMenu menu && menu.IsLoaded); confirmAtMainMenu();
} }
[Test] [Test]
@ -71,7 +73,7 @@ namespace osu.Game.Tests.Visual.Menus
{ {
TestSongSelect songSelect = null; TestSongSelect songSelect = null;
pushAndConfirm(() => songSelect = new TestSongSelect(), "song select"); pushAndConfirm(() => songSelect = new TestSongSelect());
AddStep("Show mods overlay", () => songSelect.ModSelectOverlay.Show()); AddStep("Show mods overlay", () => songSelect.ModSelectOverlay.Show());
AddAssert("Overlay was shown", () => songSelect.ModSelectOverlay.State.Value == Visibility.Visible); AddAssert("Overlay was shown", () => songSelect.ModSelectOverlay.State.Value == Visibility.Visible);
AddStep("Press escape", () => pressAndRelease(Key.Escape)); AddStep("Press escape", () => pressAndRelease(Key.Escape));
@ -84,7 +86,7 @@ namespace osu.Game.Tests.Visual.Menus
{ {
TestSongSelect songSelect = null; TestSongSelect songSelect = null;
pushAndConfirm(() => songSelect = new TestSongSelect(), "song select"); pushAndConfirm(() => songSelect = new TestSongSelect());
AddStep("Show mods overlay", () => songSelect.ModSelectOverlay.Show()); AddStep("Show mods overlay", () => songSelect.ModSelectOverlay.Show());
AddAssert("Overlay was shown", () => songSelect.ModSelectOverlay.State.Value == Visibility.Visible); AddAssert("Overlay was shown", () => songSelect.ModSelectOverlay.State.Value == Visibility.Visible);
AddStep("Move mouse to backButton", () => InputManager.MoveMouseTo(backButtonPosition)); AddStep("Move mouse to backButton", () => InputManager.MoveMouseTo(backButtonPosition));
@ -100,14 +102,14 @@ namespace osu.Game.Tests.Visual.Menus
[Test] [Test]
public void TestExitMultiWithEscape() public void TestExitMultiWithEscape()
{ {
pushAndConfirm(() => new Screens.Multi.Multiplayer(), "multiplayer"); pushAndConfirm(() => new Screens.Multi.Multiplayer());
exitViaEscapeAndConfirm(); exitViaEscapeAndConfirm();
} }
[Test] [Test]
public void TestExitMultiWithBackButton() public void TestExitMultiWithBackButton()
{ {
pushAndConfirm(() => new Screens.Multi.Multiplayer(), "multiplayer"); pushAndConfirm(() => new Screens.Multi.Multiplayer());
exitViaBackButtonAndConfirm(); exitViaBackButtonAndConfirm();
} }
@ -123,26 +125,28 @@ namespace osu.Game.Tests.Visual.Menus
AddAssert("Options overlay was closed", () => osuGame.Settings.State.Value == Visibility.Hidden); AddAssert("Options overlay was closed", () => osuGame.Settings.State.Value == Visibility.Hidden);
} }
private void pushAndConfirm(Func<Screen> newScreen, string screenName) private void pushAndConfirm(Func<Screen> newScreen)
{ {
Screen screen = null; Screen screen = null;
AddStep($"Push new {screenName}", () => osuGame.ScreenStack.Push(screen = newScreen())); AddStep("Push new screen", () => osuGame.ScreenStack.Push(screen = newScreen()));
AddUntilStep($"Wait for new {screenName}", () => osuGame.ScreenStack.CurrentScreen == screen && screen.IsLoaded); AddUntilStep("Wait for new screen", () => osuGame.ScreenStack.CurrentScreen == screen && screen.IsLoaded);
} }
private void exitViaEscapeAndConfirm() private void exitViaEscapeAndConfirm()
{ {
AddStep("Press escape", () => pressAndRelease(Key.Escape)); AddStep("Press escape", () => pressAndRelease(Key.Escape));
AddUntilStep("Wait for main menu", () => osuGame.ScreenStack.CurrentScreen is MainMenu); confirmAtMainMenu();
} }
private void exitViaBackButtonAndConfirm() private void exitViaBackButtonAndConfirm()
{ {
AddStep("Move mouse to backButton", () => InputManager.MoveMouseTo(backButtonPosition)); AddStep("Move mouse to backButton", () => InputManager.MoveMouseTo(backButtonPosition));
AddStep("Click back button", () => InputManager.Click(MouseButton.Left)); AddStep("Click back button", () => InputManager.Click(MouseButton.Left));
AddUntilStep("Wait for main menu", () => osuGame.ScreenStack.CurrentScreen is MainMenu); confirmAtMainMenu();
} }
private void confirmAtMainMenu() => AddUntilStep("Wait for main menu", () => osuGame.ScreenStack.CurrentScreen is MainMenu);
private void pressAndRelease(Key key) private void pressAndRelease(Key key)
{ {
InputManager.PressKey(key); InputManager.PressKey(key);