mirror of
https://github.com/osukey/osukey.git
synced 2025-05-02 20:27:27 +09: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()));
|
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
|
private CommentBundle getEmptyCommentBundle() => new CommentBundle
|
||||||
{
|
{
|
||||||
Comments = new List<Comment>(),
|
Comments = new List<Comment>(),
|
||||||
@ -164,8 +173,28 @@ namespace osu.Game.Tests.Visual.Online
|
|||||||
Total = 10
|
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
|
private class TestCommentsContainer : CommentsContainer
|
||||||
{
|
{
|
||||||
|
public int DictionaryLength => CommentDictionary.Count;
|
||||||
|
|
||||||
|
public new void AppendComments(CommentBundle bundle) => base.AppendComments(bundle);
|
||||||
|
|
||||||
public void ShowComments(CommentBundle bundle)
|
public void ShowComments(CommentBundle bundle)
|
||||||
{
|
{
|
||||||
CommentCounter.Current.Value = 0;
|
CommentCounter.Current.Value = 0;
|
||||||
|
@ -167,10 +167,10 @@ namespace osu.Game.Overlays.Comments
|
|||||||
moreButton.Show();
|
moreButton.Show();
|
||||||
moreButton.IsLoading = true;
|
moreButton.IsLoading = true;
|
||||||
content.Clear();
|
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)
|
protected void OnSuccess(CommentBundle response)
|
||||||
{
|
{
|
||||||
@ -181,7 +181,7 @@ namespace osu.Game.Overlays.Comments
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var topLevelComments = appendComments(response);
|
var topLevelComments = AppendComments(response);
|
||||||
|
|
||||||
LoadComponentsAsync(topLevelComments, loaded =>
|
LoadComponentsAsync(topLevelComments, loaded =>
|
||||||
{
|
{
|
||||||
@ -209,7 +209,7 @@ namespace osu.Game.Overlays.Comments
|
|||||||
/// Appends retrieved comments to the subtree rooted of comments in this page.
|
/// Appends retrieved comments to the subtree rooted of comments in this page.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="bundle">The bundle of comments to add.</param>
|
/// <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 topLevelComments = new List<DrawableComment>();
|
||||||
var orphaned = new List<Comment>();
|
var orphaned = new List<Comment>();
|
||||||
@ -217,7 +217,7 @@ namespace osu.Game.Overlays.Comments
|
|||||||
foreach (var comment in bundle.Comments.Concat(bundle.IncludedComments))
|
foreach (var comment in bundle.Comments.Concat(bundle.IncludedComments))
|
||||||
{
|
{
|
||||||
// Exclude possible duplicated comments.
|
// Exclude possible duplicated comments.
|
||||||
if (commentDictionary.ContainsKey(comment.Id))
|
if (CommentDictionary.ContainsKey(comment.Id))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
addNewComment(comment);
|
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.
|
// Comments that have no parent are added as top-level comments to the flow.
|
||||||
topLevelComments.Add(drawableComment);
|
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.
|
// The comment's parent has already been seen, so the parent<-> child links can be added.
|
||||||
comment.ParentComment = parentDrawable.Comment;
|
comment.ParentComment = parentDrawable.Comment;
|
||||||
@ -255,10 +255,10 @@ namespace osu.Game.Overlays.Comments
|
|||||||
|
|
||||||
private DrawableComment getDrawableComment(Comment comment)
|
private DrawableComment getDrawableComment(Comment comment)
|
||||||
{
|
{
|
||||||
if (commentDictionary.TryGetValue(comment.Id, out var existing))
|
if (CommentDictionary.TryGetValue(comment.Id, out var existing))
|
||||||
return existing;
|
return existing;
|
||||||
|
|
||||||
return commentDictionary[comment.Id] = new DrawableComment(comment)
|
return CommentDictionary[comment.Id] = new DrawableComment(comment)
|
||||||
{
|
{
|
||||||
ShowDeleted = { BindTarget = ShowDeleted },
|
ShowDeleted = { BindTarget = ShowDeleted },
|
||||||
Sort = { BindTarget = Sort },
|
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);
|
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);
|
api.PerformAsync(req);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user