2019-10-07 22:49:20 +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.
|
|
|
|
|
|
2020-06-13 18:41:00 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2019-10-07 22:49:20 +08:00
|
|
|
|
using NUnit.Framework;
|
2020-01-27 20:07:24 +08:00
|
|
|
|
using osu.Game.Overlays;
|
|
|
|
|
using osu.Framework.Allocation;
|
2020-06-13 18:41:00 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Testing;
|
|
|
|
|
using osu.Game.Online.API;
|
|
|
|
|
using osu.Game.Online.API.Requests;
|
|
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
|
|
|
|
using osu.Game.Overlays.Comments;
|
2019-10-07 22:49:20 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.Online
|
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
|
|
|
|
public class TestSceneCommentsContainer : OsuTestScene
|
|
|
|
|
{
|
2020-01-27 20:07:24 +08:00
|
|
|
|
[Cached]
|
|
|
|
|
private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Purple);
|
|
|
|
|
|
2020-06-13 18:41:00 +08:00
|
|
|
|
private DummyAPIAccess dummyAPI => (DummyAPIAccess)API;
|
2020-02-06 21:54:02 +08:00
|
|
|
|
|
2020-06-13 18:41:00 +08:00
|
|
|
|
private CommentsContainer commentsContainer;
|
|
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
|
public void SetUp() => Schedule(() =>
|
|
|
|
|
Child = new BasicScrollContainer
|
2019-10-07 23:26:07 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2020-06-13 18:41:00 +08:00
|
|
|
|
Child = commentsContainer = new CommentsContainer()
|
2019-10-07 23:26:07 +08:00
|
|
|
|
});
|
|
|
|
|
|
2020-06-13 18:41:00 +08:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestIdleState()
|
|
|
|
|
{
|
|
|
|
|
AddUntilStep("loading spinner shown",
|
|
|
|
|
() => commentsContainer.ChildrenOfType<CommentsShowMoreButton>().Single().IsLoading);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestSingleCommentsPage()
|
|
|
|
|
{
|
|
|
|
|
setUpCommentsResponse(exampleComments);
|
|
|
|
|
AddStep("show comments", () => commentsContainer.ShowComments(CommentableType.Beatmapset, 123));
|
|
|
|
|
AddUntilStep("show more button hidden",
|
|
|
|
|
() => commentsContainer.ChildrenOfType<CommentsShowMoreButton>().Single().Alpha == 0);
|
2019-10-07 22:49:20 +08:00
|
|
|
|
}
|
2020-02-06 21:54:02 +08:00
|
|
|
|
|
2020-06-13 18:41:00 +08:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestMultipleCommentPages()
|
2020-02-06 21:54:02 +08:00
|
|
|
|
{
|
2020-06-13 18:41:00 +08:00
|
|
|
|
var comments = exampleComments;
|
|
|
|
|
comments.HasMore = true;
|
|
|
|
|
comments.TopLevelCount = 10;
|
|
|
|
|
|
|
|
|
|
setUpCommentsResponse(comments);
|
|
|
|
|
AddStep("show comments", () => commentsContainer.ShowComments(CommentableType.Beatmapset, 123));
|
|
|
|
|
AddUntilStep("show more button visible",
|
|
|
|
|
() => commentsContainer.ChildrenOfType<CommentsShowMoreButton>().Single().Alpha == 1);
|
2020-02-06 21:54:02 +08:00
|
|
|
|
}
|
2020-06-13 18:41:00 +08:00
|
|
|
|
|
2020-06-13 18:48:16 +08:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestMultipleLoads()
|
|
|
|
|
{
|
|
|
|
|
var comments = exampleComments;
|
2020-09-23 20:06:11 +08:00
|
|
|
|
int topLevelCommentCount = exampleComments.Comments.Count;
|
2020-06-13 18:48:16 +08:00
|
|
|
|
|
|
|
|
|
AddStep("hide container", () => commentsContainer.Hide());
|
|
|
|
|
setUpCommentsResponse(comments);
|
|
|
|
|
AddRepeatStep("show comments multiple times",
|
|
|
|
|
() => commentsContainer.ShowComments(CommentableType.Beatmapset, 456), 2);
|
|
|
|
|
AddStep("show container", () => commentsContainer.Show());
|
|
|
|
|
AddUntilStep("comment count is correct",
|
|
|
|
|
() => commentsContainer.ChildrenOfType<DrawableComment>().Count() == topLevelCommentCount);
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-13 18:41:00 +08:00
|
|
|
|
private void setUpCommentsResponse(CommentBundle commentBundle)
|
|
|
|
|
=> AddStep("set up response", () =>
|
|
|
|
|
{
|
|
|
|
|
dummyAPI.HandleRequest = request =>
|
|
|
|
|
{
|
|
|
|
|
if (!(request is GetCommentsRequest getCommentsRequest))
|
2021-03-23 17:08:32 +08:00
|
|
|
|
return false;
|
2020-06-13 18:41:00 +08:00
|
|
|
|
|
|
|
|
|
getCommentsRequest.TriggerSuccess(commentBundle);
|
2021-03-23 17:08:32 +08:00
|
|
|
|
return true;
|
2020-06-13 18:41:00 +08:00
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
private CommentBundle exampleComments => new CommentBundle
|
|
|
|
|
{
|
|
|
|
|
Comments = new List<Comment>
|
|
|
|
|
{
|
|
|
|
|
new Comment
|
|
|
|
|
{
|
|
|
|
|
Id = 1,
|
|
|
|
|
Message = "This is a comment",
|
|
|
|
|
LegacyName = "FirstUser",
|
|
|
|
|
CreatedAt = DateTimeOffset.Now,
|
|
|
|
|
VotesCount = 19,
|
|
|
|
|
RepliesCount = 1
|
|
|
|
|
},
|
|
|
|
|
new Comment
|
|
|
|
|
{
|
|
|
|
|
Id = 5,
|
|
|
|
|
ParentId = 1,
|
|
|
|
|
Message = "This is a child comment",
|
|
|
|
|
LegacyName = "SecondUser",
|
|
|
|
|
CreatedAt = DateTimeOffset.Now,
|
|
|
|
|
VotesCount = 4,
|
|
|
|
|
},
|
|
|
|
|
new Comment
|
|
|
|
|
{
|
|
|
|
|
Id = 10,
|
|
|
|
|
Message = "This is another comment",
|
|
|
|
|
LegacyName = "ThirdUser",
|
|
|
|
|
CreatedAt = DateTimeOffset.Now,
|
|
|
|
|
VotesCount = 0
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
IncludedComments = new List<Comment>(),
|
|
|
|
|
};
|
2019-10-07 22:49:20 +08:00
|
|
|
|
}
|
|
|
|
|
}
|