1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-12 01:47:24 +08:00
osu-lazer/osu.Game.Tests/Visual/Online/TestSceneCommentsContainer.cs

208 lines
7.4 KiB
C#
Raw Normal View History

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-06-13 18:41:00 +08:00
private CommentsContainer commentsContainer;
[SetUp]
public void SetUp() => Schedule(() =>
Child = new BasicScrollContainer
{
RelativeSizeAxes = Axes.Both,
2020-06-13 18:41:00 +08:00
Child = commentsContainer = new CommentsContainer()
});
2020-06-13 18:41:00 +08:00
[Test]
public void TestIdleState()
{
AddUntilStep("loading spinner shown",
() => commentsContainer.ChildrenOfType<CommentsShowMoreButton>().Single().IsLoading);
}
[TestCase(false)]
[TestCase(true)]
public void TestSingleCommentsPage(bool withPinned)
2020-06-13 18:41:00 +08:00
{
setUpCommentsResponse(getExampleComments(withPinned));
2020-06-13 18:41:00 +08:00
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
}
[TestCase(false)]
[TestCase(true)]
public void TestMultipleCommentPages(bool withPinned)
{
var comments = getExampleComments(withPinned);
2020-06-13 18:41:00 +08:00
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-06-13 18:41:00 +08:00
[TestCase(false)]
[TestCase(true)]
public void TestMultipleLoads(bool withPinned)
2020-06-13 18:48:16 +08:00
{
var comments = getExampleComments(withPinned);
int topLevelCommentCount = comments.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);
}
2021-08-14 00:48:14 +08:00
[Test]
public void TestNoComment()
{
var comments = getExampleComments();
comments.Comments.Clear();
setUpCommentsResponse(comments);
AddStep("show comments", () => commentsContainer.ShowComments(CommentableType.Beatmapset, 123));
2021-08-24 13:39:03 +08:00
AddAssert("no comment shown", () => !commentsContainer.ChildrenOfType<DrawableComment>().Any());
2021-08-14 00:48:14 +08:00
}
[TestCase(false)]
[TestCase(true)]
public void TestSingleComment(bool withPinned)
{
var comment = new Comment
{
Id = 1,
Message = "This is a single comment",
LegacyName = "SingleUser",
CreatedAt = DateTimeOffset.Now,
VotesCount = 0,
Pinned = withPinned,
};
var bundle = new CommentBundle
{
Comments = new List<Comment> { comment },
IncludedComments = new List<Comment>(),
PinnedComments = new List<Comment>(),
};
if (withPinned)
bundle.PinnedComments.Add(comment);
setUpCommentsResponse(bundle);
AddStep("show comments", () => commentsContainer.ShowComments(CommentableType.Beatmapset, 123));
AddUntilStep("wait comment load", () => commentsContainer.ChildrenOfType<DrawableComment>().Any());
2021-08-24 13:39:03 +08:00
AddAssert("only one comment shown", () =>
2021-08-14 00:48:14 +08:00
commentsContainer.ChildrenOfType<DrawableComment>().Count(d => d.Comment.Pinned == withPinned) == 1);
}
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))
return false;
2020-06-13 18:41:00 +08:00
getCommentsRequest.TriggerSuccess(commentBundle);
return true;
2020-06-13 18:41:00 +08:00
};
});
private CommentBundle getExampleComments(bool withPinned = false)
2020-06-13 18:41:00 +08:00
{
var bundle = new CommentBundle
2020-06-13 18:41:00 +08:00
{
Comments = new List<Comment>
2020-06-13 18:41:00 +08:00
{
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
},
2020-06-13 18:41:00 +08:00
},
IncludedComments = new List<Comment>(),
PinnedComments = new List<Comment>(),
};
if (withPinned)
{
var pinnedComment = new Comment
2020-06-13 18:41:00 +08:00
{
Id = 15,
Message = "This is pinned comment",
LegacyName = "PinnedUser",
2020-06-13 18:41:00 +08:00
CreatedAt = DateTimeOffset.Now,
VotesCount = 999,
Pinned = true,
RepliesCount = 1,
};
bundle.Comments.Add(pinnedComment);
bundle.PinnedComments.Add(pinnedComment);
bundle.Comments.Add(new Comment
2020-06-13 18:41:00 +08:00
{
Id = 20,
Message = "Reply to pinned comment",
LegacyName = "AbandonedUser",
2020-06-13 18:41:00 +08:00
CreatedAt = DateTimeOffset.Now,
VotesCount = 0,
ParentId = 15,
});
}
return bundle;
}
2019-10-07 22:49:20 +08:00
}
}