2022-04-18 17:58:14 +08: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.
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
2022-04-18 18:41:07 +08:00
|
|
|
using System.Linq;
|
2022-04-18 17:58:14 +08:00
|
|
|
using Moq;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Screens;
|
|
|
|
using osu.Framework.Testing;
|
2022-04-19 16:08:38 +08:00
|
|
|
using osu.Game.Configuration;
|
2022-04-20 13:51:16 +08:00
|
|
|
using osu.Game.Localisation;
|
2022-04-18 17:58:14 +08:00
|
|
|
using osu.Game.Overlays;
|
|
|
|
using osu.Game.Overlays.FirstRunSetup;
|
2022-04-18 22:37:08 +08:00
|
|
|
using osu.Game.Overlays.Notifications;
|
2022-04-18 17:58:14 +08:00
|
|
|
using osu.Game.Screens;
|
|
|
|
using osuTK;
|
|
|
|
using osuTK.Input;
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.UserInterface
|
|
|
|
{
|
|
|
|
public class TestSceneFirstRunSetupOverlay : OsuManualInputManagerTestScene
|
|
|
|
{
|
|
|
|
private FirstRunSetupOverlay overlay;
|
|
|
|
|
2022-04-18 22:37:08 +08:00
|
|
|
private readonly Mock<IPerformFromScreenRunner> performer = new Mock<IPerformFromScreenRunner>();
|
|
|
|
|
|
|
|
private readonly Mock<INotificationOverlay> notificationOverlay = new Mock<INotificationOverlay>();
|
|
|
|
|
|
|
|
private Notification lastNotification;
|
2022-04-18 17:58:14 +08:00
|
|
|
|
2022-04-19 16:08:38 +08:00
|
|
|
protected OsuConfigManager LocalConfig;
|
|
|
|
|
2022-04-18 17:58:14 +08:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
2022-04-19 16:08:38 +08:00
|
|
|
Dependencies.Cache(LocalConfig = new OsuConfigManager(LocalStorage));
|
2022-04-18 22:37:08 +08:00
|
|
|
Dependencies.CacheAs(performer.Object);
|
|
|
|
Dependencies.CacheAs(notificationOverlay.Object);
|
2022-04-18 17:58:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[SetUpSteps]
|
|
|
|
public void SetUpSteps()
|
|
|
|
{
|
2022-04-18 22:37:08 +08:00
|
|
|
AddStep("setup dependencies", () =>
|
|
|
|
{
|
|
|
|
performer.Reset();
|
|
|
|
notificationOverlay.Reset();
|
|
|
|
|
|
|
|
performer.Setup(g => g.PerformFromScreen(It.IsAny<Action<IScreen>>(), It.IsAny<IEnumerable<Type>>()))
|
|
|
|
.Callback((Action<IScreen> action, IEnumerable<Type> types) => action(null));
|
|
|
|
|
|
|
|
notificationOverlay.Setup(n => n.Post(It.IsAny<Notification>()))
|
|
|
|
.Callback((Notification n) => lastNotification = n);
|
|
|
|
});
|
|
|
|
|
2022-04-18 17:58:14 +08:00
|
|
|
AddStep("add overlay", () =>
|
|
|
|
{
|
|
|
|
Child = overlay = new FirstRunSetupOverlay
|
|
|
|
{
|
|
|
|
State = { Value = Visibility.Visible }
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-04-19 16:08:38 +08:00
|
|
|
[Test]
|
2022-04-24 15:35:41 +08:00
|
|
|
[Ignore("Enable when first run setup is being displayed on first run.")]
|
2022-04-19 16:08:38 +08:00
|
|
|
public void TestDoesntOpenOnSecondRun()
|
|
|
|
{
|
|
|
|
AddStep("set first run", () => LocalConfig.SetValue(OsuSetting.ShowFirstRunSetup, true));
|
|
|
|
|
|
|
|
AddUntilStep("step through", () =>
|
|
|
|
{
|
|
|
|
if (overlay.CurrentScreen?.IsLoaded != false) overlay.NextButton.TriggerClick();
|
|
|
|
return overlay.State.Value == Visibility.Hidden;
|
|
|
|
});
|
|
|
|
|
|
|
|
AddAssert("first run false", () => !LocalConfig.Get<bool>(OsuSetting.ShowFirstRunSetup));
|
|
|
|
|
|
|
|
AddStep("add overlay", () =>
|
|
|
|
{
|
|
|
|
Child = overlay = new FirstRunSetupOverlay();
|
|
|
|
});
|
|
|
|
|
|
|
|
AddWaitStep("wait some", 5);
|
|
|
|
|
|
|
|
AddAssert("overlay didn't show", () => overlay.State.Value == Visibility.Hidden);
|
|
|
|
}
|
|
|
|
|
2022-04-19 13:46:01 +08:00
|
|
|
[TestCase(false)]
|
|
|
|
[TestCase(true)]
|
|
|
|
public void TestOverlayRunsToFinish(bool keyboard)
|
2022-04-18 17:58:14 +08:00
|
|
|
{
|
|
|
|
AddUntilStep("step through", () =>
|
|
|
|
{
|
|
|
|
if (overlay.CurrentScreen?.IsLoaded != false)
|
2022-04-19 13:46:01 +08:00
|
|
|
{
|
|
|
|
if (keyboard)
|
|
|
|
InputManager.Key(Key.Enter);
|
|
|
|
else
|
|
|
|
overlay.NextButton.TriggerClick();
|
|
|
|
}
|
2022-04-18 17:58:14 +08:00
|
|
|
|
|
|
|
return overlay.State.Value == Visibility.Hidden;
|
|
|
|
});
|
2022-04-18 18:08:34 +08:00
|
|
|
|
2022-04-18 18:41:07 +08:00
|
|
|
AddUntilStep("wait for screens removed", () => !overlay.ChildrenOfType<Screen>().Any());
|
|
|
|
|
2022-04-18 22:37:08 +08:00
|
|
|
AddStep("no notifications", () => notificationOverlay.VerifyNoOtherCalls());
|
|
|
|
|
2022-04-18 18:08:34 +08:00
|
|
|
AddStep("display again on demand", () => overlay.Show());
|
|
|
|
|
|
|
|
AddUntilStep("back at start", () => overlay.CurrentScreen is ScreenWelcome);
|
2022-04-18 17:58:14 +08:00
|
|
|
}
|
|
|
|
|
2022-04-19 13:46:01 +08:00
|
|
|
[TestCase(false)]
|
|
|
|
[TestCase(true)]
|
|
|
|
public void TestBackButton(bool keyboard)
|
2022-04-18 17:58:14 +08:00
|
|
|
{
|
|
|
|
AddAssert("back button disabled", () => !overlay.BackButton.Enabled.Value);
|
|
|
|
|
|
|
|
AddUntilStep("step to last", () =>
|
|
|
|
{
|
|
|
|
var nextButton = overlay.NextButton;
|
|
|
|
|
|
|
|
if (overlay.CurrentScreen?.IsLoaded != false)
|
|
|
|
nextButton.TriggerClick();
|
|
|
|
|
2022-04-20 16:51:08 +08:00
|
|
|
return nextButton.Text == CommonStrings.Finish;
|
2022-04-18 17:58:14 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
AddUntilStep("step back to start", () =>
|
|
|
|
{
|
|
|
|
if (overlay.CurrentScreen?.IsLoaded != false)
|
2022-04-19 13:46:01 +08:00
|
|
|
{
|
|
|
|
if (keyboard)
|
|
|
|
InputManager.Key(Key.Escape);
|
|
|
|
else
|
|
|
|
overlay.BackButton.TriggerClick();
|
|
|
|
}
|
2022-04-18 17:58:14 +08:00
|
|
|
|
|
|
|
return overlay.CurrentScreen is ScreenWelcome;
|
|
|
|
});
|
|
|
|
|
|
|
|
AddAssert("back button disabled", () => !overlay.BackButton.Enabled.Value);
|
2022-04-19 13:46:01 +08:00
|
|
|
|
|
|
|
if (keyboard)
|
|
|
|
{
|
|
|
|
AddStep("exit via keyboard", () => InputManager.Key(Key.Escape));
|
|
|
|
AddAssert("overlay dismissed", () => overlay.State.Value == Visibility.Hidden);
|
|
|
|
}
|
2022-04-18 17:58:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestClickAwayToExit()
|
|
|
|
{
|
|
|
|
AddStep("click inside content", () =>
|
|
|
|
{
|
|
|
|
InputManager.MoveMouseTo(overlay.ScreenSpaceDrawQuad.Centre);
|
|
|
|
InputManager.Click(MouseButton.Left);
|
|
|
|
});
|
|
|
|
|
|
|
|
AddAssert("overlay not dismissed", () => overlay.State.Value == Visibility.Visible);
|
|
|
|
|
|
|
|
AddStep("click outside content", () =>
|
|
|
|
{
|
2022-04-20 15:51:26 +08:00
|
|
|
InputManager.MoveMouseTo(new Vector2(overlay.ScreenSpaceDrawQuad.TopLeft.X, overlay.ScreenSpaceDrawQuad.Centre.Y));
|
2022-04-18 17:58:14 +08:00
|
|
|
InputManager.Click(MouseButton.Left);
|
|
|
|
});
|
|
|
|
|
|
|
|
AddAssert("overlay dismissed", () => overlay.State.Value == Visibility.Hidden);
|
|
|
|
}
|
2022-04-18 22:37:08 +08:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestResumeViaNotification()
|
|
|
|
{
|
|
|
|
AddStep("step to next", () => overlay.NextButton.TriggerClick());
|
|
|
|
|
|
|
|
AddAssert("is at known screen", () => overlay.CurrentScreen is ScreenUIScale);
|
|
|
|
|
|
|
|
AddStep("hide", () => overlay.Hide());
|
|
|
|
AddAssert("overlay hidden", () => overlay.State.Value == Visibility.Hidden);
|
|
|
|
|
|
|
|
AddStep("notification arrived", () => notificationOverlay.Verify(n => n.Post(It.IsAny<Notification>()), Times.Once));
|
|
|
|
|
|
|
|
AddStep("run notification action", () => lastNotification.Activated());
|
|
|
|
|
|
|
|
AddAssert("overlay shown", () => overlay.State.Value == Visibility.Visible);
|
|
|
|
AddAssert("is resumed", () => overlay.CurrentScreen is ScreenUIScale);
|
|
|
|
}
|
2022-04-18 17:58:14 +08:00
|
|
|
}
|
|
|
|
}
|