From 68495c937d975ff23052bb1c029a08ace9537847 Mon Sep 17 00:00:00 2001 From: Dao Heng Liu Date: Wed, 19 Jul 2023 01:59:40 +0100 Subject: [PATCH] fix ResetBracketTeams tests also fixes formatting and var naming issues --- .../Screens/TestSceneLadderEditorScreen.cs | 32 ++++++++++--------- .../TournamentTestScene.cs | 6 ++-- .../Components/TournamentClearAllDialog.cs | 1 - 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/osu.Game.Tournament.Tests/Screens/TestSceneLadderEditorScreen.cs b/osu.Game.Tournament.Tests/Screens/TestSceneLadderEditorScreen.cs index f41289a28f..bbf4da803e 100644 --- a/osu.Game.Tournament.Tests/Screens/TestSceneLadderEditorScreen.cs +++ b/osu.Game.Tournament.Tests/Screens/TestSceneLadderEditorScreen.cs @@ -3,9 +3,13 @@ #nullable disable +using System; using System.Linq; +using Newtonsoft.Json; using NUnit.Framework; +using osu.Framework.Bindables; using osu.Framework.Graphics; +using osu.Framework.Logging; using osu.Game.Graphics.Cursor; using osu.Game.Tournament.Screens.Editors; using osu.Framework.Testing; @@ -35,12 +39,16 @@ namespace osu.Game.Tournament.Tests.Screens [Test] public void TestResetBracketTeamsCancelled() { + Bindable matchBeforeReset = new Bindable(); + AddStep("save current match state", () => + { + matchBeforeReset.Value = JsonConvert.SerializeObject(Ladder.CurrentMatch.Value); + }); AddStep("pull up context menu", () => { InputManager.MoveMouseTo(ladderEditorScreen); InputManager.Click(MouseButton.Right); }); - AddStep("click Reset teams button", () => { InputManager.MoveMouseTo(osuContextMenuContainer.ChildrenOfType().Last(p => @@ -48,19 +56,16 @@ namespace osu.Game.Tournament.Tests.Screens InputManager.Click(MouseButton.Left); }); - AddAssert("dialog displayed", () => dialogOverlay.CurrentDialog is LadderResetTeamsDialog); + AddAssert("dialog displayed", () => DialogOverlay.CurrentDialog is LadderResetTeamsDialog); AddStep("click cancel", () => { - InputManager.MoveMouseTo(dialogOverlay.CurrentDialog.ChildrenOfType().Last()); + InputManager.MoveMouseTo(DialogOverlay.CurrentDialog.ChildrenOfType().Last()); InputManager.Click(MouseButton.Left); }); - AddUntilStep("dialog dismissed", () => dialogOverlay.CurrentDialog is not LadderResetTeamsDialog); + 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); - }); + AddAssert("assert ladder teams unchanged", () => string.Equals(matchBeforeReset.Value, JsonConvert.SerializeObject(Ladder.CurrentMatch.Value), StringComparison.Ordinal)); } [Test] @@ -79,22 +84,19 @@ namespace osu.Game.Tournament.Tests.Screens InputManager.Click(MouseButton.Left); }); - AddAssert("dialog displayed", () => dialogOverlay.CurrentDialog is LadderResetTeamsDialog); + AddAssert("dialog displayed", () => DialogOverlay.CurrentDialog is LadderResetTeamsDialog); AddStep("click confirmation", () => { - InputManager.MoveMouseTo(dialogOverlay.CurrentDialog.ChildrenOfType().First()); + InputManager.MoveMouseTo(DialogOverlay.CurrentDialog.ChildrenOfType().First()); InputManager.PressButton(MouseButton.Left); }); - AddUntilStep("dialog dismissed", () => dialogOverlay.CurrentDialog is not LadderResetTeamsDialog); + 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); - }); + AddAssert("assert ladder teams reset", () => Ladder.CurrentMatch.Value.Team1.Value == null && Ladder.CurrentMatch.Value.Team2.Value == null); } } } diff --git a/osu.Game.Tournament.Tests/TournamentTestScene.cs b/osu.Game.Tournament.Tests/TournamentTestScene.cs index 2c59b28a7c..740145074e 100644 --- a/osu.Game.Tournament.Tests/TournamentTestScene.cs +++ b/osu.Game.Tournament.Tests/TournamentTestScene.cs @@ -22,7 +22,7 @@ namespace osu.Game.Tournament.Tests public abstract partial class TournamentTestScene : OsuManualInputManagerTestScene { private TournamentMatch match; - protected DialogOverlay dialogOverlay; + protected DialogOverlay DialogOverlay; [Cached] protected LadderInfo Ladder { get; private set; } = new LadderInfo(); @@ -48,9 +48,9 @@ namespace osu.Game.Tournament.Tests Ruleset.BindTo(Ladder.Ruleset); Dependencies.CacheAs(new StableInfo(storage)); - Add(dialogOverlay = new DialogOverlay { Depth = -1 }); + Add(DialogOverlay = new DialogOverlay { Depth = -1 }); - Dependencies.CacheAs(dialogOverlay); + Dependencies.CacheAs(DialogOverlay); } [SetUpSteps] diff --git a/osu.Game.Tournament/Screens/Editors/Components/TournamentClearAllDialog.cs b/osu.Game.Tournament/Screens/Editors/Components/TournamentClearAllDialog.cs index 06b1071ce9..036a81dc62 100644 --- a/osu.Game.Tournament/Screens/Editors/Components/TournamentClearAllDialog.cs +++ b/osu.Game.Tournament/Screens/Editors/Components/TournamentClearAllDialog.cs @@ -8,7 +8,6 @@ using osu.Game.Overlays.Dialog; namespace osu.Game.Tournament.Screens.Editors.Components { public partial class TournamentClearAllDialog : DangerousActionDialog - { public TournamentClearAllDialog(IList storage) {