Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions osu.Game.Tests/Visual/Online/TestSceneChatOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input;
using osu.Framework.Logging;
using osu.Framework.Testing;
using osu.Game.Configuration;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
Expand All @@ -40,6 +41,7 @@ namespace osu.Game.Tests.Visual.Online
public partial class TestSceneChatOverlay : OsuManualInputManagerTestScene
{
private TestChatOverlay chatOverlay;
private DialogOverlay dialogOverlay;
private ChannelManager channelManager;

private readonly APIUser testUser = new APIUser { Username = "test user", Id = 5071479 };
Expand Down Expand Up @@ -72,11 +74,13 @@ public void SetUp() => Schedule(() =>
CachedDependencies = new (Type, object)[]
{
(typeof(ChannelManager), channelManager = new ChannelManager(API)),
(typeof(IDialogOverlay), dialogOverlay = new DialogOverlay())
},
Children = new Drawable[]
{
channelManager,
chatOverlay = new TestChatOverlay(),
dialogOverlay,
},
};
});
Expand Down Expand Up @@ -694,36 +698,46 @@ public void TestChatReport()
};
});

AddStep("Show report popover", () => this.ChildrenOfType<ChatLine>().First().ShowPopover());
AddStep("Open context menu", () =>
{
var username = this.ChildrenOfType<DrawableChatUsername>().First().ChildrenOfType<TruncatingSpriteText>().First();
InputManager.MoveMouseTo(username);
InputManager.Click(MouseButton.Right);
});
AddStep("Select report option", () =>
{
InputManager.MoveMouseTo(this.ChildrenOfType<Menu.DrawableMenuItem>().First(m => m.Item.Text.ToString() == "Report"));
InputManager.Click(MouseButton.Left);
});

AddStep("Set report reason to other", () =>
{
var reason = this.ChildrenOfType<OsuEnumDropdown<ChatReportReason>>().Single();
var reason = this.ChildrenOfType<FormEnumDropdown<ChatReportReason>>().Single();
reason.Current.Value = ChatReportReason.Other;
});

AddStep("Try to report", () =>
{
var btn = this.ChildrenOfType<ReportChatPopover>().Single().ChildrenOfType<RoundedButton>().Single();
var btn = this.ChildrenOfType<ReportChatDialog.SubmitButton>().Single();
InputManager.MoveMouseTo(btn);
InputManager.Click(MouseButton.Left);
});

AddAssert("Nothing happened", () => this.ChildrenOfType<ReportChatPopover>().Any());
AddAssert("Nothing happened", () => this.ChildrenOfType<ReportChatDialog>().Any());
AddStep("Set report data", () =>
{
var field = this.ChildrenOfType<ReportChatPopover>().Single().ChildrenOfType<OsuTextBox>().First();
var field = this.ChildrenOfType<ReportChatDialog>().Single().ChildrenOfType<OsuTextBox>().First();
field.Current.Value = "test other";
});

AddStep("Try to report", () =>
{
var btn = this.ChildrenOfType<ReportChatPopover>().Single().ChildrenOfType<RoundedButton>().Single();
var btn = this.ChildrenOfType<ReportChatDialog.SubmitButton>().Single();
InputManager.MoveMouseTo(btn);
InputManager.Click(MouseButton.Left);
});

