1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-26 17:52:54 +08:00
osu-lazer/osu.Game.Tests/Visual/TestCaseHoldForMenuButton.cs

54 lines
1.9 KiB
C#
Raw Normal View History

2018-04-29 00:24:49 +08:00
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
2018-04-29 00:24:49 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
using osu.Game.Screens.Play.HUD;
2018-11-20 15:51:59 +08:00
using osuTK;
using osuTK.Input;
2018-04-29 00:24:49 +08:00
namespace osu.Game.Tests.Visual
{
[Description("'Hold to Quit' UI element")]
public class TestCaseHoldForMenuButton : ManualInputManagerTestCase
2018-04-29 00:24:49 +08:00
{
private bool exitAction;
[BackgroundDependencyLoader]
private void load()
2018-04-29 00:24:49 +08:00
{
HoldForMenuButton holdForMenuButton;
Add(holdForMenuButton = new HoldForMenuButton
2018-04-29 00:24:49 +08:00
{
Origin = Anchor.BottomRight,
Anchor = Anchor.BottomRight,
Action = () => exitAction = true
2018-04-29 00:24:49 +08:00
});
var text = holdForMenuButton.Children.OfType<SpriteText>().First();
2018-05-04 05:01:00 +08:00
AddStep("Trigger text fade in", () => InputManager.MoveMouseTo(holdForMenuButton));
2018-04-29 00:24:49 +08:00
AddUntilStep(() => text.IsPresent && !exitAction, "Text visible");
AddStep("Trigger text fade out", () => InputManager.MoveMouseTo(Vector2.One));
2018-04-29 00:24:49 +08:00
AddUntilStep(() => !text.IsPresent && !exitAction, "Text is not visible");
AddStep("Trigger exit action", () =>
{
exitAction = false;
InputManager.MoveMouseTo(holdForMenuButton);
2018-05-25 18:08:46 +08:00
InputManager.PressButton(MouseButton.Left);
2018-04-29 00:24:49 +08:00
});
2018-05-25 18:08:46 +08:00
AddStep("Early release", () => InputManager.ReleaseButton(MouseButton.Left));
AddAssert("action not triggered", () => !exitAction);
2018-05-25 18:08:46 +08:00
AddStep("Trigger exit action", () => InputManager.PressButton(MouseButton.Left));
AddUntilStep(() => exitAction, $"{nameof(holdForMenuButton.Action)} was triggered");
2018-04-29 00:24:49 +08:00
}
}
}