1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-27 11:42:58 +08:00
osu-lazer/osu.Game.Tests/Visual/UserInterface/TestSceneOsuMenu.cs

86 lines
2.8 KiB
C#
Raw Normal View History

2020-04-15 14:50:19 +08: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.
2022-06-17 15:37:17 +08:00
#nullable disable
2020-04-15 14:50:19 +08:00
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 09:44:08 +08:00
private bool actionPerformed;
2020-04-15 14:50:19 +08:00
[SetUp]
public void Setup() => Schedule(() =>
{
2020-04-16 09:44:08 +08:00
actionPerformed = false;
2020-04-15 14:50:19 +08: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 09:44:08 +08:00
AddAssert("action performed", () => actionPerformed);
2020-04-15 14:50:19 +08:00
}
[Test]
public void TestDisableMenuItemsAndClick()
{
AddStep("disable menu items", () =>
{
foreach (var item in menu.Items)
((OsuMenuItem)item).Action.Disabled = true;
2020-04-15 14:50:19 +08:00
});
AddStep("move to first menu item", () => InputManager.MoveMouseTo(menu.ChildrenOfType<DrawableOsuMenuItem>().First()));
AddStep("click", () => InputManager.Click(MouseButton.Left));
2020-04-16 09:44:08 +08:00
AddAssert("action not performed", () => !actionPerformed);
2020-04-15 14:50:19 +08:00
}
[Test]
public void TestEnableMenuItemsAndClick()
{
AddStep("disable menu items", () =>
{
foreach (var item in menu.Items)
((OsuMenuItem)item).Action.Disabled = true;
2020-04-15 14:50:19 +08:00
});
AddStep("enable menu items", () =>
{
foreach (var item in menu.Items)
((OsuMenuItem)item).Action.Disabled = false;
2020-04-15 14:50:19 +08:00
});
AddStep("move to first menu item", () => InputManager.MoveMouseTo(menu.ChildrenOfType<DrawableOsuMenuItem>().First()));
AddStep("click", () => InputManager.Click(MouseButton.Left));
2020-04-16 09:44:08 +08:00
AddAssert("action performed", () => actionPerformed);
2020-04-15 14:50:19 +08:00
}
2020-04-16 09:44:08 +08:00
private void performAction() => actionPerformed = true;
2020-04-15 14:50:19 +08:00
}
}