Simplify input buttons/keys in tests

This commit is contained in:
Joehu
2020-11-05 06:41:56 -08:00
parent d7c30f9b42
commit ef3c918a3c
14 changed files with 46 additions and 113 deletions

View File

@ -41,11 +41,11 @@ namespace osu.Game.Tests.Visual.Gameplay
AddStep("store time", () => time = Player.GameplayClockContainer.GameplayClock.CurrentTime);
// test seek via keyboard
AddStep("seek with right arrow key", () => press(Key.Right));
AddStep("seek with right arrow key", () => InputManager.Key(Key.Right));
AddAssert("time seeked forward", () => Player.GameplayClockContainer.GameplayClock.CurrentTime > time + 2000);
AddStep("store time", () => time = Player.GameplayClockContainer.GameplayClock.CurrentTime);
AddStep("seek with left arrow key", () => press(Key.Left));
AddStep("seek with left arrow key", () => InputManager.Key(Key.Left));
AddAssert("time seeked backward", () => Player.GameplayClockContainer.GameplayClock.CurrentTime < time);
seekToBreak(0);
@ -67,11 +67,5 @@ namespace osu.Game.Tests.Visual.Gameplay
BreakPeriod destBreak() => Beatmap.Value.Beatmap.Breaks.ElementAt(breakIndex);
}
private void press(Key key)
{
InputManager.PressKey(key);
InputManager.ReleaseKey(key);
}
}
}

View File

