mirror of
https://github.com/osukey/osukey.git
synced 2025-08-04 07:06:35 +09:00
Share code with HoldToConfirm implementations elsewhere
This commit is contained in:
@ -3,49 +3,55 @@
|
||||
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Game.Screens.Play.HUD;
|
||||
using OpenTK;
|
||||
using OpenTK.Input;
|
||||
|
||||
namespace osu.Game.Tests.Visual
|
||||
{
|
||||
[Description("'Hold to Quit' UI element")]
|
||||
public class TestCaseQuitButton : OsuTestCase
|
||||
public class TestCaseQuitButton : ManualInputManagerTestCase
|
||||
{
|
||||
private readonly QuitButton quitButton;
|
||||
private Drawable innerButton => quitButton.Children.Single(child => child is CircularContainer);
|
||||
private bool exitAction;
|
||||
|
||||
public TestCaseQuitButton()
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
QuitButton quitButton;
|
||||
|
||||
Add(quitButton = new QuitButton
|
||||
{
|
||||
Origin = Anchor.BottomRight,
|
||||
Anchor = Anchor.BottomRight,
|
||||
});
|
||||
quitButton.ExitAction = () => exitAction = true;
|
||||
|
||||
var text = quitButton.Children.OfType<SpriteText>().Single();
|
||||
|
||||
AddStep("Trigger text fade in/out", () =>
|
||||
{
|
||||
exitAction = false;
|
||||
|
||||
innerButton.TriggerOnMouseDown();
|
||||
innerButton.TriggerOnMouseUp();
|
||||
Action = () => exitAction = true
|
||||
});
|
||||
|
||||
var text = quitButton.Children.OfType<SpriteText>().First();
|
||||
|
||||
// initial display
|
||||
AddUntilStep(() => text.IsPresent && !exitAction, "Text visible");
|
||||
AddUntilStep(() => !text.IsPresent && !exitAction, "Text is not visible");
|
||||
|
||||
AddStep("Trigger text fade in", () => InputManager.MoveMouseTo(quitButton));
|
||||
AddUntilStep(() => text.IsPresent && !exitAction, "Text visible");
|
||||
AddStep("Trigger text fade out", () => InputManager.MoveMouseTo(Vector2.One));
|
||||
AddUntilStep(() => !text.IsPresent && !exitAction, "Text is not visible");
|
||||
|
||||
AddStep("Trigger exit action", () =>
|
||||
{
|
||||
exitAction = false;
|
||||
innerButton.TriggerOnMouseDown();
|
||||
InputManager.MoveMouseTo(quitButton);
|
||||
InputManager.ButtonDown(MouseButton.Left);
|
||||
});
|
||||
|
||||
AddUntilStep(() => exitAction, $"{nameof(quitButton.ExitAction)} was triggered");
|
||||
AddStep("Early release", () => InputManager.ButtonUp(MouseButton.Left));
|
||||
AddAssert("action not triggered", () => !exitAction);
|
||||
|
||||
AddStep("Trigger exit action", () => InputManager.ButtonDown(MouseButton.Left));
|
||||
AddUntilStep(() => exitAction, $"{nameof(quitButton.Action)} was triggered");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user