mirror of
https://github.com/ppy/osu.git
synced 2025-01-21 09:33:21 +08:00
Merge branch 'master' into home-shortcut
This commit is contained in:
commit
fe62b26d73
@ -1,52 +1,128 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Game.Online.API.Requests;
|
|
||||||
using osu.Framework.Graphics.Containers;
|
|
||||||
using osu.Framework.Graphics;
|
|
||||||
using osu.Game.Overlays.Comments;
|
|
||||||
using osu.Game.Overlays;
|
using osu.Game.Overlays;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Graphics;
|
||||||
using osu.Game.Users;
|
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;
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual.Online
|
namespace osu.Game.Tests.Visual.Online
|
||||||
{
|
{
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class TestSceneCommentsContainer : OsuTestScene
|
public class TestSceneCommentsContainer : OsuTestScene
|
||||||
{
|
{
|
||||||
protected override bool UseOnlineAPI => true;
|
|
||||||
|
|
||||||
[Cached]
|
[Cached]
|
||||||
private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Purple);
|
private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Purple);
|
||||||
|
|
||||||
public TestSceneCommentsContainer()
|
private DummyAPIAccess dummyAPI => (DummyAPIAccess)API;
|
||||||
{
|
|
||||||
BasicScrollContainer scroll;
|
|
||||||
TestCommentsContainer comments;
|
|
||||||
|
|
||||||
Add(scroll = new BasicScrollContainer
|
private CommentsContainer commentsContainer;
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void SetUp() => Schedule(() =>
|
||||||
|
Child = new BasicScrollContainer
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Child = comments = new TestCommentsContainer()
|
Child = commentsContainer = new CommentsContainer()
|
||||||
});
|
});
|
||||||
|
|
||||||
AddStep("Big Black comments", () => comments.ShowComments(CommentableType.Beatmapset, 41823));
|
[Test]
|
||||||
AddStep("Airman comments", () => comments.ShowComments(CommentableType.Beatmapset, 24313));
|
public void TestIdleState()
|
||||||
AddStep("Lazer build comments", () => comments.ShowComments(CommentableType.Build, 4772));
|
|
||||||
AddStep("News comments", () => comments.ShowComments(CommentableType.NewsPost, 715));
|
|
||||||
AddStep("Trigger user change", comments.User.TriggerChange);
|
|
||||||
AddStep("Idle state", () =>
|
|
||||||
{
|
|
||||||
scroll.Clear();
|
|
||||||
scroll.Add(comments = new TestCommentsContainer());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private class TestCommentsContainer : CommentsContainer
|
|
||||||
{
|
{
|
||||||
public new Bindable<User> User => base.User;
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestMultipleCommentPages()
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestMultipleLoads()
|
||||||
|
{
|
||||||
|
var comments = exampleComments;
|
||||||
|
int topLevelCommentCount = exampleComments.Comments.Count(comment => comment.IsTopLevel);
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setUpCommentsResponse(CommentBundle commentBundle)
|
||||||
|
=> AddStep("set up response", () =>
|
||||||
|
{
|
||||||
|
dummyAPI.HandleRequest = request =>
|
||||||
|
{
|
||||||
|
if (!(request is GetCommentsRequest getCommentsRequest))
|
||||||
|
return;
|
||||||
|
|
||||||
|
getCommentsRequest.TriggerSuccess(commentBundle);
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
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>(),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ using osu.Game.Online.API.Requests.Responses;
|
|||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using osu.Framework.Extensions.IEnumerableExtensions;
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
||||||
|
using osu.Framework.Threading;
|
||||||
using osu.Game.Users;
|
using osu.Game.Users;
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Comments
|
namespace osu.Game.Overlays.Comments
|
||||||
@ -30,6 +31,7 @@ namespace osu.Game.Overlays.Comments
|
|||||||
private IAPIProvider api { get; set; }
|
private IAPIProvider api { get; set; }
|
||||||
|
|
||||||
private GetCommentsRequest request;
|
private GetCommentsRequest request;
|
||||||
|
private ScheduledDelegate scheduledCommentsLoad;
|
||||||
private CancellationTokenSource loadCancellation;
|
private CancellationTokenSource loadCancellation;
|
||||||
private int currentPage;
|
private int currentPage;
|
||||||
|
|
||||||
@ -152,8 +154,9 @@ namespace osu.Game.Overlays.Comments
|
|||||||
|
|
||||||
request?.Cancel();
|
request?.Cancel();
|
||||||
loadCancellation?.Cancel();
|
loadCancellation?.Cancel();
|
||||||
|
scheduledCommentsLoad?.Cancel();
|
||||||
request = new GetCommentsRequest(id.Value, type.Value, Sort.Value, currentPage++, 0);
|
request = new GetCommentsRequest(id.Value, type.Value, Sort.Value, currentPage++, 0);
|
||||||
request.Success += res => Schedule(() => onSuccess(res));
|
request.Success += res => scheduledCommentsLoad = Schedule(() => onSuccess(res));
|
||||||
api.PerformAsync(request);
|
api.PerformAsync(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user