@ -86,7 +86,7 @@ namespace osu.Game.Tests.Visual.Gameplay
{
showOverlay();
AddStep("Up arrow", () => press(Key.Up));
AddStep("Up arrow", () => InputManager.Key(Key.Up));
AddAssert("Last button selected", () => pauseOverlay.Buttons.Last().Selected.Value);
}
@ -98,7 +98,7 @@ namespace osu.Game.Tests.Visual.Gameplay
{
showOverlay();
AddStep("Down arrow", () => press(Key.Down));
AddStep("Down arrow", () => InputManager.Key(Key.Down));
AddAssert("First button selected", () => getButton(0).Selected.Value);
}
@ -110,11 +110,11 @@ namespace osu.Game.Tests.Visual.Gameplay
{
AddStep("Show overlay", () => failOverlay.Show());
AddStep("Up arrow", () => press(Key.Up));
AddStep("Up arrow", () => InputManager.Key(Key.Up));
AddAssert("Last button selected", () => failOverlay.Buttons.Last().Selected.Value);
AddStep("Up arrow", () => press(Key.Up));
AddStep("Up arrow", () => InputManager.Key(Key.Up));
AddAssert("First button selected", () => failOverlay.Buttons.First().Selected.Value);
AddStep("Up arrow", () => press(Key.Up));
AddStep("Up arrow", () => InputManager.Key(Key.Up));
AddAssert("Last button selected", () => failOverlay.Buttons.Last().Selected.Value);
}
@ -126,11 +126,11 @@ namespace osu.Game.Tests.Visual.Gameplay
{
AddStep("Show overlay", () => failOverlay.Show());
AddStep("Down arrow", () => press(Key.Down));
AddStep("Down arrow", () => InputManager.Key(Key.Down));
AddAssert("First button selected", () => failOverlay.Buttons.First().Selected.Value);
AddStep("Down arrow", () => press(Key.Down));
AddStep("Down arrow", () => InputManager.Key(Key.Down));
AddAssert("Last button selected", () => failOverlay.Buttons.Last().Selected.Value);
AddStep("Down arrow", () => press(Key.Down));
AddStep("Down arrow", () => InputManager.Key(Key.Down));
AddAssert("First button selected", () => failOverlay.Buttons.First().Selected.Value);
}
@ -177,7 +177,7 @@ namespace osu.Game.Tests.Visual.Gameplay
{
showOverlay();
AddStep("Down arrow", () => press(Key.Down));
AddStep("Down arrow", () => InputManager.Key(Key.Down));
AddStep("Hover second button", () => InputManager.MoveMouseTo(getButton(1)));
AddAssert("First button not selected", () => !getButton(0).Selected.Value);
AddAssert("Second button selected", () => getButton(1).Selected.Value);
@ -195,7 +195,7 @@ namespace osu.Game.Tests.Visual.Gameplay
});
AddStep("Hover second button", () => InputManager.MoveMouseTo(getButton(1)));
AddStep("Up arrow", () => press(Key.Up));
AddStep("Up arrow", () => InputManager.Key(Key.Up));
AddAssert("Second button not selected", () => !getButton(1).Selected.Value);
AddAssert("First button selected", () => getButton(0).Selected.Value);
}
@ -210,7 +210,7 @@ namespace osu.Game.Tests.Visual.Gameplay
AddStep("Hover second button", () => InputManager.MoveMouseTo(getButton(1)));
AddStep("Unhover second button", () => InputManager.MoveMouseTo(Vector2.Zero));
AddStep("Down arrow", () => press(Key.Down));
AddStep("Down arrow", () => InputManager.Key(Key.Down));
AddAssert("First button selected", () => getButton(0).Selected.Value); // Initial state condition
}
@ -246,8 +246,8 @@ namespace osu.Game.Tests.Visual.Gameplay
AddStep("Select second button", () =>
{
press(Key.Down);
press(Key.Down);
InputManager.Key(Key.Down);
InputManager.Key(Key.Down);
});
bool triggered = false;
@ -256,7 +256,7 @@ namespace osu.Game.Tests.Visual.Gameplay
{
lastAction = pauseOverlay.OnRetry;
pauseOverlay.OnRetry = () => triggered = true;
press(Key.Enter);
InputManager.Key(Key.Enter);
});
AddAssert("Action was triggered", () =>
@ -290,12 +290,6 @@ namespace osu.Game.Tests.Visual.Gameplay
private DialogButton getButton(int index) => pauseOverlay.Buttons.Skip(index).First();
private void press(Key key)
{
InputManager.PressKey(key);
InputManager.ReleaseKey(key);
}
private void press(GlobalAction action)
{
globalActionContainer.TriggerPressed(action);

View File

@ -32,11 +32,7 @@ namespace osu.Game.Tests.Visual.Gameplay
[Test]
public void TestDefaultsWhenNotDatabased()
{
AddStep("fire key", () =>
{
InputManager.PressKey(Key.A);
InputManager.ReleaseKey(Key.A);
});
AddStep("fire key", () => InputManager.Key(Key.A));
AddAssert("received key", () => receiver.ReceivedAction);
}

View File

@ -40,11 +40,7 @@ namespace osu.Game.Tests.Visual.Gameplay
void addPressKeyStep()
{
AddStep($"Press {testKey} key", () =>
{
InputManager.PressKey(testKey);
InputManager.ReleaseKey(testKey);
});
AddStep($"Press {testKey} key", () => InputManager.Key(testKey));
}
addPressKeyStep();

View File

@ -59,11 +59,7 @@ namespace osu.Game.Tests.Visual.Gameplay
confirmClockRunning(false);
confirmPauseOverlayShown(false);
AddStep("click to resume", () =>
{
InputManager.PressButton(MouseButton.Left);
InputManager.ReleaseButton(MouseButton.Left);
});
AddStep("click to resume", () => InputManager.Click(MouseButton.Left));
confirmClockRunning(true);
}

View File

@ -158,8 +158,7 @@ namespace osu.Game.Tests.Visual.Gameplay
AddStep("much move with press", () => moveFunction = Scheduler.AddDelayed(() =>
{
InputManager.MoveMouseTo(InputManager.CurrentState.Mouse.Position + new Vector2(-1, 0));
InputManager.PressButton(MouseButton.Left);
InputManager.ReleaseButton(MouseButton.Left);
InputManager.Click(MouseButton.Left);
}, 10, true));
AddWaitStep("move", 10);
AddStep("stop move", () => moveFunction.Cancel());