|
| 1 | +// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. |
| 2 | +// See the LICENCE file in the repository root for full licence text. |
| 3 | + |
| 4 | +using System.Linq; |
| 5 | +using System.Net.Http; |
| 6 | +using NUnit.Framework; |
| 7 | +using osu.Framework.Extensions; |
| 8 | +using osu.Framework.Graphics; |
| 9 | +using osu.Framework.Graphics.Cursor; |
| 10 | +using osu.Framework.Graphics.UserInterface; |
| 11 | +using osu.Framework.Testing; |
| 12 | +using osu.Game.Graphics; |
| 13 | +using osu.Game.Graphics.Containers; |
| 14 | +using osu.Game.Graphics.UserInterface; |
| 15 | +using osu.Game.Graphics.UserInterfaceV2; |
| 16 | +using osu.Game.Online.API; |
| 17 | +using osu.Game.Online.API.Requests; |
| 18 | +using osu.Game.Overlays.Chat; |
| 19 | + |
| 20 | +namespace osu.Game.Tests.Visual.Online |
| 21 | +{ |
| 22 | + public partial class TestSceneReportPopover : OsuTestScene |
| 23 | + { |
| 24 | + private DummyAPIAccess dummyAPI => (DummyAPIAccess)API; |
| 25 | + |
| 26 | + private ReportPopoverContainer popover = null!; |
| 27 | + |
| 28 | + [SetUpSteps] |
| 29 | + public void SetUp() |
| 30 | + { |
| 31 | + AddStep("create popover", () => |
| 32 | + { |
| 33 | + Child = new PopoverContainer |
| 34 | + { |
| 35 | + RelativeSizeAxes = Axes.Both, |
| 36 | + Child = popover = new ReportPopoverContainer(), |
| 37 | + }; |
| 38 | + }); |
| 39 | + } |
| 40 | + |
| 41 | + [Test] |
| 42 | + public void TestSuccess() |
| 43 | + { |
| 44 | + ChatReportRequest pendingRequest = null!; |
| 45 | + |
| 46 | + AddStep("setup request handling", () => |
| 47 | + { |
| 48 | + dummyAPI.HandleRequest += request => |
| 49 | + { |
| 50 | + if (request is ChatReportRequest chatReportRequest) |
| 51 | + { |
| 52 | + pendingRequest = chatReportRequest; |
| 53 | + return true; |
| 54 | + } |
| 55 | + |
| 56 | + return false; |
| 57 | + }; |
| 58 | + }); |
| 59 | + AddStep("show popover", () => popover.ShowPopover()); |
| 60 | + AddStep("input reason", () => this.ChildrenOfType<OsuTextBox>().First().Text = "reason"); |
| 61 | + AddStep("send report", () => this.ChildrenOfType<Button>().First().TriggerClick()); |
| 62 | + AddUntilStep("wait for loading layer to hide", () => this.ChildrenOfType<LoadingLayer>().First().IsPresent, () => Is.True); |
| 63 | + AddWaitStep("wait some", 3); |
| 64 | + AddStep("complete request", () => pendingRequest.TriggerSuccess()); |
| 65 | + AddUntilStep("wait for loading layer to hide", () => this.ChildrenOfType<LoadingLayer>().First().IsPresent, () => Is.False); |
| 66 | + AddAssert("ensure form is not present", () => this.ChildrenOfType<ReverseChildIDFillFlowContainer<Drawable>>().First().IsPresent, () => Is.False); |
| 67 | + AddAssert("ensure confirmation is present", () => this.ChildrenOfType<ReportPopover<ChatReportReason>.ReportConfirmation>().First().IsPresent, () => Is.True); |
| 68 | + AddUntilStep("wait for popover to hide", () => this.ChildrenOfType<ReportPopoverContainer.TestReportPopover>().First().IsPresent, () => Is.False); |
| 69 | + } |
| 70 | + |
| 71 | + [Test] |
| 72 | + public void TestFailure() |
| 73 | + { |
| 74 | + ChatReportRequest pendingRequest = null!; |
| 75 | + |
| 76 | + AddStep("setup request handling", () => |
| 77 | + { |
| 78 | + dummyAPI.HandleRequest += request => |
| 79 | + { |
| 80 | + if (request is ChatReportRequest chatReportRequest) |
| 81 | + { |
| 82 | + pendingRequest = chatReportRequest; |
| 83 | + return true; |
| 84 | + } |
| 85 | + |
| 86 | + return false; |
| 87 | + }; |
| 88 | + }); |
| 89 | + AddStep("show popover", () => popover.ShowPopover()); |
| 90 | + AddStep("input reason", () => this.ChildrenOfType<OsuTextBox>().First().Text = "reason"); |
| 91 | + AddStep("send report", () => this.ChildrenOfType<Button>().First().TriggerClick()); |
| 92 | + AddUntilStep("wait for loading layer to hide", () => this.ChildrenOfType<LoadingLayer>().First().IsPresent, () => Is.True); |
| 93 | + AddWaitStep("wait some", 3); |
| 94 | + AddStep("fail request", () => pendingRequest.TriggerFailure(new APIException("test error", new HttpRequestException("test error")))); |
| 95 | + AddUntilStep("wait for loading layer to hide", () => this.ChildrenOfType<LoadingLayer>().First().IsPresent, () => Is.False); |
| 96 | + AddAssert("ensure form is present", () => this.ChildrenOfType<ReverseChildIDFillFlowContainer<Drawable>>().First().IsPresent, () => Is.True); |
| 97 | + AddAssert("ensure error is present", () => this.ChildrenOfType<ErrorTextFlowContainer>().First().IsPresent, () => Is.True); |
| 98 | + AddAssert("ensure confirmation is not present", () => this.ChildrenOfType<ReportPopover<ChatReportReason>.ReportConfirmation>().First().IsPresent, () => Is.False); |
| 99 | + } |
| 100 | + |
| 101 | + protected partial class ReportPopoverContainer : Drawable, IHasPopover |
| 102 | + { |
| 103 | + public Popover GetPopover() => new TestReportPopover("test"); |
| 104 | + |
| 105 | + public partial class TestReportPopover : ReportPopover<ChatReportReason> |
| 106 | + { |
| 107 | + private IAPIProvider api { get; set; } = null!; |
| 108 | + |
| 109 | + public TestReportPopover(string name) |
| 110 | + : base($"Report {name}?") |
| 111 | + { |
| 112 | + } |
| 113 | + |
| 114 | + protected override APIRequest GetRequest(ChatReportReason reason, string comment) => new ChatReportRequest(1, reason, comment); |
| 115 | + } |
| 116 | + } |
| 117 | + } |
| 118 | +} |
0 commit comments