diff --git a/osu.Game.Tournament.Tests/Screens/TestSceneLadderEditorScreen.cs b/osu.Game.Tournament.Tests/Screens/TestSceneLadderEditorScreen.cs index 839730f3ca..825a976309 100644 --- a/osu.Game.Tournament.Tests/Screens/TestSceneLadderEditorScreen.cs +++ b/osu.Game.Tournament.Tests/Screens/TestSceneLadderEditorScreen.cs @@ -1,22 +1,99 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using osu.Framework.Allocation; +#nullable disable + +using System.Linq; +using NUnit.Framework; using osu.Framework.Graphics; using osu.Game.Graphics.Cursor; using osu.Game.Tournament.Screens.Editors; +using osu.Framework.Testing; +using osu.Game.Graphics.UserInterface; +using osu.Game.Overlays.Dialog; +using osu.Game.Tournament.Screens.Ladder.Components; +using osuTK; +using osuTK.Input; namespace osu.Game.Tournament.Tests.Screens { public partial class TestSceneLadderEditorScreen : TournamentTestScene { - [BackgroundDependencyLoader] - private void load() + private LadderEditorScreen ladderEditorScreen; + private OsuContextMenuContainer osuContextMenuContainer; + + [SetUp] + public void Setup() => Schedule(() => { - Add(new OsuContextMenuContainer + Add(osuContextMenuContainer = new OsuContextMenuContainer { RelativeSizeAxes = Axes.Both, - Child = new LadderEditorScreen() + Child = ladderEditorScreen = new LadderEditorScreen() + }); + }); + + [Test] + public void TestResetBracketTeams() + { + AddStep("pull up context menu", () => + { + InputManager.MoveMouseTo(ladderEditorScreen); + InputManager.Click(MouseButton.Right); + }); + + AddStep("click Reset teams button", () => + { + InputManager.MoveMouseTo(osuContextMenuContainer.ChildrenOfType().Last(p => + ((OsuMenuItem)p.Item).Type == MenuItemType.Destructive), new Vector2(5, 0)); + InputManager.Click(MouseButton.Left); + }); + + AddAssert("dialog displayed", () => dialogOverlay.CurrentDialog is LadderResetTeamsDialog); + + AddStep("click confirmation", () => + { + InputManager.MoveMouseTo(dialogOverlay.CurrentDialog.ChildrenOfType().First()); + InputManager.PressButton(MouseButton.Left); + }); + + AddUntilStep("dialog dismissed", () => dialogOverlay.CurrentDialog is not LadderResetTeamsDialog); + + AddStep("release mouse button", () => InputManager.ReleaseButton(MouseButton.Left)); + + AddAssert("assert ladder teams reset", () => + { + return Ladder.Matches.All(m => m.Team1.Value == null && m.Team2.Value == null); + }); + } + + [Test] + public void TestResetBracketTeamsCancelled() + { + AddStep("pull up context menu", () => + { + InputManager.MoveMouseTo(ladderEditorScreen); + InputManager.Click(MouseButton.Right); + }); + + AddStep("click Reset teams button", () => + { + InputManager.MoveMouseTo(osuContextMenuContainer.ChildrenOfType().Last(p => + ((OsuMenuItem)p.Item).Type == MenuItemType.Destructive), new Vector2(5, 0)); + InputManager.Click(MouseButton.Left); + }); + + AddAssert("dialog displayed", () => dialogOverlay.CurrentDialog is LadderResetTeamsDialog); + AddStep("click cancel", () => + { + InputManager.MoveMouseTo(dialogOverlay.CurrentDialog.ChildrenOfType().Last()); + InputManager.Click(MouseButton.Left); + }); + + AddUntilStep("dialog dismissed", () => dialogOverlay.CurrentDialog is not LadderResetTeamsDialog); + + AddAssert("assert ladder teams unchanged", () => + { + return !Ladder.Matches.Any(m => m.Team1.Value == null && m.Team2.Value == null); }); } } diff --git a/osu.Game.Tournament.Tests/TournamentTestScene.cs b/osu.Game.Tournament.Tests/TournamentTestScene.cs index cab78422a2..2c59b28a7c 100644 --- a/osu.Game.Tournament.Tests/TournamentTestScene.cs +++ b/osu.Game.Tournament.Tests/TournamentTestScene.cs @@ -10,6 +10,7 @@ using osu.Framework.Platform; using osu.Framework.Testing; using osu.Framework.Utils; using osu.Game.Beatmaps; +using osu.Game.Overlays; using osu.Game.Rulesets; using osu.Game.Tests.Visual; using osu.Game.Tournament.IO; @@ -18,9 +19,10 @@ using osu.Game.Tournament.Models; namespace osu.Game.Tournament.Tests { - public abstract partial class TournamentTestScene : OsuTestScene + public abstract partial class TournamentTestScene : OsuManualInputManagerTestScene { private TournamentMatch match; + protected DialogOverlay dialogOverlay; [Cached] protected LadderInfo Ladder { get; private set; } = new LadderInfo(); @@ -45,6 +47,10 @@ namespace osu.Game.Tournament.Tests Ruleset.BindTo(Ladder.Ruleset); Dependencies.CacheAs(new StableInfo(storage)); + + Add(dialogOverlay = new DialogOverlay { Depth = -1 }); + + Dependencies.CacheAs(dialogOverlay); } [SetUpSteps]