osu/osu.Game.Tests/Visual/Online/TestSceneVotePill.cs

110 lines
3.4 KiB
C#
Raw Normal View History

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