mirror of
https://github.com/osukey/osukey.git
synced 2025-07-01 16:29:58 +09:00
Add test coverage
This commit is contained in:
@ -1,6 +1,8 @@
|
|||||||
// 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;
|
||||||
|
using System.Collections.Generic;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Configuration;
|
using osu.Framework.Configuration;
|
||||||
@ -76,6 +78,13 @@ namespace osu.Game.Tests.Visual.Navigation
|
|||||||
ConfirmAtMainMenu();
|
ConfirmAtMainMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void PushAndConfirm(Func<Screen> newScreen)
|
||||||
|
{
|
||||||
|
Screen screen = null;
|
||||||
|
AddStep("Push new screen", () => Game.ScreenStack.Push(screen = newScreen()));
|
||||||
|
AddUntilStep("Wait for new screen", () => Game.ScreenStack.CurrentScreen == screen && screen.IsLoaded);
|
||||||
|
}
|
||||||
|
|
||||||
protected void ConfirmAtMainMenu() => AddUntilStep("Wait for main menu", () => Game.ScreenStack.CurrentScreen is MainMenu menu && menu.IsLoaded);
|
protected void ConfirmAtMainMenu() => AddUntilStep("Wait for main menu", () => Game.ScreenStack.CurrentScreen is MainMenu menu && menu.IsLoaded);
|
||||||
|
|
||||||
public class TestOsuGame : OsuGame
|
public class TestOsuGame : OsuGame
|
||||||
@ -96,6 +105,8 @@ namespace osu.Game.Tests.Visual.Navigation
|
|||||||
|
|
||||||
protected override Loader CreateLoader() => new TestLoader();
|
protected override Loader CreateLoader() => new TestLoader();
|
||||||
|
|
||||||
|
public new void PerformFromScreen(Action<IScreen> action, IEnumerable<Type> validScreens = null) => base.PerformFromScreen(action, validScreens);
|
||||||
|
|
||||||
public TestOsuGame(Storage storage, IAPIProvider api)
|
public TestOsuGame(Storage storage, IAPIProvider api)
|
||||||
{
|
{
|
||||||
Storage = storage;
|
Storage = storage;
|
||||||
|
@ -0,0 +1,72 @@
|
|||||||
|
// 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 NUnit.Framework;
|
||||||
|
using osu.Game.Screens.Menu;
|
||||||
|
using osu.Game.Screens.Play;
|
||||||
|
using osu.Game.Screens.Select;
|
||||||
|
|
||||||
|
namespace osu.Game.Tests.Visual.Navigation
|
||||||
|
{
|
||||||
|
public class TestScenePerformFromScreen : OsuGameTestScene
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void TestPerformAtMenu()
|
||||||
|
{
|
||||||
|
AddAssert("could perform immediately", () =>
|
||||||
|
{
|
||||||
|
bool actionPerformed = false;
|
||||||
|
Game.PerformFromScreen(_ => actionPerformed = true);
|
||||||
|
return actionPerformed;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestPerformAtSongSelect()
|
||||||
|
{
|
||||||
|
PushAndConfirm(() => new PlaySongSelect());
|
||||||
|
|
||||||
|
AddAssert("could perform immediately", () =>
|
||||||
|
{
|
||||||
|
bool actionPerformed = false;
|
||||||
|
Game.PerformFromScreen(_ => actionPerformed = true, new[] { typeof(PlaySongSelect) });
|
||||||
|
return actionPerformed;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestPerformAtMenuFromSongSelect()
|
||||||
|
{
|
||||||
|
PushAndConfirm(() => new PlaySongSelect());
|
||||||
|
|
||||||
|
bool actionPerformed = false;
|
||||||
|
AddStep("try to perform", () => Game.PerformFromScreen(_ => actionPerformed = true));
|
||||||
|
AddUntilStep("returned to menu", () => Game.ScreenStack.CurrentScreen is MainMenu);
|
||||||
|
AddAssert("did perform", () => actionPerformed);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestPerformAtSongSelectFromPlayerLoader()
|
||||||
|
{
|
||||||
|
PushAndConfirm(() => new PlaySongSelect());
|
||||||
|
PushAndConfirm(() => new PlayerLoader(() => new Player()));
|
||||||
|
|
||||||
|
bool actionPerformed = false;
|
||||||
|
AddStep("try to perform", () => Game.PerformFromScreen(_ => actionPerformed = true, new[] { typeof(PlaySongSelect) }));
|
||||||
|
AddUntilStep("returned to song select", () => Game.ScreenStack.CurrentScreen is PlaySongSelect);
|
||||||
|
AddAssert("did perform", () => actionPerformed);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestPerformAtMenuFromPlayerLoader()
|
||||||
|
{
|
||||||
|
PushAndConfirm(() => new PlaySongSelect());
|
||||||
|
PushAndConfirm(() => new PlayerLoader(() => new Player()));
|
||||||
|
|
||||||
|
bool actionPerformed = false;
|
||||||
|
AddStep("try to perform", () => Game.PerformFromScreen(_ => actionPerformed = true));
|
||||||
|
AddUntilStep("returned to song select", () => Game.ScreenStack.CurrentScreen is MainMenu);
|
||||||
|
AddAssert("did perform", () => actionPerformed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,13 +1,11 @@
|
|||||||
// 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;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Audio.Track;
|
using osu.Framework.Audio.Track;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Screens;
|
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Overlays;
|
using osu.Game.Overlays;
|
||||||
using osu.Game.Overlays.Mods;
|
using osu.Game.Overlays.Mods;
|
||||||
@ -32,7 +30,7 @@ namespace osu.Game.Tests.Visual.Navigation
|
|||||||
{
|
{
|
||||||
TestSongSelect songSelect = null;
|
TestSongSelect songSelect = null;
|
||||||
|
|
||||||
pushAndConfirm(() => songSelect = new TestSongSelect());
|
PushAndConfirm(() => songSelect = new TestSongSelect());
|
||||||
AddStep("Show mods overlay", () => songSelect.ModSelectOverlay.Show());
|
AddStep("Show mods overlay", () => songSelect.ModSelectOverlay.Show());
|
||||||
AddAssert("Overlay was shown", () => songSelect.ModSelectOverlay.State.Value == Visibility.Visible);
|
AddAssert("Overlay was shown", () => songSelect.ModSelectOverlay.State.Value == Visibility.Visible);
|
||||||
pushEscape();
|
pushEscape();
|
||||||
@ -49,7 +47,7 @@ namespace osu.Game.Tests.Visual.Navigation
|
|||||||
WorkingBeatmap beatmap() => Game.Beatmap.Value;
|
WorkingBeatmap beatmap() => Game.Beatmap.Value;
|
||||||
Track track() => beatmap().Track;
|
Track track() => beatmap().Track;
|
||||||
|
|
||||||
pushAndConfirm(() => new TestSongSelect());
|
PushAndConfirm(() => new TestSongSelect());
|
||||||
|
|
||||||
AddStep("import beatmap", () => ImportBeatmapTest.LoadOszIntoOsu(Game, virtualTrack: true).Wait());
|
AddStep("import beatmap", () => ImportBeatmapTest.LoadOszIntoOsu(Game, virtualTrack: true).Wait());
|
||||||
|
|
||||||
@ -77,7 +75,7 @@ namespace osu.Game.Tests.Visual.Navigation
|
|||||||
{
|
{
|
||||||
TestSongSelect songSelect = null;
|
TestSongSelect songSelect = null;
|
||||||
|
|
||||||
pushAndConfirm(() => songSelect = new TestSongSelect());
|
PushAndConfirm(() => songSelect = new TestSongSelect());
|
||||||
AddStep("Show mods overlay", () => songSelect.ModSelectOverlay.Show());
|
AddStep("Show mods overlay", () => songSelect.ModSelectOverlay.Show());
|
||||||
AddAssert("Overlay was shown", () => songSelect.ModSelectOverlay.State.Value == Visibility.Visible);
|
AddAssert("Overlay was shown", () => songSelect.ModSelectOverlay.State.Value == Visibility.Visible);
|
||||||
AddStep("Move mouse to backButton", () => InputManager.MoveMouseTo(backButtonPosition));
|
AddStep("Move mouse to backButton", () => InputManager.MoveMouseTo(backButtonPosition));
|
||||||
@ -93,14 +91,14 @@ namespace osu.Game.Tests.Visual.Navigation
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestExitMultiWithEscape()
|
public void TestExitMultiWithEscape()
|
||||||
{
|
{
|
||||||
pushAndConfirm(() => new Screens.Multi.Multiplayer());
|
PushAndConfirm(() => new Screens.Multi.Multiplayer());
|
||||||
exitViaEscapeAndConfirm();
|
exitViaEscapeAndConfirm();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestExitMultiWithBackButton()
|
public void TestExitMultiWithBackButton()
|
||||||
{
|
{
|
||||||
pushAndConfirm(() => new Screens.Multi.Multiplayer());
|
PushAndConfirm(() => new Screens.Multi.Multiplayer());
|
||||||
exitViaBackButtonAndConfirm();
|
exitViaBackButtonAndConfirm();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,13 +114,6 @@ namespace osu.Game.Tests.Visual.Navigation
|
|||||||
AddAssert("Options overlay was closed", () => Game.Settings.State.Value == Visibility.Hidden);
|
AddAssert("Options overlay was closed", () => Game.Settings.State.Value == Visibility.Hidden);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void pushAndConfirm(Func<Screen> newScreen)
|
|
||||||
{
|
|
||||||
Screen screen = null;
|
|
||||||
AddStep("Push new screen", () => Game.ScreenStack.Push(screen = newScreen()));
|
|
||||||
AddUntilStep("Wait for new screen", () => Game.ScreenStack.CurrentScreen == screen && screen.IsLoaded);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void pushEscape() =>
|
private void pushEscape() =>
|
||||||
AddStep("Press escape", () => pressAndRelease(Key.Escape));
|
AddStep("Press escape", () => pressAndRelease(Key.Escape));
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user