AddUntilStep("Overlay closed", () => !this.ChildrenOfType<ReportChatPopover>().Any());
AddUntilStep("Overlay closed", () => !this.ChildrenOfType<ReportChatDialog>().Any());
AddStep("Complete request", () => requestLock.Set());
AddUntilStep("Request sent", () => request != null);
AddUntilStep("Info message displayed", () => channelManager.CurrentChannel.Value.Messages.Last(), () => Is.InstanceOf(typeof(InfoMessage)));
Expand Down
12 changes: 6 additions & 6 deletions osu.Game.Tests/Visual/Online/TestSceneCommentActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,30 +255,30 @@ public void TestReport()
});
AddStep("Set reason to other", () =>
{
var reason = this.ChildrenOfType<OsuEnumDropdown<CommentReportReason>>().Single();
var reason = this.ChildrenOfType<FormEnumDropdown<CommentReportReason>>().Single();
reason.Current.Value = CommentReportReason.Other;
});
AddStep("Try to report", () =>
{
var btn = this.ChildrenOfType<ReportCommentPopover>().Single().ChildrenOfType<RoundedButton>().Single();
var btn = this.ChildrenOfType<ReportCommentDialog.SubmitButton>().First();
InputManager.MoveMouseTo(btn);
InputManager.Click(MouseButton.Left);
});
AddWaitStep("Wait", 3);
AddAssert("Nothing happened", () => this.ChildrenOfType<ReportCommentPopover>().Any());
AddAssert("Nothing happened", () => this.ChildrenOfType<ReportCommentDialog>().Any());
AddStep("Add comment", () =>
{
var field = this.ChildrenOfType<ReportCommentPopover>().Single().ChildrenOfType<OsuTextBox>().First();
var field = this.ChildrenOfType<ReportCommentDialog>().Single().ChildrenOfType<OsuTextBox>().First();
field.Current.Value = report_text;
});
AddStep("Try to report", () =>
{
var btn = this.ChildrenOfType<ReportCommentPopover>().Single().ChildrenOfType<RoundedButton>().Single();
var btn = this.ChildrenOfType<ReportCommentDialog.SubmitButton>().First();
InputManager.MoveMouseTo(btn);
InputManager.Click(MouseButton.Left);
});
AddWaitStep("Wait", 3);
AddAssert("Overlay closed", () => !this.ChildrenOfType<ReportCommentPopover>().Any());
AddAssert("Overlay closed", () => !this.ChildrenOfType<ReportCommentDialog>().Any());
AddAssert("Loading spinner shown", () => targetComment.ChildrenOfType<LoadingSpinner>().Any(d => d.IsPresent));
AddStep("Complete request", () => requestLock.Set());
AddUntilStep("Request sent", () => request != null);
Expand Down
39 changes: 30 additions & 9 deletions osu.Game.Tests/Visual/Online/TestSceneCommentReportButton.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
// 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 osu.Framework.Extensions;
using System;
using System.Linq;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Testing;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Overlays;
using osu.Game.Overlays.Comments;
using osu.Game.Tests.Visual.UserInterface;
using osuTK;
using osuTK.Input;

namespace osu.Game.Tests.Visual.Online
{
public partial class TestSceneCommentReportButton : ThemeComparisonTestScene
{
private DialogOverlay dialogOverlay = null!;

public TestSceneCommentReportButton()
: base(false)
{
}

[SetUpSteps]
public void SetUpSteps()
{
Expand All @@ -32,15 +41,27 @@ public void SetUpSteps()
});
}

