mirror of
https://github.com/ppy/osu.git
synced 2025-03-05 12:32:58 +08:00
Improve and refactor LoginPanel
test scene to use LoginOverlay
This commit is contained in:
parent
f87ac3f405
commit
25c9bf4061
89
osu.Game.Tests/Visual/Menus/TestSceneLoginOverlay.cs
Normal file
89
osu.Game.Tests/Visual/Menus/TestSceneLoginOverlay.cs
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
// 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.Linq;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Testing;
|
||||||
|
using osu.Game.Graphics.UserInterface;
|
||||||
|
using osu.Game.Online.API;
|
||||||
|
using osu.Game.Overlays;
|
||||||
|
using osu.Game.Users.Drawables;
|
||||||
|
using osuTK.Input;
|
||||||
|
|
||||||
|
namespace osu.Game.Tests.Visual.Menus
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public partial class TestSceneLoginOverlay : OsuManualInputManagerTestScene
|
||||||
|
{
|
||||||
|
private LoginOverlay loginOverlay = null!;
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load()
|
||||||
|
{
|
||||||
|
Child = loginOverlay = new LoginOverlay
|
||||||
|
{
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
[SetUpSteps]
|
||||||
|
public void SetUpSteps()
|
||||||
|
{
|
||||||
|
AddStep("show login overlay", () => loginOverlay.Show());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestLoginSuccess()
|
||||||
|
{
|
||||||
|
AddStep("logout", () => API.Logout());
|
||||||
|
|
||||||
|
AddStep("enter password", () => loginOverlay.ChildrenOfType<OsuPasswordTextBox>().First().Text = "password");
|
||||||
|
AddStep("submit", () => loginOverlay.ChildrenOfType<OsuButton>().First(b => b.Text.ToString() == "Sign in").TriggerClick());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestLoginFailure()
|
||||||
|
{
|
||||||
|
AddStep("logout", () =>
|
||||||
|
{
|
||||||
|
API.Logout();
|
||||||
|
((DummyAPIAccess)API).FailNextLogin();
|
||||||
|
});
|
||||||
|
|
||||||
|
AddStep("enter password", () => loginOverlay.ChildrenOfType<OsuPasswordTextBox>().First().Text = "password");
|
||||||
|
AddStep("submit", () => loginOverlay.ChildrenOfType<OsuButton>().First(b => b.Text.ToString() == "Sign in").TriggerClick());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestLoginConnecting()
|
||||||
|
{
|
||||||
|
AddStep("logout", () =>
|
||||||
|
{
|
||||||
|
API.Logout();
|
||||||
|
((DummyAPIAccess)API).StayConnectingNextLogin();
|
||||||
|
});
|
||||||
|
|
||||||
|
AddStep("enter password", () => loginOverlay.ChildrenOfType<OsuPasswordTextBox>().First().Text = "password");
|
||||||
|
AddStep("submit", () => loginOverlay.ChildrenOfType<OsuButton>().First(b => b.Text.ToString() == "Sign in").TriggerClick());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestClickingOnFlagClosesOverlay()
|
||||||
|
{
|
||||||
|
AddStep("logout", () => API.Logout());
|
||||||
|
AddStep("enter password", () => loginOverlay.ChildrenOfType<OsuPasswordTextBox>().First().Text = "password");
|
||||||
|
AddStep("submit", () => loginOverlay.ChildrenOfType<OsuButton>().First(b => b.Text.ToString() == "Sign in").TriggerClick());
|
||||||
|
|
||||||
|
AddStep("click on flag", () =>
|
||||||
|
{
|
||||||
|
InputManager.MoveMouseTo(loginOverlay.ChildrenOfType<UpdateableFlag>().First());
|
||||||
|
InputManager.Click(MouseButton.Left);
|
||||||
|
});
|
||||||
|
AddAssert("login overlay is hidden", () => loginOverlay.State.Value == Visibility.Hidden);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,78 +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.
|
|
||||||
|
|
||||||
#nullable disable
|
|
||||||
|
|
||||||
using System.Linq;
|
|
||||||
using NUnit.Framework;
|
|
||||||
using osu.Framework.Graphics;
|
|
||||||
using osu.Framework.Testing;
|
|
||||||
using osu.Game.Graphics.UserInterface;
|
|
||||||
using osu.Game.Online.API;
|
|
||||||
using osu.Game.Overlays.Login;
|
|
||||||
using osu.Game.Users.Drawables;
|
|
||||||
using osuTK.Input;
|
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual.Menus
|
|
||||||
{
|
|
||||||
[TestFixture]
|
|
||||||
public partial class TestSceneLoginPanel : OsuManualInputManagerTestScene
|
|
||||||
{
|
|
||||||
private LoginPanel loginPanel;
|
|
||||||
private int hideCount;
|
|
||||||
|
|
||||||
[SetUpSteps]
|
|
||||||
public void SetUpSteps()
|
|
||||||
{
|
|
||||||
AddStep("create login dialog", () =>
|
|
||||||
{
|
|
||||||
Add(loginPanel = new LoginPanel
|
|
||||||
{
|
|
||||||
Anchor = Anchor.Centre,
|
|
||||||
Origin = Anchor.Centre,
|
|
||||||
Width = 0.5f,
|
|
||||||
RequestHide = () => hideCount++,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void TestLoginSuccess()
|
|
||||||
{
|
|
||||||
AddStep("logout", () => API.Logout());
|
|
||||||
|
|
||||||
AddStep("enter password", () => loginPanel.ChildrenOfType<OsuPasswordTextBox>().First().Text = "password");
|
|
||||||
AddStep("submit", () => loginPanel.ChildrenOfType<OsuButton>().First(b => b.Text.ToString() == "Sign in").TriggerClick());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void TestLoginFailure()
|
|
||||||
{
|
|
||||||
AddStep("logout", () =>
|
|
||||||
{
|
|
||||||
API.Logout();
|
|
||||||
((DummyAPIAccess)API).FailNextLogin();
|
|
||||||
});
|
|
||||||
|
|
||||||
AddStep("enter password", () => loginPanel.ChildrenOfType<OsuPasswordTextBox>().First().Text = "password");
|
|
||||||
AddStep("submit", () => loginPanel.ChildrenOfType<OsuButton>().First(b => b.Text.ToString() == "Sign in").TriggerClick());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void TestClickingOnFlagClosesPanel()
|
|
||||||
{
|
|
||||||
AddStep("reset hide count", () => hideCount = 0);
|
|
||||||
|
|
||||||
AddStep("logout", () => API.Logout());
|
|
||||||
AddStep("enter password", () => loginPanel.ChildrenOfType<OsuPasswordTextBox>().First().Text = "password");
|
|
||||||
AddStep("submit", () => loginPanel.ChildrenOfType<OsuButton>().First(b => b.Text.ToString() == "Sign in").TriggerClick());
|
|
||||||
|
|
||||||
AddStep("click on flag", () =>
|
|
||||||
{
|
|
||||||
InputManager.MoveMouseTo(loginPanel.ChildrenOfType<UpdateableFlag>().First());
|
|
||||||
InputManager.Click(MouseButton.Left);
|
|
||||||
});
|
|
||||||
AddAssert("hide requested", () => hideCount == 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -56,6 +56,7 @@ namespace osu.Game.Online.API
|
|||||||
private readonly Bindable<APIState> state = new Bindable<APIState>(APIState.Online);
|
private readonly Bindable<APIState> state = new Bindable<APIState>(APIState.Online);
|
||||||
|
|
||||||
private bool shouldFailNextLogin;
|
private bool shouldFailNextLogin;
|
||||||
|
private bool stayConnectingNextLogin;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The current connectivity state of the API.
|
/// The current connectivity state of the API.
|
||||||
@ -94,6 +95,12 @@ namespace osu.Game.Online.API
|
|||||||
{
|
{
|
||||||
state.Value = APIState.Connecting;
|
state.Value = APIState.Connecting;
|
||||||
|
|
||||||
|
if (stayConnectingNextLogin)
|
||||||
|
{
|
||||||
|
stayConnectingNextLogin = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (shouldFailNextLogin)
|
if (shouldFailNextLogin)
|
||||||
{
|
{
|
||||||
LastLoginError = new APIException("Not powerful enough to login.", new ArgumentException(nameof(shouldFailNextLogin)));
|
LastLoginError = new APIException("Not powerful enough to login.", new ArgumentException(nameof(shouldFailNextLogin)));
|
||||||
@ -138,6 +145,7 @@ namespace osu.Game.Online.API
|
|||||||
IBindable<UserActivity> IAPIProvider.Activity => Activity;
|
IBindable<UserActivity> IAPIProvider.Activity => Activity;
|
||||||
|
|
||||||
public void FailNextLogin() => shouldFailNextLogin = true;
|
public void FailNextLogin() => shouldFailNextLogin = true;
|
||||||
|
public void StayConnectingNextLogin() => stayConnectingNextLogin = true;
|
||||||
|
|
||||||
protected override void Dispose(bool isDisposing)
|
protected override void Dispose(bool isDisposing)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user