2019-10-30 08:45:05 +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.
|
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2019-10-30 08:45:05 +08:00
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Game.Overlays.Comments;
|
|
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2020-02-27 00:35:20 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Game.Overlays;
|
2021-01-23 03:49:49 +08:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2021-01-23 02:47:53 +08:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2024-01-24 01:04:41 +08:00
|
|
|
|
using osu.Game.Online.API;
|
2019-10-30 08:45:05 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.Online
|
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
|
|
|
|
public partial class TestSceneVotePill : OsuTestScene
|
|
|
|
|
{
|
2020-02-27 00:35:20 +08:00
|
|
|
|
[Cached]
|
|
|
|
|
private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Blue);
|
|
|
|
|
|
2021-01-23 02:47:53 +08:00
|
|
|
|
[Cached]
|
|
|
|
|
private LoginOverlay login;
|
|
|
|
|
|
2021-01-23 03:49:49 +08:00
|
|
|
|
private TestPill votePill;
|
2021-01-23 02:47:53 +08:00
|
|
|
|
private readonly Container pillContainer;
|
|
|
|
|
|
|
|
|
|
public TestSceneVotePill()
|
|
|
|
|
{
|
|
|
|
|
AddRange(new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
pillContainer = new Container
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
AutoSizeAxes = Axes.Both
|
|
|
|
|
},
|
|
|
|
|
login = new LoginOverlay()
|
|
|
|
|
});
|
|
|
|
|
}
|
2019-10-30 08:45:05 +08:00
|
|
|
|
|
2019-11-06 17:54:04 +08:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestUserCommentPill()
|
2019-10-30 08:45:05 +08:00
|
|
|
|
{
|
2021-01-23 02:47:53 +08:00
|
|
|
|
AddStep("Hide login overlay", () => login.Hide());
|
2019-11-06 23:32:09 +08:00
|
|
|
|
AddStep("Log in", logIn);
|
2019-10-31 07:10:00 +08:00
|
|
|
|
AddStep("User comment", () => addVotePill(getUserComment()));
|
2021-01-23 03:49:49 +08:00
|
|
|
|
AddAssert("Background is transparent", () => votePill.Background.Alpha == 0);
|
2021-08-04 16:27:44 +08:00
|
|
|
|
AddStep("Click", () => votePill.TriggerClick());
|
2019-10-30 09:31:09 +08:00
|
|
|
|
AddAssert("Not loading", () => !votePill.IsLoading);
|
2019-11-06 17:54:04 +08:00
|
|
|
|
}
|
2019-10-30 09:16:14 +08:00
|
|
|
|
|
2019-11-06 17:54:04 +08:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestRandomCommentPill()
|
|
|
|
|
{
|
2021-01-23 02:47:53 +08:00
|
|
|
|
AddStep("Hide login overlay", () => login.Hide());
|
2019-11-06 23:32:09 +08:00
|
|
|
|
AddStep("Log in", logIn);
|
2019-11-06 17:54:04 +08:00
|
|
|
|
AddStep("Random comment", () => addVotePill(getRandomComment()));
|
2021-01-23 03:49:49 +08:00
|
|
|
|
AddAssert("Background is visible", () => votePill.Background.Alpha == 1);
|
2021-08-04 16:27:44 +08:00
|
|
|
|
AddStep("Click", () => votePill.TriggerClick());
|
2019-10-30 09:31:09 +08:00
|
|
|
|
AddAssert("Loading", () => votePill.IsLoading);
|
2019-11-06 17:54:04 +08:00
|
|
|
|
}
|
2019-10-30 09:16:14 +08:00
|
|
|
|
|
2019-11-06 17:54:04 +08:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestOfflineRandomCommentPill()
|
|
|
|
|
{
|
2021-01-23 02:47:53 +08:00
|
|
|
|
AddStep("Hide login overlay", () => login.Hide());
|
2019-11-06 23:24:30 +08:00
|
|
|
|
AddStep("Log out", API.Logout);
|
2019-11-06 17:54:04 +08:00
|
|
|
|
AddStep("Random comment", () => addVotePill(getRandomComment()));
|
2021-08-04 16:27:44 +08:00
|
|
|
|
AddStep("Click", () => votePill.TriggerClick());
|
2021-01-23 02:47:53 +08:00
|
|
|
|
AddAssert("Login overlay is visible", () => login.State.Value == Visibility.Visible);
|
2019-10-30 08:45:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-01-24 01:04:41 +08:00
|
|
|
|
private void logIn()
|
|
|
|
|
{
|
|
|
|
|
API.Login("localUser", "password");
|
|
|
|
|
((DummyAPIAccess)API).AuthenticateSecondFactor("abcdefgh");
|
|
|
|
|
}
|
2019-11-06 23:32:09 +08:00
|
|
|
|
|
2019-10-31 07:10:00 +08:00
|
|
|
|
private Comment getUserComment() => new Comment
|
|
|
|
|
{
|
|
|
|
|
IsVoted = false,
|
2019-11-06 23:24:30 +08:00
|
|
|
|
UserId = API.LocalUser.Value.Id,
|
2019-10-31 07:10:00 +08:00
|
|
|
|
VotesCount = 10,
|
|
|
|
|
};
|
|
|
|
|
|
2019-11-06 17:54:04 +08:00
|
|
|
|
private Comment getRandomComment() => new Comment
|
|
|
|
|
{
|
|
|
|
|
IsVoted = false,
|
|
|
|
|
UserId = 4444,
|
|
|
|
|
VotesCount = 2,
|
|
|
|
|
};
|
|
|
|
|
|
2019-10-30 08:45:05 +08:00
|
|
|
|
private void addVotePill(Comment comment)
|
|
|
|
|
{
|
2021-01-23 02:47:53 +08:00
|
|
|
|
pillContainer.Clear();
|
2021-01-23 03:49:49 +08:00
|
|
|
|
pillContainer.Child = votePill = new TestPill(comment)
|
2019-10-30 08:45:05 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
2021-01-23 02:47:53 +08:00
|
|
|
|
};
|
2019-10-30 08:45:05 +08:00
|
|
|
|
}
|
2021-01-23 03:49:49 +08:00
|
|
|
|
|
|
|
|
|
private partial class TestPill : VotePill
|
|
|
|
|
{
|
|
|
|
|
public new Box Background => base.Background;
|
|
|
|
|
|
|
|
|
|
public TestPill(Comment comment)
|
|
|
|
|
: base(comment)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-10-30 08:45:05 +08:00
|
|
|
|
}
|
|
|
|
|
}
|