mirror of
https://github.com/ppy/osu.git
synced 2025-01-27 13:23:05 +08:00
Add test coverage of external editing
This commit is contained in:
parent
72091b43df
commit
aa16c72e06
@ -1,6 +1,7 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Framework.Extensions;
|
using osu.Framework.Extensions;
|
||||||
@ -13,6 +14,7 @@ using osu.Framework.Testing;
|
|||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Configuration;
|
using osu.Game.Configuration;
|
||||||
using osu.Game.Database;
|
using osu.Game.Database;
|
||||||
|
using osu.Game.Graphics.UserInterface;
|
||||||
using osu.Game.Overlays;
|
using osu.Game.Overlays;
|
||||||
using osu.Game.Rulesets.Mania;
|
using osu.Game.Rulesets.Mania;
|
||||||
using osu.Game.Rulesets.Osu;
|
using osu.Game.Rulesets.Osu;
|
||||||
@ -31,6 +33,54 @@ namespace osu.Game.Tests.Visual.Navigation
|
|||||||
{
|
{
|
||||||
private BeatmapSetInfo beatmapSet = null!;
|
private BeatmapSetInfo beatmapSet = null!;
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestExternalEditingNoChange()
|
||||||
|
{
|
||||||
|
prepareBeatmap();
|
||||||
|
openEditor();
|
||||||
|
|
||||||
|
AddStep("open file menu", () => getEditor().ChildrenOfType<Menu.DrawableMenuItem>().Single(m => m.Item.Text.Value.ToString() == "File").TriggerClick());
|
||||||
|
AddStep("click external edit", () => getEditor().ChildrenOfType<Menu.DrawableMenuItem>().Single(m => m.Item.Text.Value.ToString() == "Edit externally").TriggerClick());
|
||||||
|
|
||||||
|
AddUntilStep("wait for external edit screen", () => Game.ScreenStack.CurrentScreen is ExternalEditScreen externalEditScreen && externalEditScreen.IsLoaded);
|
||||||
|
|
||||||
|
AddUntilStep("wait for button ready", () => ((ExternalEditScreen)Game.ScreenStack.CurrentScreen).ChildrenOfType<DangerousRoundedButton>().FirstOrDefault()?.Enabled.Value == true);
|
||||||
|
|
||||||
|
AddStep("finish external edit", () => ((ExternalEditScreen)Game.ScreenStack.CurrentScreen).ChildrenOfType<DangerousRoundedButton>().First().TriggerClick());
|
||||||
|
|
||||||
|
AddUntilStep("wait for editor", () => Game.ScreenStack.CurrentScreen is Editor editor && editor.ReadyForUse);
|
||||||
|
|
||||||
|
AddAssert("beatmap didn't change", () => getEditor().Beatmap.Value.BeatmapSetInfo.Equals(beatmapSet));
|
||||||
|
AddAssert("old beatmapset not deleted", () => Game.BeatmapManager.QueryBeatmapSet(s => s.ID == beatmapSet.ID), () => Is.Not.Null);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestExternalEditingWithChange()
|
||||||
|
{
|
||||||
|
prepareBeatmap();
|
||||||
|
openEditor();
|
||||||
|
|
||||||
|
AddStep("open file menu", () => getEditor().ChildrenOfType<Menu.DrawableMenuItem>().Single(m => m.Item.Text.Value.ToString() == "File").TriggerClick());
|
||||||
|
AddStep("click external edit", () => getEditor().ChildrenOfType<Menu.DrawableMenuItem>().Single(m => m.Item.Text.Value.ToString() == "Edit externally").TriggerClick());
|
||||||
|
|
||||||
|
AddUntilStep("wait for external edit screen", () => Game.ScreenStack.CurrentScreen is ExternalEditScreen externalEditScreen && externalEditScreen.IsLoaded);
|
||||||
|
|
||||||
|
AddUntilStep("wait for button ready", () => ((ExternalEditScreen)Game.ScreenStack.CurrentScreen).ChildrenOfType<DangerousRoundedButton>().FirstOrDefault()?.Enabled.Value == true);
|
||||||
|
|
||||||
|
AddStep("add file externally", () =>
|
||||||
|
{
|
||||||
|
var op = ((ExternalEditScreen)Game.ScreenStack.CurrentScreen).EditOperation!;
|
||||||
|
File.WriteAllText(Path.Combine(op.MountedPath, "test.txt"), "test");
|
||||||
|
});
|
||||||
|
|
||||||
|
AddStep("finish external edit", () => ((ExternalEditScreen)Game.ScreenStack.CurrentScreen).ChildrenOfType<DangerousRoundedButton>().First().TriggerClick());
|
||||||
|
|
||||||
|
AddUntilStep("wait for editor", () => Game.ScreenStack.CurrentScreen is Editor editor && editor.ReadyForUse);
|
||||||
|
|
||||||
|
AddAssert("beatmap changed", () => !getEditor().Beatmap.Value.BeatmapSetInfo.Equals(beatmapSet));
|
||||||
|
AddAssert("old beatmapset deleted", () => Game.BeatmapManager.QueryBeatmapSet(s => s.ID == beatmapSet.ID), () => Is.Null);
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestSaveThenDeleteActuallyDeletesAtSongSelect()
|
public void TestSaveThenDeleteActuallyDeletesAtSongSelect()
|
||||||
{
|
{
|
||||||
|
@ -38,7 +38,7 @@ namespace osu.Game.Screens.Edit
|
|||||||
|
|
||||||
private readonly Editor editor;
|
private readonly Editor editor;
|
||||||
|
|
||||||
private ExternalEditOperation<BeatmapSetInfo>? operation;
|
public ExternalEditOperation<BeatmapSetInfo>? EditOperation;
|
||||||
|
|
||||||
private double timeLoaded;
|
private double timeLoaded;
|
||||||
|
|
||||||
@ -92,7 +92,7 @@ namespace osu.Game.Screens.Edit
|
|||||||
|
|
||||||
fileMountOperation.ContinueWith(t =>
|
fileMountOperation.ContinueWith(t =>
|
||||||
{
|
{
|
||||||
operation = t.GetResultSafely();
|
EditOperation = t.GetResultSafely();
|
||||||
|
|
||||||
Scheduler.AddDelayed(() =>
|
Scheduler.AddDelayed(() =>
|
||||||
{
|
{
|
||||||
@ -146,11 +146,11 @@ namespace osu.Game.Screens.Edit
|
|||||||
|
|
||||||
private void open()
|
private void open()
|
||||||
{
|
{
|
||||||
if (operation == null)
|
if (EditOperation == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Ensure the trailing separator is present in order to show the folder contents.
|
// Ensure the trailing separator is present in order to show the folder contents.
|
||||||
gameHost.OpenFileExternally(operation.MountedPath.TrimDirectorySeparator() + Path.DirectorySeparatorChar);
|
gameHost.OpenFileExternally(EditOperation.MountedPath.TrimDirectorySeparator() + Path.DirectorySeparatorChar);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool OnExiting(ScreenExitEvent e)
|
public override bool OnExiting(ScreenExitEvent e)
|
||||||
@ -158,7 +158,7 @@ namespace osu.Game.Screens.Edit
|
|||||||
if (!fileMountOperation.IsCompleted)
|
if (!fileMountOperation.IsCompleted)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (operation != null)
|
if (EditOperation != null)
|
||||||
{
|
{
|
||||||
finish();
|
finish();
|
||||||
return false;
|
return false;
|
||||||
@ -178,7 +178,7 @@ namespace osu.Game.Screens.Edit
|
|||||||
Schedule(() =>
|
Schedule(() =>
|
||||||
{
|
{
|
||||||
// Setting to null will allow exit to succeed.
|
// Setting to null will allow exit to succeed.
|
||||||
operation = null;
|
EditOperation = null;
|
||||||
|
|
||||||
Live<BeatmapSetInfo>? beatmap = t.GetResultSafely();
|
Live<BeatmapSetInfo>? beatmap = t.GetResultSafely();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user