From 6d2f9108132b45c07fcdb48aa7bc1a37f879c32b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Wed, 12 Jun 2024 15:43:33 +0200 Subject: [PATCH] Add test coverage --- .../Editor/TestSceneManiaHitObjectComposer.cs | 98 +++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/osu.Game.Rulesets.Mania.Tests/Editor/TestSceneManiaHitObjectComposer.cs b/osu.Game.Rulesets.Mania.Tests/Editor/TestSceneManiaHitObjectComposer.cs index cb0fc72a34..d88f488582 100644 --- a/osu.Game.Rulesets.Mania.Tests/Editor/TestSceneManiaHitObjectComposer.cs +++ b/osu.Game.Rulesets.Mania.Tests/Editor/TestSceneManiaHitObjectComposer.cs @@ -190,6 +190,104 @@ namespace osu.Game.Rulesets.Mania.Tests.Editor AddAssert("tail blueprint positioned correctly", () => this.ChildrenOfType().ElementAt(1).DrawPosition == holdNote.Tail.DrawPosition); } + [Test] + public void TestDragHoldNoteHead() + { + setScrollStep(ScrollingDirection.Down); + + HoldNote holdNote = null; + AddStep("setup beatmap", () => + { + composer.EditorBeatmap.Clear(); + composer.EditorBeatmap.Add(holdNote = new HoldNote + { + Column = 1, + StartTime = 250, + EndTime = 750, + }); + }); + + DrawableHoldNote drawableHoldNote = null; + EditHoldNoteEndPiece headPiece = null; + + AddStep("select blueprint", () => + { + drawableHoldNote = this.ChildrenOfType().Single(); + InputManager.MoveMouseTo(drawableHoldNote); + InputManager.Click(MouseButton.Left); + }); + AddStep("grab hold note head", () => + { + headPiece = this.ChildrenOfType().First(); + InputManager.MoveMouseTo(headPiece); + InputManager.PressButton(MouseButton.Left); + }); + + AddStep("drag head downwards", () => + { + InputManager.MoveMouseTo(headPiece, new Vector2(0, 100)); + InputManager.ReleaseButton(MouseButton.Left); + }); + + AddAssert("start time moved back", () => holdNote!.StartTime, () => Is.LessThan(250)); + AddAssert("end time unchanged", () => holdNote.EndTime, () => Is.EqualTo(750)); + + AddAssert("head note positioned correctly", () => Precision.AlmostEquals(drawableHoldNote.ScreenSpaceDrawQuad.BottomLeft, drawableHoldNote.Head.ScreenSpaceDrawQuad.BottomLeft)); + AddAssert("tail note positioned correctly", () => Precision.AlmostEquals(drawableHoldNote.ScreenSpaceDrawQuad.TopLeft, drawableHoldNote.Tail.ScreenSpaceDrawQuad.BottomLeft)); + + AddAssert("head blueprint positioned correctly", () => this.ChildrenOfType().ElementAt(0).DrawPosition == drawableHoldNote.Head.DrawPosition); + AddAssert("tail blueprint positioned correctly", () => this.ChildrenOfType().ElementAt(1).DrawPosition == drawableHoldNote.Tail.DrawPosition); + } + + [Test] + public void TestDragHoldNoteTail() + { + setScrollStep(ScrollingDirection.Down); + + HoldNote holdNote = null; + AddStep("setup beatmap", () => + { + composer.EditorBeatmap.Clear(); + composer.EditorBeatmap.Add(holdNote = new HoldNote + { + Column = 1, + StartTime = 250, + EndTime = 750, + }); + }); + + DrawableHoldNote drawableHoldNote = null; + EditHoldNoteEndPiece tailPiece = null; + + AddStep("select blueprint", () => + { + drawableHoldNote = this.ChildrenOfType().Single(); + InputManager.MoveMouseTo(drawableHoldNote); + InputManager.Click(MouseButton.Left); + }); + AddStep("grab hold note tail", () => + { + tailPiece = this.ChildrenOfType().Last(); + InputManager.MoveMouseTo(tailPiece); + InputManager.PressButton(MouseButton.Left); + }); + + AddStep("drag tail upwards", () => + { + InputManager.MoveMouseTo(tailPiece, new Vector2(0, -100)); + InputManager.ReleaseButton(MouseButton.Left); + }); + + AddAssert("start time unchanged", () => holdNote!.StartTime, () => Is.EqualTo(250)); + AddAssert("end time moved forward", () => holdNote.EndTime, () => Is.GreaterThan(750)); + + AddAssert("head note positioned correctly", () => Precision.AlmostEquals(drawableHoldNote.ScreenSpaceDrawQuad.BottomLeft, drawableHoldNote.Head.ScreenSpaceDrawQuad.BottomLeft)); + AddAssert("tail note positioned correctly", () => Precision.AlmostEquals(drawableHoldNote.ScreenSpaceDrawQuad.TopLeft, drawableHoldNote.Tail.ScreenSpaceDrawQuad.BottomLeft)); + + AddAssert("head blueprint positioned correctly", () => this.ChildrenOfType().ElementAt(0).DrawPosition == drawableHoldNote.Head.DrawPosition); + AddAssert("tail blueprint positioned correctly", () => this.ChildrenOfType().ElementAt(1).DrawPosition == drawableHoldNote.Tail.DrawPosition); + } + private void setScrollStep(ScrollingDirection direction) => AddStep($"set scroll direction = {direction}", () => ((Bindable)composer.Composer.ScrollingInfo.Direction).Value = direction);