2020-04-15 06:50:19 +00:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
|
|
|
using System.Linq;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Testing;
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
|
|
|
using osuTK.Input;
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.UserInterface
|
|
|
|
{
|
|
|
|
public class TestSceneOsuMenu : OsuManualInputManagerTestScene
|
|
|
|
{
|
|
|
|
private OsuMenu menu;
|
2020-04-16 01:44:08 +00:00
|
|
|
private bool actionPerformed;
|
2020-04-15 06:50:19 +00:00
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
public void Setup() => Schedule(() =>
|
|
|
|
{
|
2020-04-16 01:44:08 +00:00
|
|
|
actionPerformed = false;
|
2020-04-15 06:50:19 +00:00
|
|
|
|
|
|
|
Child = menu = new OsuMenu(Direction.Vertical, true)
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Items = new[]
|
|
|
|
{
|
|
|
|
new OsuMenuItem("standard", MenuItemType.Standard, performAction),
|
|
|
|
new OsuMenuItem("highlighted", MenuItemType.Highlighted, performAction),
|
|
|
|
new OsuMenuItem("destructive", MenuItemType.Destructive, performAction),
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestClickEnabledMenuItem()
|
|
|
|
{
|
|
|
|
AddStep("move to first menu item", () => InputManager.MoveMouseTo(menu.ChildrenOfType<DrawableOsuMenuItem>().First()));
|
|
|
|
AddStep("click", () => InputManager.Click(MouseButton.Left));
|
|
|
|
|
2020-04-16 01:44:08 +00:00
|
|
|
AddAssert("action performed", () => actionPerformed);
|
2020-04-15 06:50:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestDisableMenuItemsAndClick()
|
|
|
|
{
|
|
|
|
AddStep("disable menu items", () =>
|
|
|
|
{
|
|
|
|
foreach (var item in menu.Items)
|
2020-04-16 04:25:08 +00:00
|
|
|
((OsuMenuItem)item).Action.Disabled = true;
|
2020-04-15 06:50:19 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("move to first menu item", () => InputManager.MoveMouseTo(menu.ChildrenOfType<DrawableOsuMenuItem>().First()));
|
|
|
|
AddStep("click", () => InputManager.Click(MouseButton.Left));
|
|
|
|
|
2020-04-16 01:44:08 +00:00
|
|
|
AddAssert("action not performed", () => !actionPerformed);
|
2020-04-15 06:50:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestEnableMenuItemsAndClick()
|
|
|
|
{
|
|
|
|
AddStep("disable menu items", () =>
|
|
|
|
{
|
|
|
|
foreach (var item in menu.Items)
|
2020-04-16 04:25:08 +00:00
|
|
|
((OsuMenuItem)item).Action.Disabled = true;
|
2020-04-15 06:50:19 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("enable menu items", () =>
|
|
|
|
{
|
|
|
|
foreach (var item in menu.Items)
|
2020-04-16 04:25:08 +00:00
|
|
|
((OsuMenuItem)item).Action.Disabled = false;
|
2020-04-15 06:50:19 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("move to first menu item", () => InputManager.MoveMouseTo(menu.ChildrenOfType<DrawableOsuMenuItem>().First()));
|
|
|
|
AddStep("click", () => InputManager.Click(MouseButton.Left));
|
|
|
|
|
2020-04-16 01:44:08 +00:00
|
|
|
AddAssert("action performed", () => actionPerformed);
|
2020-04-15 06:50:19 +00:00
|
|
|
}
|
|
|
|
|
2020-04-16 01:44:08 +00:00
|
|
|
private void performAction() => actionPerformed = true;
|
2020-04-15 06:50:19 +00:00
|
|
|
}
|
|
|
|
}
|