2023-06-23 00:37:25 +08:00
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
2019-03-04 12:24:19 +08:00
// See the LICENCE file in the repository root for full licence text.
2018-09-10 03:51:38 +08:00
2023-07-19 08:59:40 +08:00
using System ;
2023-07-17 14:59:15 +08:00
using System.Linq ;
2023-07-19 08:59:40 +08:00
using Newtonsoft.Json ;
2023-07-17 14:59:15 +08:00
using NUnit.Framework ;
2023-07-19 08:59:40 +08:00
using osu.Framework.Bindables ;
2018-09-21 18:58:47 +08:00
using osu.Framework.Graphics ;
using osu.Game.Graphics.Cursor ;
2019-06-18 14:28:36 +08:00
using osu.Game.Tournament.Screens.Editors ;
2023-07-17 14:59:15 +08:00
using osu.Framework.Testing ;
using osu.Game.Graphics.UserInterface ;
using osu.Game.Overlays.Dialog ;
2023-07-19 06:44:53 +08:00
using osu.Game.Tournament.Screens.Editors.Components ;
2023-07-17 14:59:15 +08:00
using osuTK ;
using osuTK.Input ;
2018-09-10 03:51:38 +08:00
2019-06-18 14:28:36 +08:00
namespace osu.Game.Tournament.Tests.Screens
2018-09-10 03:51:38 +08:00
{
2023-07-24 17:22:32 +08:00
public partial class TestSceneLadderEditorScreen : TournamentScreenTestScene
2018-09-10 03:51:38 +08:00
{
2023-07-21 05:33:43 +08:00
private LadderEditorScreen ladderEditorScreen = null ! ;
private OsuContextMenuContainer ? osuContextMenuContainer ;
2023-07-17 14:59:15 +08:00
[SetUp]
public void Setup ( ) = > Schedule ( ( ) = >
2018-09-10 03:51:38 +08:00
{
2023-07-21 05:33:43 +08:00
ladderEditorScreen = new LadderEditorScreen ( ) ;
2023-07-17 14:59:15 +08:00
Add ( osuContextMenuContainer = new OsuContextMenuContainer
2018-09-21 18:58:47 +08:00
{
RelativeSizeAxes = Axes . Both ,
2023-07-17 14:59:15 +08:00
Child = ladderEditorScreen = new LadderEditorScreen ( )
} ) ;
} ) ;
[Test]
2023-07-17 15:11:28 +08:00
public void TestResetBracketTeamsCancelled ( )
2023-07-17 14:59:15 +08:00
{
2023-07-19 08:59:40 +08:00
Bindable < string > matchBeforeReset = new Bindable < string > ( ) ;
AddStep ( "save current match state" , ( ) = >
{
matchBeforeReset . Value = JsonConvert . SerializeObject ( Ladder . CurrentMatch . Value ) ;
} ) ;
2023-07-17 14:59:15 +08:00
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 ) ;
} ) ;
2023-07-19 08:59:40 +08:00
AddAssert ( "dialog displayed" , ( ) = > DialogOverlay . CurrentDialog is LadderResetTeamsDialog ) ;
2023-07-17 15:11:28 +08:00
AddStep ( "click cancel" , ( ) = >
2023-07-17 14:59:15 +08:00
{
2023-07-19 08:59:40 +08:00
InputManager . MoveMouseTo ( DialogOverlay . CurrentDialog . ChildrenOfType < PopupDialogButton > ( ) . Last ( ) ) ;
2023-07-17 15:11:28 +08:00
InputManager . Click ( MouseButton . Left ) ;
2023-07-17 14:59:15 +08:00
} ) ;
2023-07-19 08:59:40 +08:00
AddUntilStep ( "dialog dismissed" , ( ) = > DialogOverlay . CurrentDialog is not LadderResetTeamsDialog ) ;
2023-07-17 14:59:15 +08:00
2023-07-19 08:59:40 +08:00
AddAssert ( "assert ladder teams unchanged" , ( ) = > string . Equals ( matchBeforeReset . Value , JsonConvert . SerializeObject ( Ladder . CurrentMatch . Value ) , StringComparison . Ordinal ) ) ;
2023-07-17 14:59:15 +08:00
}
[Test]
2023-07-17 15:11:28 +08:00
public void TestResetBracketTeams ( )
2023-07-17 14:59:15 +08:00
{
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 ) ;
} ) ;
2023-07-19 08:59:40 +08:00
AddAssert ( "dialog displayed" , ( ) = > DialogOverlay . CurrentDialog is LadderResetTeamsDialog ) ;
2023-07-17 15:11:28 +08:00
AddStep ( "click confirmation" , ( ) = >
2023-07-17 14:59:15 +08:00
{
2023-07-19 08:59:40 +08:00
InputManager . MoveMouseTo ( DialogOverlay . CurrentDialog . ChildrenOfType < PopupDialogButton > ( ) . First ( ) ) ;
2023-07-17 15:11:28 +08:00
InputManager . PressButton ( MouseButton . Left ) ;
2023-07-17 14:59:15 +08:00
} ) ;
2023-07-19 08:59:40 +08:00
AddUntilStep ( "dialog dismissed" , ( ) = > DialogOverlay . CurrentDialog is not LadderResetTeamsDialog ) ;
2023-07-17 14:59:15 +08:00
2023-07-17 15:11:28 +08:00
AddStep ( "release mouse button" , ( ) = > InputManager . ReleaseButton ( MouseButton . Left ) ) ;
2023-07-25 19:50:55 +08:00
AddAssert ( "assert ladder teams reset" , ( ) = > Ladder . CurrentMatch . Value ? . Team1 . Value = = null & & Ladder . CurrentMatch . Value ? . Team2 . Value = = null ) ;
2018-09-10 03:51:38 +08:00
}
}
}