1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-18 08:52:54 +08:00
osu-lazer/osu.Game.Tests/Visual/UserInterface/TestSceneCommentEditor.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

144 lines
4.9 KiB
C#
Raw Normal View History

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.
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;
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
{
public class TestSceneCommentEditor : OsuManualInputManagerTestScene
2020-02-11 23:46:49 +08:00
{
[Cached]
private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Blue);
2020-02-13 09:06:34 +08:00
private TestCommentEditor commentEditor;
private TestCancellableCommentEditor cancellableCommentEditor;
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
{
2020-02-13 09:06:34 +08:00
InputManager.MoveMouseTo(commentEditor);
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
AddAssert("text committed", () => commentEditor.CommittedText == "text");
AddAssert("button is loading", () => commentEditor.IsLoading);
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
{
InputManager.MoveMouseTo(commentEditor);
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
AddAssert("no text committed", () => commentEditor.CommittedText == null);
AddAssert("button is not loading", () => !commentEditor.IsLoading);
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
{
InputManager.MoveMouseTo(commentEditor);
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
AddAssert("text committed", () => commentEditor.CommittedText == "some other text");
AddAssert("button is loading", () => commentEditor.IsLoading);
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
{
InputManager.MoveMouseTo(cancellableCommentEditor.ButtonsContainer);
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 class TestCommentEditor : CommentEditor
{
2020-02-13 09:06:34 +08:00
public new Bindable<string> Current => base.Current;
public new FillFlowContainer ButtonsContainer => base.ButtonsContainer;
2020-02-14 03:56:34 +08:00
public string CommittedText { get; private set; }
2020-02-11 23:46:49 +08:00
2020-02-14 03:56:34 +08:00
public TestCommentEditor()
{
OnCommit = onCommit;
}
private void onCommit(string value)
{
CommittedText = value;
Scheduler.AddDelayed(() => IsLoading = false, 1000);
}
2020-02-12 01:08:24 +08:00
2020-02-14 03:56:34 +08:00
protected override string FooterText => @"Footer text. And it is pretty long. Cool.";
protected override string CommitButtonText => @"Commit";
2020-02-14 04:04:53 +08:00
protected override string TextBoxPlaceholder => @"This text box is empty";
2020-02-11 23:46:49 +08:00
}
2020-02-12 01:47:51 +08:00
private class TestCancellableCommentEditor : CancellableCommentEditor
{
2020-02-13 09:06:34 +08:00
public new FillFlowContainer ButtonsContainer => base.ButtonsContainer;
2020-02-12 01:47:51 +08:00
protected override string FooterText => @"Wow, another one. Sicc";
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;
}
protected override string CommitButtonText => @"Save";
2020-02-14 04:04:53 +08:00
protected override string TextBoxPlaceholder => @"Multiline textboxes soon";
2020-02-12 01:47:51 +08:00
}
2020-02-11 23:46:49 +08:00
}
}