2020-02-11 23:46:49 +08:00
|
|
|
|
// 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.
|
|
|
|
|
|
2022-11-30 18:58:03 +08:00
|
|
|
|
using System.Linq;
|
2020-02-13 09:06:34 +08:00
|
|
|
|
using NUnit.Framework;
|
2020-02-11 23:46:49 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2020-02-13 09:06:34 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2020-02-11 23:46:49 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2022-11-30 18:58:03 +08:00
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2022-11-29 10:13:54 +08:00
|
|
|
|
using osu.Framework.Localisation;
|
2022-11-30 18:58:03 +08:00
|
|
|
|
using osu.Framework.Testing;
|
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2020-02-11 23:46:49 +08:00
|
|
|
|
using osu.Game.Overlays;
|
|
|
|
|
using osu.Game.Overlays.Comments;
|
2020-02-12 01:47:51 +08:00
|
|
|
|
using osuTK;
|
2020-02-13 09:06:34 +08:00
|
|
|
|
using osuTK.Input;
|
2020-02-11 23:46:49 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.UserInterface
|
|
|
|
|
{
|
2020-03-23 09:01:33 +08:00
|
|
|
|
public partial class TestSceneCommentEditor : OsuManualInputManagerTestScene
|
2020-02-11 23:46:49 +08:00
|
|
|
|
{
|
|
|
|
|
[Cached]
|
|
|
|
|
private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Blue);
|
|
|
|
|
|
2022-11-29 10:17:44 +08:00
|
|
|
|
private TestCommentEditor commentEditor = null!;
|
|
|
|
|
private TestCancellableCommentEditor cancellableCommentEditor = null!;
|
2020-02-12 07:05:45 +08:00
|
|
|
|
|
2020-02-14 03:44:02 +08:00
|
|
|
|
[SetUp]
|
2020-02-14 03:56:34 +08:00
|
|
|
|
public void SetUp() => Schedule(() =>
|
|
|
|
|
Add(new FillFlowContainer
|
2020-02-14 03:44:02 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Width = 800,
|
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
|
Spacing = new Vector2(0, 20),
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2020-02-14 03:56:34 +08:00
|
|
|
|
commentEditor = new TestCommentEditor(),
|
|
|
|
|
cancellableCommentEditor = new TestCancellableCommentEditor()
|
2020-02-14 03:44:02 +08:00
|
|
|
|
}
|
|
|
|
|
}));
|
|
|
|
|
|
2020-02-13 09:06:34 +08:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestCommitViaKeyboard()
|
2020-02-11 23:46:49 +08:00
|
|
|
|
{
|
2020-02-14 04:01:25 +08:00
|
|
|
|
AddStep("click on text box", () =>
|
2020-02-12 07:05:45 +08:00
|
|
|
|
{
|
2022-11-30 18:58:03 +08:00
|
|
|
|
InputManager.MoveMouseTo(commentEditor.ChildrenOfType<TextBox>().Single());
|
2020-02-13 09:06:34 +08:00
|
|
|
|
InputManager.Click(MouseButton.Left);
|
|
|
|
|
});
|
2020-02-14 04:01:25 +08:00
|
|
|
|
AddStep("enter text", () => commentEditor.Current.Value = "text");
|
|
|
|
|
|
2020-11-05 22:41:56 +08:00
|
|
|
|
AddStep("press Enter", () => InputManager.Key(Key.Enter));
|
2020-02-14 04:01:25 +08:00
|
|
|
|
|
2023-01-10 04:37:36 +08:00
|
|
|
|
AddUntilStep("button is loading", () => commentEditor.IsSpinnerShown);
|
2020-02-14 04:01:25 +08:00
|
|
|
|
AddAssert("text committed", () => commentEditor.CommittedText == "text");
|
2023-01-10 04:37:36 +08:00
|
|
|
|
AddUntilStep("button is not loading", () => !commentEditor.IsSpinnerShown);
|
2020-02-13 09:06:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestCommitViaKeyboardWhenEmpty()
|
|
|
|
|
{
|
2020-02-14 04:01:25 +08:00
|
|
|
|
AddStep("click on text box", () =>
|
2020-02-13 09:06:34 +08:00
|
|
|
|
{
|
2022-11-30 18:58:03 +08:00
|
|
|
|
InputManager.MoveMouseTo(commentEditor.ChildrenOfType<TextBox>().Single());
|
2020-02-13 09:06:34 +08:00
|
|
|
|
InputManager.Click(MouseButton.Left);
|
2020-02-12 07:05:45 +08:00
|
|
|
|
});
|
2020-02-14 04:01:25 +08:00
|
|
|
|
|
2020-11-05 22:41:56 +08:00
|
|
|
|
AddStep("press Enter", () => InputManager.Key(Key.Enter));
|
2020-02-14 04:01:25 +08:00
|
|
|
|
|
2023-01-10 04:37:36 +08:00
|
|
|
|
AddAssert("button is not loading", () => !commentEditor.IsSpinnerShown);
|
2022-11-29 19:20:38 +08:00
|
|
|
|
AddAssert("no text committed", () => commentEditor.CommittedText.Length == 0);
|
2020-02-13 09:06:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestCommitViaButton()
|
|
|
|
|
{
|
2020-02-14 04:01:25 +08:00
|
|
|
|
AddStep("click on text box", () =>
|
2020-02-13 09:06:34 +08:00
|
|
|
|
{
|
2022-11-30 18:58:03 +08:00
|
|
|
|
InputManager.MoveMouseTo(commentEditor.ChildrenOfType<TextBox>().Single());
|
2020-02-13 09:06:34 +08:00
|
|
|
|
InputManager.Click(MouseButton.Left);
|
|
|
|
|
});
|
2020-02-14 04:01:25 +08:00
|
|
|
|
AddStep("enter text", () => commentEditor.Current.Value = "some other text");
|
|
|
|
|
|
|
|
|
|
AddStep("click submit", () =>
|
2020-02-13 09:06:34 +08:00
|
|
|
|
{
|
|
|
|
|
InputManager.MoveMouseTo(commentEditor.ButtonsContainer);
|
|
|
|
|
InputManager.Click(MouseButton.Left);
|
|
|
|
|
});
|
2020-02-14 04:01:25 +08:00
|
|
|
|
|
2023-01-10 04:37:36 +08:00
|
|
|
|
AddUntilStep("button is loading", () => commentEditor.IsSpinnerShown);
|
2020-02-14 04:01:25 +08:00
|
|
|
|
AddAssert("text committed", () => commentEditor.CommittedText == "some other text");
|
2023-01-10 04:37:36 +08:00
|
|
|
|
AddUntilStep("button is not loading", () => !commentEditor.IsSpinnerShown);
|
2020-02-13 09:06:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestCancelAction()
|
|
|
|
|
{
|
2020-02-14 04:01:25 +08:00
|
|
|
|
AddStep("click cancel button", () =>
|
2020-02-13 09:06:34 +08:00
|
|
|
|
{
|
2022-11-30 18:30:00 +08:00
|
|
|
|
InputManager.MoveMouseTo(cancellableCommentEditor.ButtonsContainer[1]);
|
2020-02-13 09:06:34 +08:00
|
|
|
|
InputManager.Click(MouseButton.Left);
|
|
|
|
|
});
|
2020-02-14 04:01:25 +08:00
|
|
|
|
|
|
|
|
|
AddAssert("cancel action fired", () => cancellableCommentEditor.Cancelled);
|
2020-02-13 09:06:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-11 23:46:49 +08:00
|
|
|
|
private partial class TestCommentEditor : CommentEditor
|
|
|
|
|
{
|
2020-02-13 09:06:34 +08:00
|
|
|
|
public new Bindable<string> Current => base.Current;
|
|
|
|
|
public new FillFlowContainer ButtonsContainer => base.ButtonsContainer;
|
|
|
|
|
|
2022-11-29 19:20:38 +08:00
|
|
|
|
public string CommittedText { get; private set; } = string.Empty;
|
2020-02-11 23:46:49 +08:00
|
|
|
|
|
2023-01-10 04:37:36 +08:00
|
|
|
|
public bool IsSpinnerShown => this.ChildrenOfType<LoadingSpinner>().Single().IsPresent;
|
2022-11-30 18:58:03 +08:00
|
|
|
|
|
2023-01-07 03:51:57 +08:00
|
|
|
|
protected override void OnCommit(string value)
|
2020-02-14 03:56:34 +08:00
|
|
|
|
{
|
2023-01-10 04:37:36 +08:00
|
|
|
|
ShowLoadingSpinner = true;
|
2020-02-14 03:56:34 +08:00
|
|
|
|
CommittedText = value;
|
2023-01-10 04:37:36 +08:00
|
|
|
|
Scheduler.AddDelayed(() => ShowLoadingSpinner = false, 1000);
|
2020-02-14 03:56:34 +08:00
|
|
|
|
}
|
2020-02-12 01:08:24 +08:00
|
|
|
|
|
2022-11-29 10:13:54 +08:00
|
|
|
|
protected override LocalisableString FooterText => @"Footer text. And it is pretty long. Cool.";
|
|
|
|
|
protected override LocalisableString CommitButtonText => @"Commit";
|
|
|
|
|
protected override LocalisableString TextBoxPlaceholder => @"This text box is empty";
|
2020-02-11 23:46:49 +08:00
|
|
|
|
}
|
2020-02-12 01:47:51 +08:00
|
|
|
|
|
|
|
|
|
private partial class TestCancellableCommentEditor : CancellableCommentEditor
|
|
|
|
|
{
|
2020-02-13 09:06:34 +08:00
|
|
|
|
public new FillFlowContainer ButtonsContainer => base.ButtonsContainer;
|
2023-01-07 03:51:57 +08:00
|
|
|
|
|
2022-11-29 10:13:54 +08:00
|
|
|
|
protected override LocalisableString FooterText => @"Wow, another one. Sicc";
|
2020-02-12 01:47:51 +08:00
|
|
|
|
|
2020-02-14 03:56:34 +08:00
|
|
|
|
public bool Cancelled { get; private set; }
|
2020-02-12 01:47:51 +08:00
|
|
|
|
|
2020-02-14 03:56:34 +08:00
|
|
|
|
public TestCancellableCommentEditor()
|
|
|
|
|
{
|
|
|
|
|
OnCancel = () => Cancelled = true;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-07 03:51:57 +08:00
|
|
|
|
protected override void OnCommit(string text)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-29 10:13:54 +08:00
|
|
|
|
protected override LocalisableString CommitButtonText => @"Save";
|
|
|
|
|
protected override LocalisableString TextBoxPlaceholder => @"Multiline textboxes soon";
|
2020-02-12 01:47:51 +08:00
|
|
|
|
}
|
2020-02-11 23:46:49 +08:00
|
|
|
|
}
|
|
|
|
|
}
|