protected override Drawable CreateContent() => new PopoverContainer
protected override Drawable CreateContent() => new DependencyProvidingContainer
{
RelativeSizeAxes = Axes.Both,
Child = new CommentReportButton(new Comment { User = new APIUser { Username = "Someone" } })
CachedDependencies = new (Type, object)[]
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Scale = new Vector2(2f),
}.With(b => Schedule(b.ShowPopover)),
};
(typeof(IDialogOverlay), dialogOverlay = new DialogOverlay()),
},
Children = new Drawable[]
{
new CommentReportButton(new Comment { User = new APIUser { Username = "Someone" } })
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Scale = new Vector2(2f),
},
dialogOverlay,
}
}.With(c => c.OnLoadComplete += _ =>
{
InputManager.MoveMouseTo(c.ChildrenOfType<CommentReportButton>().First());
InputManager.Click(MouseButton.Left);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,32 @@
using System.Linq;
using System.Net.Http;
using NUnit.Framework;
using osu.Framework.Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Testing;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.UserInterface;
using osu.Game.Graphics.UserInterfaceV2;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Overlays;
using osu.Game.Overlays.Chat;
using osu.Game.Overlays.Settings;
using osu.Game.Resources.Localisation.Web;

namespace osu.Game.Tests.Visual.Online
{
public partial class TestSceneReportPopover : OsuTestScene
public partial class TestSceneReportDialog : OsuTestScene
{
private DummyAPIAccess dummyAPI => (DummyAPIAccess)API;
private DialogOverlay dialogOverlay = null!;

private ReportPopoverContainer popover = null!;
private DummyAPIAccess dummyAPI => (DummyAPIAccess)API;

[SetUpSteps]
public void SetUp()
{
AddStep("create popover", () =>
AddStep("create dialog overlay", () =>
{
Child = new PopoverContainer
{
RelativeSizeAxes = Axes.Both,
Child = popover = new ReportPopoverContainer(),
};
Child = dialogOverlay = new DialogOverlay();
});
}

Expand All @@ -56,16 +51,23 @@ public void TestSuccess()
return false;
};
});
AddStep("show popover", () => popover.ShowPopover());
AddStep("push dialog", () => dialogOverlay.Push(new TestReportDialog("test")));

AddStep("try to report", () => dialogOverlay.CurrentDialog!.PerformAction<TestReportDialog.SubmitButton>());
AddWaitStep("wait", 3);
AddAssert("nothing happened", () => dialogOverlay.CurrentDialog!.ChildrenOfType<LoadingLayer>().First().IsReadOnly, () => Is.False);

AddStep("input reason", () => this.ChildrenOfType<OsuTextBox>().First().Text = "reason");
AddStep("send report", () => this.ChildrenOfType<Button>().First().TriggerClick());
AddUntilStep("wait for loading layer to hide", () => this.ChildrenOfType<LoadingLayer>().First().IsPresent, () => Is.True);
AddStep("send report", () => dialogOverlay.CurrentDialog!.PerformAction<TestReportDialog.SubmitButton>());

AddUntilStep("wait for loading layer to show", () => this.ChildrenOfType<LoadingLayer>().First().IsPresent, () => Is.True);
AddWaitStep("wait some", 3);
AddStep("complete request", () => pendingRequest.TriggerSuccess());
AddUntilStep("wait for loading layer to hide", () => this.ChildrenOfType<LoadingLayer>().First().IsPresent, () => Is.False);

AddAssert("ensure form is not present", () => this.ChildrenOfType<ReverseChildIDFillFlowContainer<Drawable>>().First().IsPresent, () => Is.False);
AddAssert("ensure confirmation is present", () => this.ChildrenOfType<ReportPopover<ChatReportReason>.ReportConfirmation>().First().IsPresent, () => Is.True);
AddUntilStep("wait for popover to hide", () => this.ChildrenOfType<ReportPopoverContainer.TestReportPopover>().First().IsPresent, () => Is.False);
AddAssert("ensure header text is updated", () => dialogOverlay.CurrentDialog!.HeaderText, () => Is.EqualTo(UsersStrings.ReportThanks));
AddUntilStep("wait for dialog to hide", () => this.ChildrenOfType<TestReportDialog>().Any(), () => Is.False);
}

[Test]
Expand All @@ -86,33 +88,29 @@ public void TestFailure()
return false;
};
});
AddStep("show popover", () => popover.ShowPopover());
AddStep("push dialog", () => dialogOverlay.Push(new TestReportDialog("test")));

AddStep("input reason", () => this.ChildrenOfType<OsuTextBox>().First().Text = "reason");
AddStep("send report", () => this.ChildrenOfType<Button>().First().TriggerClick());
AddUntilStep("wait for loading layer to hide", () => this.ChildrenOfType<LoadingLayer>().First().IsPresent, () => Is.True);
AddStep("send report", () => dialogOverlay.CurrentDialog!.PerformAction<TestReportDialog.SubmitButton>());

AddUntilStep("wait for loading layer to show", () => this.ChildrenOfType<LoadingLayer>().First().IsPresent, () => Is.True);
AddWaitStep("wait some", 3);
AddStep("fail request", () => pendingRequest.TriggerFailure(new APIException("test error", new HttpRequestException("test error"))));
AddUntilStep("wait for loading layer to hide", () => this.ChildrenOfType<LoadingLayer>().First().IsPresent, () => Is.False);

