mirror of
https://github.com/ppy/osu.git
synced 2025-01-12 16:02:55 +08:00
Refactor test to only allow init of actions
This commit is contained in:
parent
351160f94e
commit
dee57c7e72
@ -3,7 +3,6 @@
|
||||
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
@ -26,6 +25,8 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
|
||||
private GlobalActionContainer globalActionContainer;
|
||||
|
||||
private bool triggeredRetryButton;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuGameBase game)
|
||||
{
|
||||
@ -35,12 +36,18 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
[SetUp]
|
||||
public void SetUp() => Schedule(() =>
|
||||
{
|
||||
triggeredRetryButton = false;
|
||||
|
||||
globalActionContainer.Children = new Drawable[]
|
||||
{
|
||||
pauseOverlay = new PauseOverlay
|
||||
{
|
||||
OnResume = () => Logger.Log(@"Resume"),
|
||||
OnRetry = () => Logger.Log(@"Retry"),
|
||||
OnRetry = () =>
|
||||
{
|
||||
Logger.Log(@"Retry");
|
||||
triggeredRetryButton = true;
|
||||
},
|
||||
OnQuit = () => Logger.Log(@"Quit"),
|
||||
},
|
||||
failOverlay = new FailOverlay
|
||||
@ -224,17 +231,9 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
{
|
||||
showOverlay();
|
||||
|
||||
bool triggered = false;
|
||||
AddStep("Click retry button", () =>
|
||||
{
|
||||
var lastAction = pauseOverlay.OnRetry;
|
||||
pauseOverlay.OnRetry = () => triggered = true;
|
||||
AddStep("Click retry button", () => getButton(1).TriggerClick());
|
||||
|
||||
getButton(1).TriggerClick();
|
||||
pauseOverlay.OnRetry = lastAction;
|
||||
});
|
||||
|
||||
AddAssert("Action was triggered", () => triggered);
|
||||
AddAssert("Retry was triggered", () => triggeredRetryButton);
|
||||
AddAssert("Overlay is closed", () => pauseOverlay.State.Value == Visibility.Hidden);
|
||||
}
|
||||
|
||||
@ -252,25 +251,9 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
InputManager.Key(Key.Down);
|
||||
});
|
||||
|
||||
bool triggered = false;
|
||||
Action lastAction = null;
|
||||
AddStep("Press enter", () =>
|
||||
{
|
||||
lastAction = pauseOverlay.OnRetry;
|
||||
pauseOverlay.OnRetry = () => triggered = true;
|
||||
InputManager.Key(Key.Enter);
|
||||
});
|
||||
AddStep("Press enter", () => InputManager.Key(Key.Enter));
|
||||
|
||||
AddAssert("Action was triggered", () =>
|
||||
{
|
||||
if (lastAction != null)
|
||||
{
|
||||
pauseOverlay.OnRetry = lastAction;
|
||||
lastAction = null;
|
||||
}
|
||||
|
||||
return triggered;
|
||||
});
|
||||
AddAssert("Retry was triggered", () => triggeredRetryButton);
|
||||
AddAssert("Overlay is closed", () => pauseOverlay.State.Value == Visibility.Hidden);
|
||||
}
|
||||
|
||||
|
@ -38,9 +38,9 @@ namespace osu.Game.Screens.Play
|
||||
|
||||
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => true;
|
||||
|
||||
public Action? OnResume;
|
||||
public Action? OnRetry;
|
||||
public Action? OnQuit;
|
||||
public Action? OnResume { get; init; }
|
||||
public Action? OnRetry { get; init; }
|
||||
public Action? OnQuit { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Action that is invoked when <see cref="GlobalAction.Back"/> is triggered.
|
||||
|
Loading…
Reference in New Issue
Block a user