mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 17:07:38 +08:00
Add test
This commit is contained in:
parent
3e9fd4c08c
commit
dc0aa2295a
@ -15,6 +15,7 @@ using osu.Framework.Testing;
|
||||
using osu.Game.Graphics.Containers;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Graphics.UserInterfaceV2;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.API.Requests;
|
||||
using osu.Game.Online.API.Requests.Responses;
|
||||
@ -38,12 +39,14 @@ namespace osu.Game.Tests.Visual.Online
|
||||
|
||||
private CommentsContainer commentsContainer = null!;
|
||||
|
||||
private readonly ManualResetEventSlim requestLock = new ManualResetEventSlim();
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
base.Content.AddRange(new Drawable[]
|
||||
{
|
||||
new PopoverContainer()
|
||||
new PopoverContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Child = content = new OsuScrollContainer
|
||||
@ -85,8 +88,6 @@ namespace osu.Game.Tests.Visual.Online
|
||||
});
|
||||
}
|
||||
|
||||
private readonly ManualResetEventSlim deletionPerformed = new ManualResetEventSlim();
|
||||
|
||||
[Test]
|
||||
public void TestDeletion()
|
||||
{
|
||||
@ -110,7 +111,7 @@ namespace osu.Game.Tests.Visual.Online
|
||||
});
|
||||
AddStep("Setup request handling", () =>
|
||||
{
|
||||
deletionPerformed.Reset();
|
||||
requestLock.Reset();
|
||||
|
||||
dummyAPI.HandleRequest = request =>
|
||||
{
|
||||
@ -143,7 +144,7 @@ namespace osu.Game.Tests.Visual.Online
|
||||
|
||||
Task.Run(() =>
|
||||
{
|
||||
deletionPerformed.Wait(10000);
|
||||
requestLock.Wait(10000);
|
||||
req.TriggerSuccess(cb);
|
||||
});
|
||||
|
||||
@ -154,7 +155,7 @@ namespace osu.Game.Tests.Visual.Online
|
||||
|
||||
AddAssert("Loading spinner shown", () => commentsContainer.ChildrenOfType<LoadingSpinner>().Any(d => d.IsPresent));
|
||||
|
||||
AddStep("Complete request", () => deletionPerformed.Set());
|
||||
AddStep("Complete request", () => requestLock.Set());
|
||||
|
||||
AddUntilStep("Comment is deleted locally", () => this.ChildrenOfType<DrawableComment>().Single(x => x.Comment.Id == 1).WasDeleted);
|
||||
}
|
||||
@ -209,6 +210,78 @@ namespace osu.Game.Tests.Visual.Online
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestReport()
|
||||
{
|
||||
const string report_text = "I don't like this comment";
|
||||
DrawableComment? targetComment = null;
|
||||
CommentReportRequest? request = null;
|
||||
|
||||
addTestComments();
|
||||
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 CommentReportRequest req))
|
||||
return false;
|
||||
|
||||
Task.Run(() =>
|
||||
{
|
||||
request = req;
|
||||
requestLock.Wait(10000);
|
||||
req.TriggerSuccess();
|
||||
});
|
||||
|
||||
return true;
|
||||
};
|
||||
});
|
||||
AddStep("Click the button", () =>
|
||||
{
|
||||
var btn = targetComment.ChildrenOfType<OsuSpriteText>().Single(x => x.Text == "Report");
|
||||
InputManager.MoveMouseTo(btn);
|
||||
InputManager.Click(MouseButton.Left);
|
||||
});
|
||||
AddStep("Select \"other\"", () =>
|
||||
{
|
||||
var field = this.ChildrenOfType<LabelledEnumDropdown<CommentReportReason>>().Single();
|
||||
field.Current.Value = CommentReportReason.Other;
|
||||
});
|
||||
AddStep("Try to report", () =>
|
||||
{
|
||||
var btn = this.ChildrenOfType<ReportCommentPopover>().Single().ChildrenOfType<RoundedButton>().Single();
|
||||
InputManager.MoveMouseTo(btn);
|
||||
InputManager.Click(MouseButton.Left);
|
||||
});
|
||||
AddWaitStep("Wait", 3);
|
||||
AddAssert("Nothing happened", () => this.ChildrenOfType<ReportCommentPopover>().Any());
|
||||
AddStep("Enter some text", () =>
|
||||
{
|
||||
var field = this.ChildrenOfType<LabelledTextBox>().Single();
|
||||
field.Current.Value = report_text;
|
||||
});
|
||||
AddStep("Try to report", () =>
|
||||
{
|
||||
var btn = this.ChildrenOfType<ReportCommentPopover>().Single().ChildrenOfType<RoundedButton>().Single();
|
||||
InputManager.MoveMouseTo(btn);
|
||||
InputManager.Click(MouseButton.Left);
|
||||
});
|
||||
AddWaitStep("Wait", 3);
|
||||
AddAssert("Overlay closed", () => !this.ChildrenOfType<ReportCommentPopover>().Any());
|
||||
AddAssert("Loading spinner shown", () => targetComment.ChildrenOfType<LoadingSpinner>().Any(d => d.IsPresent));
|
||||
AddStep("Complete request", () => requestLock.Set());
|
||||
AddUntilStep("Request sent", () => request != null);
|
||||
AddAssert("Request is correct", () => request != null && request.CommentID == 2 && request.Info == report_text && request.Reason == CommentReportReason.Other);
|
||||
AddUntilStep("Buttons hidden", () => !targetComment.ChildrenOfType<LinkFlowContainer>().Single(x => x.Name == @"Actions buttons").IsPresent);
|
||||
}
|
||||
|
||||
private void addTestComments()
|
||||
{
|
||||
AddStep("set up response", () =>
|
||||
|
@ -414,7 +414,7 @@ namespace osu.Game.Overlays.Comments
|
||||
actionsContainer.Hide();
|
||||
actionsLoading.Show();
|
||||
var request = new CommentReportRequest(Comment.Id, reason, comment);
|
||||
request.Success += () =>
|
||||
request.Success += () => Schedule(() =>
|
||||
{
|
||||
actionsLoading.Hide();
|
||||
notificationOverlay?.Post(new SimpleNotification
|
||||
@ -422,12 +422,12 @@ namespace osu.Game.Overlays.Comments
|
||||
Icon = FontAwesome.Solid.CheckCircle,
|
||||
Text = "The comment reported successfully."
|
||||
});
|
||||
};
|
||||
request.Failure += _ =>
|
||||
});
|
||||
request.Failure += _ => Schedule(() =>
|
||||
{
|
||||
actionsLoading.Hide();
|
||||
actionsContainer.Show();
|
||||
};
|
||||
});
|
||||
api.Queue(request);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user