mirror of
https://github.com/ppy/osu.git
synced 2025-02-13 10:33:07 +08:00
Add tests for CommentsPage
This commit is contained in:
parent
e7964023ae
commit
dc10e58b4f
@ -25,7 +25,8 @@ namespace osu.Game.Tests.Visual.Online
|
||||
typeof(SortTabControl),
|
||||
typeof(ShowChildrenButton),
|
||||
typeof(DeletedChildrenPlaceholder),
|
||||
typeof(VotePill)
|
||||
typeof(VotePill),
|
||||
typeof(CommentsPage),
|
||||
};
|
||||
|
||||
protected override bool UseOnlineAPI => true;
|
||||
|
165
osu.Game.Tests/Visual/Online/TestSceneCommentsPage.cs
Normal file
165
osu.Game.Tests/Visual/Online/TestSceneCommentsPage.cs
Normal file
@ -0,0 +1,165 @@
|
||||
// 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.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using osu.Game.Overlays.Comments;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Game.Online.API.Requests.Responses;
|
||||
using osu.Game.Users;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osuTK.Graphics;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Online
|
||||
{
|
||||
public class TestSceneCommentsPage : OsuTestScene
|
||||
{
|
||||
public override IReadOnlyList<Type> RequiredTypes => new[]
|
||||
{
|
||||
typeof(DrawableComment),
|
||||
typeof(CommentsPage),
|
||||
};
|
||||
|
||||
[Cached]
|
||||
private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Purple);
|
||||
|
||||
private readonly BindableBool showDeleted = new BindableBool();
|
||||
private readonly Container content;
|
||||
|
||||
public TestSceneCommentsPage()
|
||||
{
|
||||
AddRange(new Drawable[]
|
||||
{
|
||||
new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = Color4.Black,
|
||||
},
|
||||
new FillFlowContainer
|
||||
{
|
||||
AutoSizeAxes = Axes.Y,
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Direction = FillDirection.Vertical,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new OsuCheckbox
|
||||
{
|
||||
Current = showDeleted,
|
||||
LabelText = @"Show Deleted"
|
||||
},
|
||||
content = new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
AddStep("load comments", () => createPage(comment_bundle));
|
||||
AddStep("load empty comments", () => createPage(empty_comment_bundle));
|
||||
}
|
||||
|
||||
private void createPage(CommentBundle commentBundle)
|
||||
{
|
||||
content.Clear();
|
||||
content.Add(new CommentsPage(commentBundle)
|
||||
{
|
||||
ShowDeleted = { BindTarget = showDeleted }
|
||||
});
|
||||
}
|
||||
|
||||
private static readonly CommentBundle empty_comment_bundle = new CommentBundle
|
||||
{
|
||||
Comments = new List<Comment>(),
|
||||
Total = 0,
|
||||
};
|
||||
|
||||
private static readonly CommentBundle comment_bundle = new CommentBundle
|
||||
{
|
||||
Comments = new List<Comment>
|
||||
{
|
||||
new Comment
|
||||
{
|
||||
Id = 1,
|
||||
Message = "Simple test comment",
|
||||
LegacyName = "TestUser1",
|
||||
CreatedAt = DateTimeOffset.Now,
|
||||
VotesCount = 5
|
||||
},
|
||||
new Comment
|
||||
{
|
||||
Id = 2,
|
||||
Message = "This comment has been deleted :( but visible for admins",
|
||||
LegacyName = "TestUser2",
|
||||
CreatedAt = DateTimeOffset.Now,
|
||||
DeletedAt = DateTimeOffset.Now,
|
||||
VotesCount = 5
|
||||
},
|
||||
new Comment
|
||||
{
|
||||
Id = 3,
|
||||
Message = "This comment is a top level",
|
||||
LegacyName = "TestUser3",
|
||||
CreatedAt = DateTimeOffset.Now,
|
||||
RepliesCount = 2,
|
||||
},
|
||||
new Comment
|
||||
{
|
||||
Id = 4,
|
||||
ParentId = 3,
|
||||
Message = "And this is a reply",
|
||||
RepliesCount = 1,
|
||||
LegacyName = "TestUser1",
|
||||
CreatedAt = DateTimeOffset.Now,
|
||||
},
|
||||
new Comment
|
||||
{
|
||||
Id = 15,
|
||||
ParentId = 4,
|
||||
Message = "Reply to reply",
|
||||
LegacyName = "TestUser1",
|
||||
CreatedAt = DateTimeOffset.Now,
|
||||
},
|
||||
new Comment
|
||||
{
|
||||
Id = 6,
|
||||
ParentId = 3,
|
||||
LegacyName = "TestUser11515",
|
||||
CreatedAt = DateTimeOffset.Now,
|
||||
DeletedAt = DateTimeOffset.Now,
|
||||
},
|
||||
new Comment
|
||||
{
|
||||
Id = 5,
|
||||
Message = "This comment is voted and edited",
|
||||
LegacyName = "BigBrainUser",
|
||||
CreatedAt = DateTimeOffset.Now,
|
||||
EditedAt = DateTimeOffset.Now,
|
||||
VotesCount = 1000,
|
||||
EditedById = 1,
|
||||
}
|
||||
},
|
||||
IncludedComments = new List<Comment>(),
|
||||
UserVotes = new List<long>
|
||||
{
|
||||
5
|
||||
},
|
||||
Users = new List<User>
|
||||
{
|
||||
new User
|
||||
{
|
||||
Id = 1,
|
||||
Username = "Good_Admin"
|
||||
}
|
||||
},
|
||||
TopLevelCount = 4,
|
||||
Total = 7
|
||||
};
|
||||
}
|
||||
}
|
@ -6,8 +6,6 @@ using osu.Game.Users;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace osu.Game.Online.API.Requests.Responses
|
||||
{
|
||||
@ -70,12 +68,10 @@ namespace osu.Game.Online.API.Requests.Responses
|
||||
|
||||
public bool IsDeleted => DeletedAt.HasValue;
|
||||
|
||||
public bool HasMessage => !string.IsNullOrEmpty(MessageHtml);
|
||||
public bool HasMessage => !string.IsNullOrEmpty(Message);
|
||||
|
||||
public bool IsVoted { get; set; }
|
||||
|
||||
public string GetMessage => HasMessage ? WebUtility.HtmlDecode(Regex.Replace(MessageHtml, @"<(.|\n)*?>", string.Empty)) : string.Empty;
|
||||
|
||||
public int DeletedChildrenCount => ChildComments.Count(c => c.IsDeleted);
|
||||
}
|
||||
}
|
||||
|
@ -47,17 +47,25 @@ namespace osu.Game.Online.API.Requests.Responses
|
||||
[JsonProperty(@"included_comments")]
|
||||
public List<Comment> IncludedComments { get; set; }
|
||||
|
||||
private List<long> userVotes;
|
||||
|
||||
[JsonProperty(@"user_votes")]
|
||||
private List<long> userVotes
|
||||
public List<long> UserVotes
|
||||
{
|
||||
set => value.ForEach(v =>
|
||||
get => userVotes;
|
||||
set
|
||||
{
|
||||
Comments.ForEach(c =>
|
||||
userVotes = value;
|
||||
|
||||
value.ForEach(v =>
|
||||
{
|
||||
if (v == c.Id)
|
||||
c.IsVoted = true;
|
||||
Comments.ForEach(c =>
|
||||
{
|
||||
if (v == c.Id)
|
||||
c.IsVoted = true;
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private List<User> users;
|
||||
|
@ -213,7 +213,7 @@ namespace osu.Game.Overlays.Comments
|
||||
|
||||
if (comment.HasMessage)
|
||||
{
|
||||
var formattedSource = MessageFormatter.FormatText(comment.GetMessage);
|
||||
var formattedSource = MessageFormatter.FormatText(comment.Message);
|
||||
message.AddLinks(formattedSource.Text, formattedSource.Links);
|
||||
}
|
||||
|
||||
@ -343,7 +343,7 @@ namespace osu.Game.Overlays.Comments
|
||||
if (parentComment == null)
|
||||
return string.Empty;
|
||||
|
||||
return parentComment.HasMessage ? parentComment.GetMessage : parentComment.IsDeleted ? @"deleted" : string.Empty;
|
||||
return parentComment.HasMessage ? parentComment.Message : parentComment.IsDeleted ? @"deleted" : string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user