diff --git a/osu.Game.Tests/Visual/TestCaseHoldToQuit.cs b/osu.Game.Tests/Visual/TestCaseHoldToQuit.cs new file mode 100644 index 0000000000..d7f024d905 --- /dev/null +++ b/osu.Game.Tests/Visual/TestCaseHoldToQuit.cs @@ -0,0 +1,56 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System.Linq; +using NUnit.Framework; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Sprites; +using osu.Game.Screens.Play.HUD; + +namespace osu.Game.Tests.Visual +{ + [Description("'Hold to Quit' UI element")] + public class TestCaseHoldToQuit : OsuTestCase + { + private bool exitAction; + + public TestCaseHoldToQuit() + { + HoldToQuit holdToQuit; + Add(holdToQuit = new HoldToQuit + { + Origin = Anchor.BottomRight, + Anchor = Anchor.BottomRight, + }); + holdToQuit.Button.ExitAction = () => exitAction = true; + + var text = holdToQuit.Children.OfType().Single(); + + AddStep("Text fade in", () => + { + exitAction = false; + holdToQuit.Button.TriggerOnMouseDown(); + holdToQuit.Button.TriggerOnMouseUp(); + }); + + AddUntilStep(() => text.IsPresent && !exitAction, "Text visible"); + + AddStep("Text fade out", () => + { + exitAction = false; + holdToQuit.Button.TriggerOnMouseDown(); + holdToQuit.Button.TriggerOnMouseUp(); + }); + + AddUntilStep(() => !text.IsPresent && !exitAction, "Text is not visible"); + + AddStep("Trigger exit action", () => + { + exitAction = false; + holdToQuit.Button.TriggerOnMouseDown(); + }); + + AddUntilStep(() => exitAction, $"{nameof(holdToQuit.Button.ExitAction)} was triggered"); + } + } +}