mirror of
https://github.com/ppy/osu.git
synced 2025-02-15 09:42:57 +08:00
Add failing test case
Includes a refactor of `ThemeComparisonTestScene` to allow accessing a manual input manager.
This commit is contained in:
parent
ec86cc1333
commit
e4335a543e
@ -21,7 +21,7 @@ namespace osu.Game.Tests.Visual.Settings
|
|||||||
{
|
{
|
||||||
AddStep("create", () =>
|
AddStep("create", () =>
|
||||||
{
|
{
|
||||||
Cell(0, 0).Children = new Drawable[]
|
ContentContainer.Children = new Drawable[]
|
||||||
{
|
{
|
||||||
new Box
|
new Box
|
||||||
{
|
{
|
||||||
|
@ -6,23 +6,51 @@ using NUnit.Framework;
|
|||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics.UserInterface;
|
using osu.Framework.Graphics.UserInterface;
|
||||||
using osu.Framework.Input.Events;
|
|
||||||
using osu.Framework.Input.States;
|
|
||||||
using osu.Framework.Testing;
|
using osu.Framework.Testing;
|
||||||
using osu.Game.Graphics.UserInterface;
|
using osu.Game.Graphics.UserInterface;
|
||||||
using osu.Game.Input.Bindings;
|
using osuTK.Input;
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual.UserInterface
|
namespace osu.Game.Tests.Visual.UserInterface
|
||||||
{
|
{
|
||||||
public partial class TestSceneOsuDropdown : ThemeComparisonTestScene
|
public partial class TestSceneOsuDropdown : ThemeComparisonTestScene
|
||||||
{
|
{
|
||||||
protected override Drawable CreateContent() =>
|
protected override Drawable CreateContent() => new OsuEnumDropdown<TestEnum>
|
||||||
new OsuEnumDropdown<TestEnum>
|
{
|
||||||
{
|
Anchor = Anchor.Centre,
|
||||||
Anchor = Anchor.Centre,
|
Origin = Anchor.TopCentre,
|
||||||
Origin = Anchor.TopCentre,
|
Width = 150
|
||||||
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
|
private enum TestEnum
|
||||||
{
|
{
|
||||||
@ -32,26 +60,5 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
[System.ComponentModel.Description("Really lonnnnnnng option")]
|
[System.ComponentModel.Description("Really lonnnnnnng option")]
|
||||||
ReallyLongOption,
|
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,8 +53,8 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
public void TestBackgroundColour()
|
public void TestBackgroundColour()
|
||||||
{
|
{
|
||||||
AddStep("set red scheme", () => CreateThemedContent(OverlayColourScheme.Red));
|
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("rounded button has correct colour", () => ContentContainer.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("settings button has correct colour", () => ContentContainer.ChildrenOfType<SettingsButton>().First().BackgroundColour == new OverlayColourProvider(OverlayColourScheme.Red).Colour3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,18 +6,21 @@ using System.Linq;
|
|||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics.Shapes;
|
using osu.Framework.Graphics.Shapes;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Overlays;
|
using osu.Game.Overlays;
|
||||||
|
using osuTK;
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual.UserInterface
|
namespace osu.Game.Tests.Visual.UserInterface
|
||||||
{
|
{
|
||||||
public abstract partial class ThemeComparisonTestScene : OsuGridTestScene
|
public abstract partial class ThemeComparisonTestScene : OsuManualInputManagerTestScene
|
||||||
{
|
{
|
||||||
private readonly bool showWithoutColourProvider;
|
private readonly bool showWithoutColourProvider;
|
||||||
|
|
||||||
|
public Container ContentContainer { get; private set; } = null!;
|
||||||
|
|
||||||
protected ThemeComparisonTestScene(bool showWithoutColourProvider = true)
|
protected ThemeComparisonTestScene(bool showWithoutColourProvider = true)
|
||||||
: base(1, showWithoutColourProvider ? 2 : 1)
|
|
||||||
{
|
{
|
||||||
this.showWithoutColourProvider = showWithoutColourProvider;
|
this.showWithoutColourProvider = showWithoutColourProvider;
|
||||||
}
|
}
|
||||||
@ -25,16 +28,32 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(OsuColour colours)
|
private void load(OsuColour colours)
|
||||||
{
|
{
|
||||||
|
Child = ContentContainer = new Container
|
||||||
|
{
|
||||||
|
Anchor = Anchor.TopRight,
|
||||||
|
Origin = Anchor.TopRight,
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
};
|
||||||
|
|
||||||
if (showWithoutColourProvider)
|
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,
|
new Box
|
||||||
Colour = colours.GreySeaFoam
|
{
|
||||||
},
|
RelativeSizeAxes = Axes.Both,
|
||||||
CreateContent()
|
Colour = colours.GreySeaFoam
|
||||||
|
},
|
||||||
|
CreateContent()
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -43,10 +62,8 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
{
|
{
|
||||||
var colourProvider = new OverlayColourProvider(colourScheme);
|
var colourProvider = new OverlayColourProvider(colourScheme);
|
||||||
|
|
||||||
int col = showWithoutColourProvider ? 1 : 0;
|
ContentContainer.Clear();
|
||||||
|
ContentContainer.Add(new DependencyProvidingContainer
|
||||||
Cell(0, col).Clear();
|
|
||||||
Cell(0, col).Add(new DependencyProvidingContainer
|
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
CachedDependencies = new (Type, object)[]
|
CachedDependencies = new (Type, object)[]
|
||||||
|
Loading…
Reference in New Issue
Block a user