1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-12 23:12:56 +08:00

Improve test coverage and segregation

This commit is contained in:
Dean Herbert 2024-08-06 19:25:23 +09:00
parent 9ccd8c906d
commit f7b45a26de
No known key found for this signature in database

View File

@ -12,6 +12,7 @@ using osu.Game.Overlays.Mods;
using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Osu.Mods; using osu.Game.Rulesets.Osu.Mods;
using osuTK; using osuTK;
using osuTK.Input;
namespace osu.Game.Tests.Visual.UserInterface namespace osu.Game.Tests.Visual.UserInterface
{ {
@ -27,6 +28,9 @@ namespace osu.Game.Tests.Visual.UserInterface
[SetUp] [SetUp]
public void SetUp() => Schedule(() => public void SetUp() => Schedule(() =>
{ {
SelectedMods.Value = Array.Empty<Mod>();
InputManager.MoveMouseTo(Vector2.One);
Child = new Container Child = new Container
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
@ -71,66 +75,87 @@ namespace osu.Game.Tests.Visual.UserInterface
} }
[Test] [Test]
public void TestHoverExpand() public void TestHoverDoesNotExpandWhenNoCustomisableMods()
{ {
// Can not expand by hovering when no supported mod AddStep("hover header", () => InputManager.MoveMouseTo(header));
{
AddStep("hover header", () => InputManager.MoveMouseTo(header));
AddAssert("not expanded", () => !panel.Expanded); checkExpanded(false);
AddStep("hover content", () => InputManager.MoveMouseTo(content)); AddStep("hover content", () => InputManager.MoveMouseTo(content));
AddAssert("neither expanded", () => !panel.Expanded); checkExpanded(false);
AddStep("left from content", () => InputManager.MoveMouseTo(Vector2.One)); AddStep("left from content", () => InputManager.MoveMouseTo(Vector2.One));
} }
[Test]
public void TestHoverExpandsWithCustomisableMods()
{
AddStep("add customisable mod", () => AddStep("add customisable mod", () =>
{ {
SelectedMods.Value = new[] { new OsuModDoubleTime() }; SelectedMods.Value = new[] { new OsuModDoubleTime() };
panel.Enabled.Value = true; panel.Enabled.Value = true;
}); });
// Can expand by hovering when supported mod AddStep("hover header", () => InputManager.MoveMouseTo(header));
checkExpanded(true);
AddStep("move to content", () => InputManager.MoveMouseTo(content));
checkExpanded(true);
AddStep("move away", () => InputManager.MoveMouseTo(Vector2.One));
checkExpanded(false);
AddStep("hover header", () => InputManager.MoveMouseTo(header));
checkExpanded(true);
AddStep("move away", () => InputManager.MoveMouseTo(Vector2.One));
checkExpanded(false);
}
[Test]
public void TestExpandedStatePersistsWhenClicked()
{
AddStep("add customisable mod", () =>
{ {
AddStep("hover header", () => InputManager.MoveMouseTo(header)); SelectedMods.Value = new[] { new OsuModDoubleTime() };
panel.Enabled.Value = true;
});
AddAssert("expanded", () => panel.Expanded); AddStep("hover header", () => InputManager.MoveMouseTo(header));
checkExpanded(true);
AddStep("hover content", () => InputManager.MoveMouseTo(content)); AddStep("click", () => InputManager.Click(MouseButton.Left));
checkExpanded(false);
AddStep("click", () => InputManager.Click(MouseButton.Left));
checkExpanded(true);
AddAssert("still expanded", () => panel.Expanded); AddStep("move away", () => InputManager.MoveMouseTo(Vector2.One));
} checkExpanded(true);
// Will collapse when mouse left from content AddStep("click", () => InputManager.Click(MouseButton.Left));
checkExpanded(false);
}
[Test]
public void TestHoverExpandsAndCollapsesWhenHeaderClicked()
{
AddStep("add customisable mod", () =>
{ {
AddStep("left from content", () => InputManager.MoveMouseTo(Vector2.One)); SelectedMods.Value = new[] { new OsuModDoubleTime() };
panel.Enabled.Value = true;
});
AddAssert("not expanded", () => !panel.Expanded); AddStep("hover header", () => InputManager.MoveMouseTo(header));
} checkExpanded(true);
// Will collapse when mouse left from header AddStep("click", () => InputManager.Click(MouseButton.Left));
{ checkExpanded(false);
AddStep("hover header", () => InputManager.MoveMouseTo(header)); }
AddAssert("expanded", () => panel.Expanded); private void checkExpanded(bool expanded)
{
AddStep("left from header", () => InputManager.MoveMouseTo(Vector2.One)); AddUntilStep(expanded ? "is expanded" : "not expanded", () => panel.Expanded, () => Is.EqualTo(expanded));
AddAssert("not expanded", () => !panel.Expanded);
}
// Not collapse when mouse left if not expanded by hovering
{
AddStep("expand not by hovering", () => panel.Expanded = true);
AddStep("hover content", () => InputManager.MoveMouseTo(content));
AddStep("moust left", () => InputManager.MoveMouseTo(Vector2.One));
AddAssert("still expanded", () => panel.Expanded);
}
} }
} }
} }