osu/osu.Game.Tests/Visual/UserInterface/TestSceneCommentEditor.cs

144 lines
4.9 KiB
C#
Raw Normal View History

2020-02-11 15:46:49 +00: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 01:06:34 +00:00
using NUnit.Framework;
2020-02-11 15:46:49 +00:00
using osu.Framework.Allocation;
2020-02-13 01:06:34 +00:00
using osu.Framework.Bindables;
2020-02-11 15:46:49 +00:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Overlays;
using osu.Game.Overlays.Comments;
2020-02-11 17:47:51 +00:00
using osuTK;
2020-02-13 01:06:34 +00:00
using osuTK.Input;
2020-02-11 15:46:49 +00:00
namespace osu.Game.Tests.Visual.UserInterface
{
public class TestSceneCommentEditor : OsuManualInputManagerTestScene
2020-02-11 15:46:49 +00:00
{
[Cached]
private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Blue);
2020-02-13 01:06:34 +00:00
private TestCommentEditor commentEditor;
private TestCancellableCommentEditor cancellableCommentEditor;
2020-02-11 23:05:45 +00:00
2020-02-13 19:44:02 +00:00
[SetUp]
2020-02-13 19:56:34 +00:00
public void SetUp() => Schedule(() =>
Add(new FillFlowContainer
2020-02-13 19:44:02 +00: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-13 19:56:34 +00:00
commentEditor = new TestCommentEditor(),
cancellableCommentEditor = new TestCancellableCommentEditor()
2020-02-13 19:44:02 +00:00
}
}));
2020-02-13 01:06:34 +00:00
[Test]
public void TestCommitViaKeyboard()
2020-02-11 15:46:49 +00:00
{
2020-02-13 20:01:25 +00:00
AddStep("click on text box", () =>
2020-02-11 23:05:45 +00:00
{
2020-02-13 01:06:34 +00:00
InputManager.MoveMouseTo(commentEditor);
InputManager.Click(MouseButton.Left);
});
2020-02-13 20:01:25 +00:00
AddStep("enter text", () => commentEditor.Current.Value = "text");
2020-11-05 14:41:56 +00:00
AddStep("press Enter", () => InputManager.Key(Key.Enter));
2020-02-13 20:01:25 +00:00
AddAssert("text committed", () => commentEditor.CommittedText == "text");
AddAssert("button is loading", () => commentEditor.IsLoading);
2020-02-13 01:06:34 +00:00
}
[Test]
public void TestCommitViaKeyboardWhenEmpty()
{
2020-02-13 20:01:25 +00:00
AddStep("click on text box", () =>
2020-02-13 01:06:34 +00:00
{
InputManager.MoveMouseTo(commentEditor);
InputManager.Click(MouseButton.Left);
2020-02-11 23:05:45 +00:00
});
2020-02-13 20:01:25 +00:00
2020-11-05 14:41:56 +00:00
AddStep("press Enter", () => InputManager.Key(Key.Enter));
2020-02-13 20:01:25 +00:00
AddAssert("no text committed", () => commentEditor.CommittedText == null);
AddAssert("button is not loading", () => !commentEditor.IsLoading);
2020-02-13 01:06:34 +00:00
}
[Test]
public void TestCommitViaButton()
{
2020-02-13 20:01:25 +00:00
AddStep("click on text box", () =>
2020-02-13 01:06:34 +00:00
{
InputManager.MoveMouseTo(commentEditor);
InputManager.Click(MouseButton.Left);
});
2020-02-13 20:01:25 +00:00
AddStep("enter text", () => commentEditor.Current.Value = "some other text");
AddStep("click submit", () =>
2020-02-13 01:06:34 +00:00
{
InputManager.MoveMouseTo(commentEditor.ButtonsContainer);
InputManager.Click(MouseButton.Left);
});
2020-02-13 20:01:25 +00:00
AddAssert("text committed", () => commentEditor.CommittedText == "some other text");
AddAssert("button is loading", () => commentEditor.IsLoading);
2020-02-13 01:06:34 +00:00
}
[Test]
public void TestCancelAction()
{
2020-02-13 20:01:25 +00:00
AddStep("click cancel button", () =>
2020-02-13 01:06:34 +00:00
{
InputManager.MoveMouseTo(cancellableCommentEditor.ButtonsContainer);
InputManager.Click(MouseButton.Left);
});
2020-02-13 20:01:25 +00:00
AddAssert("cancel action fired", () => cancellableCommentEditor.Cancelled);
2020-02-13 01:06:34 +00:00
}
2020-02-11 15:46:49 +00:00
private class TestCommentEditor : CommentEditor
{
2020-02-13 01:06:34 +00:00
public new Bindable<string> Current => base.Current;
public new FillFlowContainer ButtonsContainer => base.ButtonsContainer;
2020-02-13 19:56:34 +00:00
public string CommittedText { get; private set; }
2020-02-11 15:46:49 +00:00
2020-02-13 19:56:34 +00:00
public TestCommentEditor()
{
OnCommit = onCommit;
}
private void onCommit(string value)
{
CommittedText = value;
Scheduler.AddDelayed(() => IsLoading = false, 1000);
}
2020-02-11 17:08:24 +00:00
2020-02-13 19:56:34 +00:00
protected override string FooterText => @"Footer text. And it is pretty long. Cool.";
protected override string CommitButtonText => @"Commit";
2020-02-13 20:04:53 +00:00
protected override string TextBoxPlaceholder => @"This text box is empty";
2020-02-11 15:46:49 +00:00
}
2020-02-11 17:47:51 +00:00
private class TestCancellableCommentEditor : CancellableCommentEditor
{
2020-02-13 01:06:34 +00:00
public new FillFlowContainer ButtonsContainer => base.ButtonsContainer;
2020-02-11 17:47:51 +00:00
protected override string FooterText => @"Wow, another one. Sicc";
2020-02-13 19:56:34 +00:00
public bool Cancelled { get; private set; }
2020-02-11 17:47:51 +00:00
2020-02-13 19:56:34 +00:00
public TestCancellableCommentEditor()
{
OnCancel = () => Cancelled = true;
}
protected override string CommitButtonText => @"Save";
2020-02-13 20:04:53 +00:00
protected override string TextBoxPlaceholder => @"Multiline textboxes soon";
2020-02-11 17:47:51 +00:00
}
2020-02-11 15:46:49 +00:00
}
}