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