1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 08:23:00 +08:00

add test for comment when logging in and out

This commit is contained in:
Liam DeVoe 2023-06-21 02:17:51 -04:00
parent dd4f271158
commit 6de7328fef

View File

@ -1,4 +1,4 @@
// 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.
using System.Linq;
@ -11,6 +11,7 @@ using osu.Framework.Graphics.UserInterface;
using osu.Framework.Localisation;
using osu.Framework.Testing;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.API;
using osu.Game.Overlays;
using osu.Game.Overlays.Comments;
using osuTK;
@ -25,6 +26,7 @@ namespace osu.Game.Tests.Visual.UserInterface
private TestCommentEditor commentEditor = null!;
private TestCancellableCommentEditor cancellableCommentEditor = null!;
private DummyAPIAccess dummyAPI => (DummyAPIAccess)API;
[SetUp]
public void SetUp() => Schedule(() =>
@ -96,6 +98,37 @@ namespace osu.Game.Tests.Visual.UserInterface
AddUntilStep("button is not loading", () => !commentEditor.IsSpinnerShown);
}
[Test]
public void TestLoggingInAndOut()
{
void addLoggedInAsserts()
{
AddAssert("commit button visible", () => commentEditor.ButtonsContainer[0].Alpha == 1);
AddAssert("login button hidden", () => commentEditor.ButtonsContainer[1].Alpha == 0);
AddAssert("text box editable", () => !commentEditor.TextBox.ReadOnly);
}
void addLoggedOutAsserts()
{
AddAssert("commit button hidden", () => commentEditor.ButtonsContainer[0].Alpha == 0);
AddAssert("login button visible", () => commentEditor.ButtonsContainer[1].Alpha == 1);
AddAssert("text box readonly", () => commentEditor.TextBox.ReadOnly);
}
// there's also the case of starting logged out, but more annoying to test.
// starting logged in
addLoggedInAsserts();
// moving from logged in -> logged out
AddStep("log out", () => dummyAPI.Logout());
addLoggedOutAsserts();
// moving from logged out -> logged in
AddStep("log back in", () => dummyAPI.Login("username", "password"));
addLoggedInAsserts();
}
[Test]
public void TestCancelAction()
{
@ -112,6 +145,7 @@ namespace osu.Game.Tests.Visual.UserInterface
{
public new Bindable<string> Current => base.Current;
public new FillFlowContainer ButtonsContainer => base.ButtonsContainer;
public new TextBox TextBox => base.TextBox;
public string CommittedText { get; private set; } = string.Empty;
@ -125,8 +159,12 @@ namespace osu.Game.Tests.Visual.UserInterface
}
protected override LocalisableString FooterText => @"Footer text. And it is pretty long. Cool.";
protected override LocalisableString GetCommitButtonText(bool isLoggedIn) => @"Commit";
protected override LocalisableString GetPlaceholderText(bool isLoggedIn) => @"This text box is empty";
protected override LocalisableString GetCommitButtonText(bool isLoggedIn) =>
isLoggedIn ? @"Commit" : "You're logged out!";
protected override LocalisableString GetPlaceholderText(bool isLoggedIn) =>
isLoggedIn ? @"This text box is empty" : "Still empty, but now you can't type in it.";
}
private partial class TestCancellableCommentEditor : CancellableCommentEditor