mirror of
https://github.com/osukey/osukey.git
synced 2025-08-07 00:23:59 +09:00
Add test
This commit is contained in:
@ -11,6 +11,8 @@ using osu.Framework.Allocation;
|
|||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics.Cursor;
|
using osu.Framework.Graphics.Cursor;
|
||||||
|
using osu.Framework.Graphics.Sprites;
|
||||||
|
using osu.Framework.Graphics.UserInterface;
|
||||||
using osu.Framework.Testing;
|
using osu.Framework.Testing;
|
||||||
using osu.Game.Graphics.Containers;
|
using osu.Game.Graphics.Containers;
|
||||||
using osu.Game.Graphics.Sprites;
|
using osu.Game.Graphics.Sprites;
|
||||||
@ -21,6 +23,7 @@ using osu.Game.Online.API.Requests;
|
|||||||
using osu.Game.Online.API.Requests.Responses;
|
using osu.Game.Online.API.Requests.Responses;
|
||||||
using osu.Game.Overlays;
|
using osu.Game.Overlays;
|
||||||
using osu.Game.Overlays.Comments;
|
using osu.Game.Overlays.Comments;
|
||||||
|
using osu.Game.Overlays.Comments.Buttons;
|
||||||
using osuTK.Input;
|
using osuTK.Input;
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual.Online
|
namespace osu.Game.Tests.Visual.Online
|
||||||
@ -278,6 +281,93 @@ namespace osu.Game.Tests.Visual.Online
|
|||||||
AddAssert("Request is correct", () => request != null && request.CommentID == 2 && request.Comment == report_text && request.Reason == CommentReportReason.Other);
|
AddAssert("Request is correct", () => request != null && request.CommentID == 2 && request.Comment == report_text && request.Reason == CommentReportReason.Other);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestReply()
|
||||||
|
{
|
||||||
|
addTestComments();
|
||||||
|
DrawableComment? targetComment = null;
|
||||||
|
AddUntilStep("Comment exists", () =>
|
||||||
|
{
|
||||||
|
var comments = this.ChildrenOfType<DrawableComment>();
|
||||||
|
targetComment = comments.SingleOrDefault(x => x.Comment.Id == 2);
|
||||||
|
return targetComment != null;
|
||||||
|
});
|
||||||
|
AddStep("Setup request handling", () =>
|
||||||
|
{
|
||||||
|
requestLock.Reset();
|
||||||
|
|
||||||
|
dummyAPI.HandleRequest = r =>
|
||||||
|
{
|
||||||
|
if (!(r is CommentPostRequest req))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (req.ParentCommentId != 2)
|
||||||
|
throw new ArgumentException("Wrong parent ID in request!");
|
||||||
|
|
||||||
|
if (req.CommentableId != 123 || req.Commentable != CommentableType.Beatmapset)
|
||||||
|
throw new ArgumentException("Wrong commentable data in request!");
|
||||||
|
|
||||||
|
Task.Run(() =>
|
||||||
|
{
|
||||||
|
requestLock.Wait(10000);
|
||||||
|
req.TriggerSuccess(new CommentBundle
|
||||||
|
{
|
||||||
|
Comments = new List<Comment>
|
||||||
|
{
|
||||||
|
new Comment
|
||||||
|
{
|
||||||
|
Id = 98,
|
||||||
|
Message = req.Message,
|
||||||
|
LegacyName = "FirstUser",
|
||||||
|
CreatedAt = DateTimeOffset.Now,
|
||||||
|
VotesCount = 98,
|
||||||
|
ParentId = req.ParentCommentId,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
});
|
||||||
|
AddStep("Click reply button", () =>
|
||||||
|
{
|
||||||
|
var btn = targetComment.ChildrenOfType<LinkFlowContainer>().Skip(1).First();
|
||||||
|
var texts = btn.ChildrenOfType<SpriteText>();
|
||||||
|
InputManager.MoveMouseTo(texts.Skip(1).First());
|
||||||
|
InputManager.Click(MouseButton.Left);
|
||||||
|
});
|
||||||
|
AddAssert("There is 0 replies", () =>
|
||||||
|
{
|
||||||
|
var replLabel = targetComment.ChildrenOfType<ShowRepliesButton>().First().ChildrenOfType<SpriteText>().First();
|
||||||
|
return replLabel.Text.ToString().Contains('0') && targetComment!.Comment.RepliesCount == 0;
|
||||||
|
});
|
||||||
|
AddStep("Focus field", () =>
|
||||||
|
{
|
||||||
|
InputManager.MoveMouseTo(targetComment.ChildrenOfType<TextBox>().First());
|
||||||
|
InputManager.Click(MouseButton.Left);
|
||||||
|
});
|
||||||
|
AddStep("Enter text", () =>
|
||||||
|
{
|
||||||
|
targetComment.ChildrenOfType<TextBox>().First().Current.Value = "random reply";
|
||||||
|
});
|
||||||
|
AddStep("Submit", () =>
|
||||||
|
{
|
||||||
|
InputManager.Key(Key.Enter);
|
||||||
|
});
|
||||||
|
AddStep("Complete request", () => requestLock.Set());
|
||||||
|
AddUntilStep("There is 1 reply", () =>
|
||||||
|
{
|
||||||
|
var replLabel = targetComment.ChildrenOfType<ShowRepliesButton>().First().ChildrenOfType<SpriteText>().First();
|
||||||
|
return replLabel.Text.ToString().Contains('1') && targetComment!.Comment.RepliesCount == 1;
|
||||||
|
});
|
||||||
|
AddUntilStep("Submitted comment shown", () =>
|
||||||
|
{
|
||||||
|
var r = targetComment.ChildrenOfType<DrawableComment>().Skip(1).FirstOrDefault();
|
||||||
|
return r != null && r.Comment.Message == "random reply";
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private void addTestComments()
|
private void addTestComments()
|
||||||
{
|
{
|
||||||
AddStep("set up response", () =>
|
AddStep("set up response", () =>
|
||||||
|
Reference in New Issue
Block a user