diff --git a/osu.Game.Tests/Visual/Online/TestSceneVotePill.cs b/osu.Game.Tests/Visual/Online/TestSceneVotePill.cs new file mode 100644 index 0000000000..8197cf72de --- /dev/null +++ b/osu.Game.Tests/Visual/Online/TestSceneVotePill.cs @@ -0,0 +1,76 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System; +using System.Collections.Generic; +using NUnit.Framework; +using osu.Framework.Graphics; +using osu.Game.Overlays.Comments; +using osu.Game.Online.API.Requests.Responses; + +namespace osu.Game.Tests.Visual.Online +{ + [TestFixture] + public class TestSceneVotePill : OsuTestScene + { + public override IReadOnlyList RequiredTypes => new[] + { + typeof(VotePill) + }; + + private VotePill votePill; + + [Test] + public void TestUserCommentPill() + { + AddStep("Log in", logIn); + AddStep("User comment", () => addVotePill(getUserComment())); + AddStep("Click", () => votePill.Click()); + AddAssert("Not loading", () => !votePill.IsLoading); + } + + [Test] + public void TestRandomCommentPill() + { + AddStep("Log in", logIn); + AddStep("Random comment", () => addVotePill(getRandomComment())); + AddStep("Click", () => votePill.Click()); + AddAssert("Loading", () => votePill.IsLoading); + } + + [Test] + public void TestOfflineRandomCommentPill() + { + AddStep("Log out", API.Logout); + AddStep("Random comment", () => addVotePill(getRandomComment())); + AddStep("Click", () => votePill.Click()); + AddAssert("Not loading", () => !votePill.IsLoading); + } + + private void logIn() => API.Login("localUser", "password"); + + private Comment getUserComment() => new Comment + { + IsVoted = false, + UserId = API.LocalUser.Value.Id, + VotesCount = 10, + }; + + private Comment getRandomComment() => new Comment + { + IsVoted = false, + UserId = 4444, + VotesCount = 2, + }; + + private void addVotePill(Comment comment) + { + Clear(); + Add(votePill = new VotePill(comment) + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + }); + } + } +} diff --git a/osu.Game/Overlays/Comments/VotePill.cs b/osu.Game/Overlays/Comments/VotePill.cs index e8d9013fd9..ab35a477aa 100644 --- a/osu.Game/Overlays/Comments/VotePill.cs +++ b/osu.Game/Overlays/Comments/VotePill.cs @@ -48,8 +48,6 @@ namespace osu.Game.Overlays.Comments { this.comment = comment; - Action = onAction; - AutoSizeAxes = Axes.X; Height = 20; LoadingAnimationSize = new Vector2(10); @@ -60,6 +58,9 @@ namespace osu.Game.Overlays.Comments { AccentColour = borderContainer.BorderColour = sideNumber.Colour = colours.GreenLight; hoverLayer.Colour = Color4.Black.Opacity(0.5f); + + if (api.IsLoggedIn && api.LocalUser.Value.Id != comment.UserId) + Action = onAction; } protected override void LoadComplete() @@ -157,6 +158,9 @@ namespace osu.Game.Overlays.Comments private void updateDisplay() { + if (Action == null) + return; + if (isVoted.Value) { hoverLayer.FadeTo(IsHovered ? 1 : 0);