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.
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
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
|
|
|
|
|
{
|
2020-02-13 01:06:34 +00:00
|
|
|
|
public class TestSceneCommentEditor : ManualInputManagerTestScene
|
2020-02-11 15:46:49 +00:00
|
|
|
|
{
|
|
|
|
|
public override IReadOnlyList<Type> RequiredTypes => new[]
|
|
|
|
|
{
|
|
|
|
|
typeof(CommentEditor),
|
2020-02-11 17:47:51 +00:00
|
|
|
|
typeof(CancellableCommentEditor),
|
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 01:06:34 +00:00
|
|
|
|
AddStep("Click on textbox", () =>
|
2020-02-11 23:05:45 +00:00
|
|
|
|
{
|
2020-02-13 01:06:34 +00:00
|
|
|
|
InputManager.MoveMouseTo(commentEditor);
|
|
|
|
|
InputManager.Click(MouseButton.Left);
|
|
|
|
|
});
|
|
|
|
|
AddStep("Write something", () => commentEditor.Current.Value = "text");
|
|
|
|
|
AddStep("Click Enter", () => press(Key.Enter));
|
2020-02-13 19:56:34 +00:00
|
|
|
|
AddAssert("Text has been invoked", () => !string.IsNullOrEmpty(commentEditor.CommittedText));
|
2020-02-13 01:06:34 +00:00
|
|
|
|
AddAssert("Button is loading", () => commentEditor.IsLoading);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestCommitViaKeyboardWhenEmpty()
|
|
|
|
|
{
|
|
|
|
|
AddStep("Click on textbox", () =>
|
|
|
|
|
{
|
|
|
|
|
InputManager.MoveMouseTo(commentEditor);
|
|
|
|
|
InputManager.Click(MouseButton.Left);
|
2020-02-11 23:05:45 +00:00
|
|
|
|
});
|
2020-02-13 01:06:34 +00:00
|
|
|
|
AddStep("Click Enter", () => press(Key.Enter));
|
2020-02-13 19:56:34 +00:00
|
|
|
|
AddAssert("Text not invoked", () => string.IsNullOrEmpty(commentEditor.CommittedText));
|
2020-02-13 01:06:34 +00:00
|
|
|
|
AddAssert("Button is not loading", () => !commentEditor.IsLoading);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestCommitViaButton()
|
|
|
|
|
{
|
|
|
|
|
AddStep("Click on textbox", () =>
|
|
|
|
|
{
|
|
|
|
|
InputManager.MoveMouseTo(commentEditor);
|
|
|
|
|
InputManager.Click(MouseButton.Left);
|
|
|
|
|
});
|
|
|
|
|
AddStep("Write something", () => commentEditor.Current.Value = "text");
|
|
|
|
|
AddStep("Click on button", () =>
|
|
|
|
|
{
|
|
|
|
|
InputManager.MoveMouseTo(commentEditor.ButtonsContainer);
|
|
|
|
|
InputManager.Click(MouseButton.Left);
|
|
|
|
|
});
|
2020-02-13 19:56:34 +00:00
|
|
|
|
AddAssert("Text has been invoked", () => !string.IsNullOrEmpty(commentEditor.CommittedText));
|
2020-02-13 01:06:34 +00:00
|
|
|
|
AddAssert("Button is loading", () => commentEditor.IsLoading);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestCancelAction()
|
|
|
|
|
{
|
|
|
|
|
AddStep("Click on cancel button", () =>
|
|
|
|
|
{
|
|
|
|
|
InputManager.MoveMouseTo(cancellableCommentEditor.ButtonsContainer);
|
|
|
|
|
InputManager.Click(MouseButton.Left);
|
|
|
|
|
});
|
2020-02-13 19:56:34 +00:00
|
|
|
|
AddAssert("Cancel action is fired", () => cancellableCommentEditor.Cancelled);
|
2020-02-13 01:06:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void press(Key key)
|
|
|
|
|
{
|
|
|
|
|
InputManager.PressKey(key);
|
|
|
|
|
InputManager.ReleaseKey(key);
|
2020-02-11 23:05:45 +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-11 17:08:24 +00:00
|
|
|
|
protected override string TextboxPlaceholderText => @"This textbox 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-11 17:47:51 +00:00
|
|
|
|
protected override string TextboxPlaceholderText => @"Miltiline textboxes soon";
|
|
|
|
|
}
|
2020-02-11 15:46:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|