Skip to content

Commit

Permalink
add ladder editor reset teams confirmation dialog test
Browse files Browse the repository at this point in the history
  • Loading branch information
ILW8 committed Jul 20, 2023
1 parent e779529 commit 3510394
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 6 deletions.
87 changes: 82 additions & 5 deletions osu.Game.Tournament.Tests/Screens/TestSceneLadderEditorScreen.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,99 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. 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<DrawableOsuMenuItem>().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<PopupDialogButton>().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<DrawableOsuMenuItem>().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<PopupDialogButton>().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);
});
}
}
Expand Down
8 changes: 7 additions & 1 deletion osu.Game.Tournament.Tests/TournamentTestScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
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;
Expand All @@ -18,9 +19,10 @@

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();
Expand All @@ -45,6 +47,10 @@ private void load(TournamentStorage storage)

Ruleset.BindTo(Ladder.Ruleset);
Dependencies.CacheAs(new StableInfo(storage));

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

Dependencies.CacheAs<IDialogOverlay>(dialogOverlay);
}

[SetUpSteps]
Expand Down

0 comments on commit 3510394

Please sign in to comment.