AddAssert("ensure form is present", () => this.ChildrenOfType<ReverseChildIDFillFlowContainer<Drawable>>().First().IsPresent, () => Is.True);
AddAssert("ensure error is present", () => this.ChildrenOfType<ErrorTextFlowContainer>().First().IsPresent, () => Is.True);
AddAssert("ensure confirmation is not present", () => this.ChildrenOfType<ReportPopover<ChatReportReason>.ReportConfirmation>().First().IsPresent, () => Is.False);
AddAssert("ensure error is present", () => this.ChildrenOfType<SettingsNote>().First().Current.Value?.Text.ToString(), () => Is.EqualTo("test error"));
AddAssert("ensure header text is not updated", () => dialogOverlay.CurrentDialog!.HeaderText.ToString(), () => Is.EqualTo("Report test?"));
}

protected partial class ReportPopoverContainer : Drawable, IHasPopover
public partial class TestReportDialog : ReportDialog<ChatReportReason>
{
public Popover GetPopover() => new TestReportPopover("test");

public partial class TestReportPopover : ReportPopover<ChatReportReason>
public TestReportDialog(string name)
: base($"Report {name}?")
{
private IAPIProvider api { get; set; } = null!;

public TestReportPopover(string name)
: base($"Report {name}?")
{
}

protected override APIRequest GetRequest(ChatReportReason reason, string comment) => new ChatReportRequest(1, reason, comment);
}

protected override APIRequest GetRequest(ChatReportReason reason, string comment) => new ChatReportRequest(1, reason, comment);
}
}
}
35 changes: 35 additions & 0 deletions osu.Game.Tests/Visual/UserInterface/TestScenePopupDialog.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
// 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.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Testing;
using osu.Game.Graphics;
using osu.Game.Overlays.Dialog;
using osuTK;
using osuTK.Input;
Expand Down Expand Up @@ -47,14 +51,25 @@ public void TestDangerousButton([Values(false, true)] bool atEdge)

AddStep("hold button", () => InputManager.PressButton(MouseButton.Left));
AddUntilStep("action invoked", () => dialog.DangerousButtonInvoked);
AddAssert("dialog is hidden", () => dialog.State.Value, () => Is.EqualTo(Visibility.Hidden));
AddStep("release button", () => InputManager.ReleaseButton(MouseButton.Left));
}

[Test]
public void TestHideDialogBeforeInvoke()
{
AddStep("move mouse to button", () => InputManager.MoveMouseTo(dialog.ChildrenOfType<NonHideButton>().First()));
AddStep("click button", () => InputManager.Click(MouseButton.Left));
AddAssert("action invoked", () => dialog.NonHideActionInvoked, () => Is.True);
AddAssert("dialog is still visible", () => dialog.State.Value, () => Is.EqualTo(Visibility.Visible));
}

private partial class TestPopupDialog : PopupDialog
{
public PopupDialogDangerousButton DangerousButton { get; }

public bool DangerousButtonInvoked;
public bool NonHideActionInvoked;

public TestPopupDialog()
{
Expand All @@ -78,8 +93,28 @@ public TestPopupDialog()
Text = @"Careful with this one..",
Action = () => DangerousButtonInvoked = true,
},
new NonHideButton
{
Action = () => NonHideActionInvoked = true,
},
};
}
}

private partial class NonHideButton : PopupDialogButton
{
public override bool HideDialogBeforeInvoke => false;

public NonHideButton()
{
Text = @"This button will not hide the dialog!";
}

[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
ButtonColour = colours.Yellow;
}
}
}
}
2 changes: 1 addition & 1 deletion osu.Game/Graphics/UserInterfaceV2/FormTextBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public CompositeDrawable? TabbableContentContainer

public event TextBox.OnCommitHandler? OnCommit;

private readonly BindableWithCurrent<string> current = new BindableWithCurrent<string>();
private readonly BindableWithCurrent<string> current = new BindableWithCurrent<string>(string.Empty);

/// <summary>
/// Caption describing this slider bar, displayed on top of the controls.
Expand Down
Loading
Loading