Rewrite test cases

- Depend less on arbitrary timings
- Remove unnecessary seeks
- Change method name to make more sense
- Use nunit style assertions
This commit is contained in:
Bartłomiej Dach 2023-02-19 13:33:06 +01:00
parent 80b329f069
commit 80ee917c77
No known key found for this signature in database

View File

@ -7,7 +7,7 @@ using osu.Framework.Allocation;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Testing; using osu.Framework.Testing;
using osu.Game.Configuration; using osu.Game.Configuration;
using osu.Game.Rulesets.Mania.Objects.Drawables; using osu.Game.Rulesets.Mania.UI;
using osu.Game.Tests.Visual; using osu.Game.Tests.Visual;
using osuTK.Input; using osuTK.Input;
@ -36,29 +36,32 @@ namespace osu.Game.Rulesets.Mania.Tests.Editor
[Test] [Test]
public void TestSeekOnNotePlacement() public void TestSeekOnNotePlacement()
{ {
AddStep("Seek to 1935", () => EditorClock.Seek(1935)); double? initialTime = null;
AddStep("Change seek setting to true", () => config.SetValue(OsuSetting.EditorSeekToHitObject, true));
seekSetup(); AddStep("store initial time", () => initialTime = EditorClock.CurrentTime);
AddUntilStep("Wait for seeking to end", () => !EditorClock.IsSeeking); AddStep("change seek setting to true", () => config.SetValue(OsuSetting.EditorSeekToHitObject, true));
AddAssert("Seeked to object", () => EditorClock.CurrentTimeAccurate == 2287.1875); placeObject();
AddUntilStep("wait for seek to complete", () => !EditorClock.IsSeeking);
AddAssert("seeked forward to object", () => EditorClock.CurrentTime, () => Is.GreaterThan(initialTime));
} }
[Test] [Test]
public void TestNoSeekOnNotePlacement() public void TestNoSeekOnNotePlacement()
{ {
AddStep("Seek to 1935", () => EditorClock.Seek(1935)); double? initialTime = null;
AddStep("Change seek setting to false", () => config.SetValue(OsuSetting.EditorSeekToHitObject, false));
seekSetup(); AddStep("store initial time", () => initialTime = EditorClock.CurrentTime);
AddAssert("Not seeking", () => !EditorClock.IsSeeking); AddStep("change seek setting to false", () => config.SetValue(OsuSetting.EditorSeekToHitObject, false));
AddAssert("Not seeked to object", () => EditorClock.CurrentTime == 1935); placeObject();
AddAssert("not seeking", () => !EditorClock.IsSeeking);
AddAssert("time is unchanged", () => EditorClock.CurrentTime, () => Is.EqualTo(initialTime));
} }
private void seekSetup() private void placeObject()
{ {
AddStep("Seek to 1935", () => EditorClock.Seek(1935)); AddStep("select note placement tool", () => InputManager.Key(Key.Number2));
AddStep("Select note", () => InputManager.Key(Key.Number2)); AddStep("move mouse to centre of last column", () => InputManager.MoveMouseTo(this.ChildrenOfType<Column>().Last().ScreenSpaceDrawQuad.Centre));
AddStep("Place note", () => InputManager.MoveMouseTo(this.ChildrenOfType<DrawableHoldNoteHead>().First(x => x.HitObject.StartTime == 2170))); AddStep("place note", () => InputManager.Click(MouseButton.Left));
AddStep("Click", () => InputManager.Click(MouseButton.Left));
} }
} }
} }