Merge pull request #19455 from peppy/confirm-playlist-discard

Add confirmation dialog when about to discard a playlist
This commit is contained in:
Dean Herbert
2022-07-30 19:17:49 +09:00
committed by GitHub
6 changed files with 175 additions and 5 deletions

View File

@ -4,6 +4,7 @@
#nullable disable
using System.Linq;
using JetBrains.Annotations;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Audio;
@ -17,6 +18,8 @@ using osu.Game.Online.API;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Multiplayer;
using osu.Game.Online.Rooms;
using osu.Game.Overlays;
using osu.Game.Overlays.Dialog;
using osu.Game.Overlays.Mods;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Osu;
@ -24,6 +27,7 @@ using osu.Game.Rulesets.Osu.Mods;
using osu.Game.Rulesets.Taiko;
using osu.Game.Rulesets.Taiko.Mods;
using osu.Game.Rulesets.UI;
using osu.Game.Screens.Menu;
using osu.Game.Screens.OnlinePlay;
using osu.Game.Screens.OnlinePlay.Match;
using osu.Game.Screens.OnlinePlay.Multiplayer;
@ -65,7 +69,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
AddStep("load match", () =>
{
SelectedRoom.Value = new Room { Name = { Value = "Test Room" } };
LoadScreen(screen = new MultiplayerMatchSubScreen(SelectedRoom.Value));
LoadScreen(screen = new TestMultiplayerMatchSubScreen(SelectedRoom.Value));
});
AddUntilStep("wait for load", () => screen.IsCurrentScreen());
@ -281,5 +285,29 @@ namespace osu.Game.Tests.Visual.Multiplayer
return lastItem.IsSelectedItem;
});
}
private class TestMultiplayerMatchSubScreen : MultiplayerMatchSubScreen
{
[Resolved(canBeNull: true)]
[CanBeNull]
private IDialogOverlay dialogOverlay { get; set; }
public TestMultiplayerMatchSubScreen(Room room)
: base(room)
{
}
public override bool OnExiting(ScreenExitEvent e)
{
// For testing purposes allow the screen to exit without confirming on second attempt.
if (!ExitConfirmed && dialogOverlay?.CurrentDialog is ConfirmDiscardChangesDialog confirmDialog)
{
confirmDialog.PerformAction<PopupDialogDangerousButton>();
return true;
}
return base.OnExiting(e);
}
}
}
}

View File

@ -26,6 +26,7 @@ using osu.Game.Rulesets.Osu.Mods;
using osu.Game.Scoring;
using osu.Game.Screens.Menu;
using osu.Game.Screens.OnlinePlay.Lounge;
using osu.Game.Screens.OnlinePlay.Playlists;
using osu.Game.Screens.Play;
using osu.Game.Screens.Ranking;
using osu.Game.Screens.Select;
@ -45,6 +46,57 @@ namespace osu.Game.Tests.Visual.Navigation
private Vector2 optionsButtonPosition => Game.ToScreenSpace(new Vector2(click_padding, click_padding));
[TestCase(false)]
[TestCase(true)]
public void TestConfirmationRequiredToDiscardPlaylist(bool withPlaylistItemAdded)
{
Screens.OnlinePlay.Playlists.Playlists playlistScreen = null;
AddUntilStep("wait for dialog overlay", () => Game.ChildrenOfType<DialogOverlay>().SingleOrDefault() != null);
PushAndConfirm(() => playlistScreen = new Screens.OnlinePlay.Playlists.Playlists());
AddStep("import beatmap", () => BeatmapImportHelper.LoadQuickOszIntoOsu(Game).WaitSafely());
AddStep("open create screen", () =>
{
InputManager.MoveMouseTo(playlistScreen.ChildrenOfType<CreatePlaylistsRoomButton>().Single());
InputManager.Click(MouseButton.Left);
});
if (withPlaylistItemAdded)
{
AddUntilStep("wait for settings displayed",
() => (playlistScreen.CurrentSubScreen as PlaylistsRoomSubScreen)?.ChildrenOfType<PlaylistsRoomSettingsOverlay>().SingleOrDefault()?.State.Value == Visibility.Visible);
AddStep("edit playlist", () => InputManager.Key(Key.Enter));
AddUntilStep("wait for song select", () => (playlistScreen.CurrentSubScreen as PlaylistsSongSelect)?.BeatmapSetsLoaded == true);
AddUntilStep("wait for selection", () => !Game.Beatmap.IsDefault);
AddStep("add item", () => InputManager.Key(Key.Enter));
AddUntilStep("wait for return to playlist screen", () => playlistScreen.CurrentSubScreen is PlaylistsRoomSubScreen);
pushEscape();
AddAssert("confirmation dialog shown", () => Game.ChildrenOfType<DialogOverlay>().Single().CurrentDialog is not null);
AddStep("confirm exit", () => InputManager.Key(Key.Enter));
AddAssert("dialog dismissed", () => Game.ChildrenOfType<DialogOverlay>().Single().CurrentDialog == null);
exitViaEscapeAndConfirm();
}
else
{
pushEscape();
AddAssert("confirmation dialog not shown", () => Game.ChildrenOfType<DialogOverlay>().Single().CurrentDialog == null);
exitViaEscapeAndConfirm();
}
}
[Test]
public void TestExitSongSelectWithEscape()
{

View File

@ -6,6 +6,7 @@
using System;
using System.Diagnostics;
using System.Linq;
using JetBrains.Annotations;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Audio;
@ -16,9 +17,12 @@ using osu.Framework.Testing;
using osu.Game.Beatmaps;
using osu.Game.Database;
using osu.Game.Online.Rooms;
using osu.Game.Overlays;
using osu.Game.Overlays.Dialog;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Screens.Menu;
using osu.Game.Screens.OnlinePlay.Components;
using osu.Game.Screens.OnlinePlay.Match.Components;
using osu.Game.Screens.OnlinePlay.Playlists;
@ -221,10 +225,26 @@ namespace osu.Game.Tests.Visual.Playlists
public new Bindable<WorkingBeatmap> Beatmap => base.Beatmap;
[Resolved(canBeNull: true)]
[CanBeNull]
private IDialogOverlay dialogOverlay { get; set; }
public TestPlaylistsRoomSubScreen(Room room)
: base(room)
{
}
public override bool OnExiting(ScreenExitEvent e)
{
// For testing purposes allow the screen to exit without confirming on second attempt.
if (!ExitConfirmed && dialogOverlay?.CurrentDialog is ConfirmDiscardChangesDialog confirmDialog)
{
confirmDialog.PerformAction<PopupDialogDangerousButton>();
return true;
}
return base.OnExiting(e);
}
}
}
}