1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-14 20:33:09 +08:00

Add failing test case

Includes a refactor of `ThemeComparisonTestScene` to allow accessing a manual input manager.
This commit is contained in:
Salman Ahmed 2024-06-27 06:41:39 +03:00
parent ec86cc1333
commit e4335a543e
4 changed files with 70 additions and 46 deletions

View File

@ -21,7 +21,7 @@ namespace osu.Game.Tests.Visual.Settings
{
AddStep("create", () =>
{
Cell(0, 0).Children = new Drawable[]
ContentContainer.Children = new Drawable[]
{
new Box
{

View File

@ -6,23 +6,51 @@ using NUnit.Framework;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Events;
using osu.Framework.Input.States;
using osu.Framework.Testing;
using osu.Game.Graphics.UserInterface;
using osu.Game.Input.Bindings;
using osuTK.Input;
namespace osu.Game.Tests.Visual.UserInterface
{
public partial class TestSceneOsuDropdown : ThemeComparisonTestScene
{
protected override Drawable CreateContent() =>
new OsuEnumDropdown<TestEnum>
{
Anchor = Anchor.Centre,
Origin = Anchor.TopCentre,
Width = 150
};
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();
private enum TestEnum
{
@ -32,26 +60,5 @@ namespace osu.Game.Tests.Visual.UserInterface
[System.ComponentModel.Description("Really lonnnnnnng option")]
ReallyLongOption,
}
[Test]
// todo: this can be written much better if ThemeComparisonTestScene has a manual input manager
public void TestBackAction()
{
AddStep("open", () => dropdown().ChildrenOfType<Menu>().Single().Open());
AddStep("press back", () => dropdown().OnPressed(new KeyBindingPressEvent<GlobalAction>(new InputState(), GlobalAction.Back)));
AddAssert("closed", () => dropdown().ChildrenOfType<Menu>().Single().State == MenuState.Closed);
AddStep("open", () => dropdown().ChildrenOfType<Menu>().Single().Open());
AddStep("type something", () => dropdown().ChildrenOfType<DropdownSearchBar>().Single().SearchTerm.Value = "something");
AddAssert("search bar visible", () => dropdown().ChildrenOfType<DropdownSearchBar>().Single().State.Value == Visibility.Visible);
AddStep("press back", () => dropdown().OnPressed(new KeyBindingPressEvent<GlobalAction>(new InputState(), GlobalAction.Back)));
AddAssert("text clear", () => dropdown().ChildrenOfType<DropdownSearchBar>().Single().SearchTerm.Value == string.Empty);
AddAssert("search bar hidden", () => dropdown().ChildrenOfType<DropdownSearchBar>().Single().State.Value == Visibility.Hidden);
AddAssert("still open", () => dropdown().ChildrenOfType<Menu>().Single().State == MenuState.Open);
AddStep("press back", () => dropdown().OnPressed(new KeyBindingPressEvent<GlobalAction>(new InputState(), GlobalAction.Back)));
AddAssert("closed", () => dropdown().ChildrenOfType<Menu>().Single().State == MenuState.Closed);
OsuEnumDropdown<TestEnum> dropdown() => this.ChildrenOfType<OsuEnumDropdown<TestEnum>>().First();
}
}
}

View File

@ -53,8 +53,8 @@ namespace osu.Game.Tests.Visual.UserInterface
public void TestBackgroundColour()
{
AddStep("set red scheme", () => CreateThemedContent(OverlayColourScheme.Red));
AddAssert("rounded button has correct colour", () => Cell(0, 1).ChildrenOfType<RoundedButton>().First().BackgroundColour == new OverlayColourProvider(OverlayColourScheme.Red).Colour3);
AddAssert("settings button has correct colour", () => Cell(0, 1).ChildrenOfType<SettingsButton>().First().BackgroundColour == new OverlayColourProvider(OverlayColourScheme.Red).Colour3);
AddAssert("rounded button has correct colour", () => ContentContainer.ChildrenOfType<RoundedButton>().First().BackgroundColour == new OverlayColourProvider(OverlayColourScheme.Red).Colour3);
AddAssert("settings button has correct colour", () => ContentContainer.ChildrenOfType<SettingsButton>().First().BackgroundColour == new OverlayColourProvider(OverlayColourScheme.Red).Colour3);
}
}
}

View File

@ -6,18 +6,21 @@ using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics;
using osu.Game.Overlays;
using osuTK;
namespace osu.Game.Tests.Visual.UserInterface
{
public abstract partial class ThemeComparisonTestScene : OsuGridTestScene
public abstract partial class ThemeComparisonTestScene : OsuManualInputManagerTestScene
{
private readonly bool showWithoutColourProvider;
public Container ContentContainer { get; private set; } = null!;
protected ThemeComparisonTestScene(bool showWithoutColourProvider = true)
: base(1, showWithoutColourProvider ? 2 : 1)
{
this.showWithoutColourProvider = showWithoutColourProvider;
}
@ -25,16 +28,32 @@ namespace osu.Game.Tests.Visual.UserInterface
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
Child = ContentContainer = new Container
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
RelativeSizeAxes = Axes.Both,
};
if (showWithoutColourProvider)
{
Cell(0, 0).AddRange(new[]
ContentContainer.Size = new Vector2(0.5f, 1f);
Add(new Container
{
new Box
Anchor = Anchor.TopLeft,
Origin = Anchor.TopLeft,
RelativeSizeAxes = Axes.Both,
Size = new Vector2(0.5f, 1f),
Children = new[]
{
RelativeSizeAxes = Axes.Both,
Colour = colours.GreySeaFoam
},
CreateContent()
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = colours.GreySeaFoam
},
CreateContent()
}
});
}
}
@ -43,10 +62,8 @@ namespace osu.Game.Tests.Visual.UserInterface
{
var colourProvider = new OverlayColourProvider(colourScheme);
int col = showWithoutColourProvider ? 1 : 0;
Cell(0, col).Clear();
Cell(0, col).Add(new DependencyProvidingContainer
ContentContainer.Clear();
ContentContainer.Add(new DependencyProvidingContainer
{
RelativeSizeAxes = Axes.Both,
CachedDependencies = new (Type, object)[]