Skip to content

Commit

Permalink
fix ResetBracketTeams tests
Browse files Browse the repository at this point in the history
also fixes formatting and var naming issues
  • Loading branch information
ILW8 committed Jul 20, 2023
1 parent e67253e commit 68495c9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
32 changes: 17 additions & 15 deletions osu.Game.Tournament.Tests/Screens/TestSceneLadderEditorScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -35,32 +39,33 @@ public void Setup() => Schedule(() =>
[Test]
public void TestResetBracketTeamsCancelled()
{
Bindable<string> matchBeforeReset = new Bindable<string>();
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<DrawableOsuMenuItem>().Last(p =>
((OsuMenuItem)p.Item).Type == MenuItemType.Destructive), new Vector2(5, 0));
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<PopupDialogButton>().Last());
InputManager.MoveMouseTo(DialogOverlay.CurrentDialog.ChildrenOfType<PopupDialogButton>().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]
Expand All @@ -79,22 +84,19 @@ public void TestResetBracketTeams()
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<PopupDialogButton>().First());
InputManager.MoveMouseTo(DialogOverlay.CurrentDialog.ChildrenOfType<PopupDialogButton>().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);
}
}
}
6 changes: 3 additions & 3 deletions osu.Game.Tournament.Tests/TournamentTestScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -48,9 +48,9 @@ private void load(TournamentStorage storage)
Ruleset.BindTo(Ladder.Ruleset);
Dependencies.CacheAs(new StableInfo(storage));

Add(dialogOverlay = new DialogOverlay { Depth = -1 });
Add(DialogOverlay = new DialogOverlay { Depth = -1 });

Dependencies.CacheAs<IDialogOverlay>(dialogOverlay);
Dependencies.CacheAs<IDialogOverlay>(DialogOverlay);
}

[SetUpSteps]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
namespace osu.Game.Tournament.Screens.Editors.Components
{
public partial class TournamentClearAllDialog : DangerousActionDialog

{
public TournamentClearAllDialog(IList storage)
{
Expand Down

0 comments on commit 68495c9

Please sign in to comment.