mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 20:22:55 +08:00
Add test coverage of navigation
This commit is contained in:
parent
07da1cd731
commit
288f759bb4
@ -1,20 +0,0 @@
|
||||
// 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.Overlays;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Navigation
|
||||
{
|
||||
public class TestFirstRunSetup : OsuTestScene
|
||||
{
|
||||
[Test]
|
||||
public void TestOverlay()
|
||||
{
|
||||
AddStep("add overlay", () =>
|
||||
{
|
||||
Child = new FirstRunSetupOverlay();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
// 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.Framework.Graphics.Containers;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Game.Overlays.FirstRunSetup;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Navigation
|
||||
{
|
||||
public class TestSceneFirstRunSetupOverlay : OsuTestScene
|
||||
{
|
||||
private FirstRunSetupOverlay overlay;
|
||||
|
||||
[SetUpSteps]
|
||||
public void SetUpSteps()
|
||||
{
|
||||
AddStep("add overlay", () =>
|
||||
{
|
||||
Child = overlay = new FirstRunSetupOverlay();
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestOverlayRunsToFinish()
|
||||
{
|
||||
AddUntilStep("step through", () =>
|
||||
{
|
||||
if (overlay.CurrentScreen?.IsLoaded != false)
|
||||
overlay.NextButton.TriggerClick();
|
||||
|
||||
return overlay.State.Value == Visibility.Hidden;
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestBackButton()
|
||||
{
|
||||
AddAssert("back button disabled", () => !overlay.BackButton.Enabled.Value);
|
||||
|
||||
AddUntilStep("step to last", () =>
|
||||
{
|
||||
var nextButton = overlay.NextButton;
|
||||
|
||||
if (overlay.CurrentScreen?.IsLoaded != false)
|
||||
nextButton.TriggerClick();
|
||||
|
||||
return nextButton.Text.ToString() == "Finish";
|
||||
});
|
||||
|
||||
AddUntilStep("step back to start", () =>
|
||||
{
|
||||
if (overlay.CurrentScreen?.IsLoaded != false)
|
||||
overlay.BackButton.TriggerClick();
|
||||
|
||||
return overlay.CurrentScreen is ScreenWelcome;
|
||||
});
|
||||
|
||||
AddAssert("back button disabled", () => !overlay.BackButton.Enabled.Value);
|
||||
}
|
||||
}
|
||||
}
|
@ -41,14 +41,19 @@ namespace osu.Game.Overlays
|
||||
|
||||
private ScreenStack stack = null!;
|
||||
|
||||
private PurpleTriangleButton nextButton = null!;
|
||||
private DangerousTriangleButton backButton = null!;
|
||||
public PurpleTriangleButton NextButton = null!;
|
||||
public DangerousTriangleButton BackButton = null!;
|
||||
|
||||
[Cached]
|
||||
private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Purple);
|
||||
|
||||
private int? currentStepIndex;
|
||||
|
||||
/// <summary>
|
||||
/// The currently displayed screen, if any.
|
||||
/// </summary>
|
||||
public FirstRunSetupScreen? CurrentScreen => (FirstRunSetupScreen?)stack.CurrentScreen;
|
||||
|
||||
private readonly FirstRunStep[] steps =
|
||||
{
|
||||
new FirstRunStep(typeof(ScreenWelcome), "Welcome"),
|
||||
@ -176,7 +181,7 @@ namespace osu.Game.Overlays
|
||||
{
|
||||
new[]
|
||||
{
|
||||
backButton = new DangerousTriangleButton
|
||||
BackButton = new DangerousTriangleButton
|
||||
{
|
||||
Width = 200,
|
||||
Text = "Back",
|
||||
@ -184,7 +189,7 @@ namespace osu.Game.Overlays
|
||||
Enabled = { Value = false },
|
||||
},
|
||||
Empty(),
|
||||
nextButton = new PurpleTriangleButton
|
||||
NextButton = new PurpleTriangleButton
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Width = 1,
|
||||
@ -249,7 +254,7 @@ namespace osu.Game.Overlays
|
||||
stack.CurrentScreen.Exit();
|
||||
currentStepIndex--;
|
||||
|
||||
backButton.Enabled.Value = currentStepIndex != 0;
|
||||
BackButton.Enabled.Value = currentStepIndex != 0;
|
||||
}
|
||||
|
||||
private void showNextStep()
|
||||
@ -260,7 +265,7 @@ namespace osu.Game.Overlays
|
||||
currentStepIndex++;
|
||||
|
||||
Debug.Assert(currentStepIndex != null);
|
||||
backButton.Enabled.Value = currentStepIndex > 0;
|
||||
BackButton.Enabled.Value = currentStepIndex > 0;
|
||||
|
||||
if (currentStepIndex < steps.Length)
|
||||
{
|
||||
@ -272,7 +277,7 @@ namespace osu.Game.Overlays
|
||||
Hide();
|
||||
}
|
||||
|
||||
nextButton.Text = currentStepIndex + 1 < steps.Length
|
||||
NextButton.Text = currentStepIndex + 1 < steps.Length
|
||||
? $"Next ({steps[currentStepIndex.Value + 1].Description})"
|
||||
: "Finish";
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user