mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 23:12:56 +08:00
Add back regression test
This commit is contained in:
parent
638d060145
commit
ddb494efb3
@ -51,6 +51,15 @@ namespace osu.Game.Tests.Visual.Online
|
||||
AddStep("Add empty comment bundle", () => comments.ShowComments(getEmptyCommentBundle()));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestAppendDuplicatedComment()
|
||||
{
|
||||
AddStep("Add comment bundle", () => comments.ShowComments(getCommentBundle()));
|
||||
AddUntilStep("Dictionary length is 10", () => comments.DictionaryLength == 10);
|
||||
AddStep("Append existing comment", () => comments.AppendComments(getCommentSubBundle()));
|
||||
AddAssert("Dictionary length is 10", () => comments.DictionaryLength == 10);
|
||||
}
|
||||
|
||||
private CommentBundle getEmptyCommentBundle() => new CommentBundle
|
||||
{
|
||||
Comments = new List<Comment>(),
|
||||
@ -164,8 +173,28 @@ namespace osu.Game.Tests.Visual.Online
|
||||
Total = 10
|
||||
};
|
||||
|
||||
private CommentBundle getCommentSubBundle() => new CommentBundle
|
||||
{
|
||||
Comments = new List<Comment>
|
||||
{
|
||||
new Comment
|
||||
{
|
||||
Id = 1,
|
||||
Message = "Simple test comment",
|
||||
LegacyName = "TestUser1",
|
||||
CreatedAt = DateTimeOffset.Now,
|
||||
VotesCount = 5
|
||||
},
|
||||
},
|
||||
IncludedComments = new List<Comment>(),
|
||||
};
|
||||
|
||||
private class TestCommentsContainer : CommentsContainer
|
||||
{
|
||||
public int DictionaryLength => CommentDictionary.Count;
|
||||
|
||||
public new void AppendComments(CommentBundle bundle) => base.AppendComments(bundle);
|
||||
|
||||
public void ShowComments(CommentBundle bundle)
|
||||
{
|
||||
CommentCounter.Current.Value = 0;
|
||||
|
@ -167,10 +167,10 @@ namespace osu.Game.Overlays.Comments
|
||||
moreButton.Show();
|
||||
moreButton.IsLoading = true;
|
||||
content.Clear();
|
||||
commentDictionary.Clear();
|
||||
CommentDictionary.Clear();
|
||||
}
|
||||
|
||||
private readonly Dictionary<long, DrawableComment> commentDictionary = new Dictionary<long, DrawableComment>();
|
||||
protected readonly Dictionary<long, DrawableComment> CommentDictionary = new Dictionary<long, DrawableComment>();
|
||||
|
||||
protected void OnSuccess(CommentBundle response)
|
||||
{
|
||||
@ -181,7 +181,7 @@ namespace osu.Game.Overlays.Comments
|
||||
return;
|
||||
}
|
||||
|
||||
var topLevelComments = appendComments(response);
|
||||
var topLevelComments = AppendComments(response);
|
||||
|
||||
LoadComponentsAsync(topLevelComments, loaded =>
|
||||
{
|
||||
@ -209,7 +209,7 @@ namespace osu.Game.Overlays.Comments
|
||||
/// Appends retrieved comments to the subtree rooted of comments in this page.
|
||||
/// </summary>
|
||||
/// <param name="bundle">The bundle of comments to add.</param>
|
||||
private List<DrawableComment> appendComments([NotNull] CommentBundle bundle)
|
||||
protected List<DrawableComment> AppendComments([NotNull] CommentBundle bundle)
|
||||
{
|
||||
var topLevelComments = new List<DrawableComment>();
|
||||
var orphaned = new List<Comment>();
|
||||
@ -217,7 +217,7 @@ namespace osu.Game.Overlays.Comments
|
||||
foreach (var comment in bundle.Comments.Concat(bundle.IncludedComments))
|
||||
{
|
||||
// Exclude possible duplicated comments.
|
||||
if (commentDictionary.ContainsKey(comment.Id))
|
||||
if (CommentDictionary.ContainsKey(comment.Id))
|
||||
continue;
|
||||
|
||||
addNewComment(comment);
|
||||
@ -238,7 +238,7 @@ namespace osu.Game.Overlays.Comments
|
||||
// Comments that have no parent are added as top-level comments to the flow.
|
||||
topLevelComments.Add(drawableComment);
|
||||
}
|
||||
else if (commentDictionary.TryGetValue(comment.ParentId.Value, out var parentDrawable))
|
||||
else if (CommentDictionary.TryGetValue(comment.ParentId.Value, out var parentDrawable))
|
||||
{
|
||||
// The comment's parent has already been seen, so the parent<-> child links can be added.
|
||||
comment.ParentComment = parentDrawable.Comment;
|
||||
@ -255,10 +255,10 @@ namespace osu.Game.Overlays.Comments
|
||||
|
||||
private DrawableComment getDrawableComment(Comment comment)
|
||||
{
|
||||
if (commentDictionary.TryGetValue(comment.Id, out var existing))
|
||||
if (CommentDictionary.TryGetValue(comment.Id, out var existing))
|
||||
return existing;
|
||||
|
||||
return commentDictionary[comment.Id] = new DrawableComment(comment)
|
||||
return CommentDictionary[comment.Id] = new DrawableComment(comment)
|
||||
{
|
||||
ShowDeleted = { BindTarget = ShowDeleted },
|
||||
Sort = { BindTarget = Sort },
|
||||
@ -270,7 +270,7 @@ namespace osu.Game.Overlays.Comments
|
||||
{
|
||||
var req = new GetCommentsRequest(id.Value, type.Value, Sort.Value, page, drawableComment.Comment.Id);
|
||||
|
||||
req.Success += response => Schedule(() => appendComments(response));
|
||||
req.Success += response => Schedule(() => AppendComments(response));
|
||||
|
||||
api.PerformAsync(req);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user