2023-06-23 00:37:25 +08:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
2021-10-17 00:12:02 +08:00
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
|
2023-12-06 03:50:05 +08:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using NUnit.Framework;
|
2021-10-17 00:12:02 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
2023-12-06 03:50:05 +08:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
|
|
|
|
using osu.Framework.Testing;
|
2021-10-17 00:12:02 +08:00
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2024-06-27 11:41:39 +08:00
|
|
|
|
using osuTK.Input;
|
2021-10-17 00:12:02 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.UserInterface
|
|
|
|
|
{
|
2022-11-24 13:32:20 +08:00
|
|
|
|
public partial class TestSceneOsuDropdown : ThemeComparisonTestScene
|
2021-10-17 00:12:02 +08:00
|
|
|
|
{
|
2024-06-27 11:41:39 +08:00
|
|
|
|
protected override Drawable CreateContent() => new OsuEnumDropdown<TestEnum>
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
Width = 150
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestBackAction()
|
|
|
|
|
{
|
|
|
|
|
AddStep("open", () => dropdownMenu.Open());
|
|
|
|
|
AddStep("press back", () => InputManager.Key(Key.Escape));
|
|
|
|
|
AddAssert("closed", () => dropdownMenu.State == MenuState.Closed);
|
|
|
|
|
|
|
|
|
|
AddStep("open", () => dropdownMenu.Open());
|
|
|
|
|
AddStep("type something", () => dropdownSearchBar.SearchTerm.Value = "something");
|
|
|
|
|
AddAssert("search bar visible", () => dropdownSearchBar.State.Value == Visibility.Visible);
|
|
|
|
|
AddStep("press back", () => InputManager.Key(Key.Escape));
|
|
|
|
|
AddAssert("text clear", () => dropdownSearchBar.SearchTerm.Value == string.Empty);
|
|
|
|
|
AddAssert("search bar hidden", () => dropdownSearchBar.State.Value == Visibility.Hidden);
|
|
|
|
|
AddAssert("still open", () => dropdownMenu.State == MenuState.Open);
|
|
|
|
|
AddStep("press back", () => InputManager.Key(Key.Escape));
|
|
|
|
|
AddAssert("closed", () => dropdownMenu.State == MenuState.Closed);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestSelectAction()
|
|
|
|
|
{
|
|
|
|
|
AddStep("open", () => dropdownMenu.Open());
|
|
|
|
|
AddStep("press down", () => InputManager.Key(Key.Down));
|
|
|
|
|
AddStep("press enter", () => InputManager.Key(Key.Enter));
|
|
|
|
|
AddAssert("second selected", () => dropdown.Current.Value == TestEnum.ReallyLongOption);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private OsuEnumDropdown<TestEnum> dropdown => this.ChildrenOfType<OsuEnumDropdown<TestEnum>>().Last();
|
|
|
|
|
private Menu dropdownMenu => dropdown.ChildrenOfType<Menu>().Single();
|
|
|
|
|
private DropdownSearchBar dropdownSearchBar => dropdown.ChildrenOfType<DropdownSearchBar>().Single();
|
2023-12-06 03:50:05 +08:00
|
|
|
|
|
2024-02-15 14:57:38 +08:00
|
|
|
|
private enum TestEnum
|
|
|
|
|
{
|
|
|
|
|
[System.ComponentModel.Description("Option")]
|
|
|
|
|
Option,
|
|
|
|
|
|
|
|
|
|
[System.ComponentModel.Description("Really lonnnnnnng option")]
|
|
|
|
|
ReallyLongOption,
|
|
|
|
|
}
|
2021-10-17 00:12:02 +08:00
|
|
|
|
}
|
|
|
|
|
}
|