2022-11-15 20:07:05 +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.
|
|
|
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2022-11-16 06:51:57 +08:00
|
|
|
using osu.Game.Graphics.UserInterface;
|
2022-11-15 23:12:24 +08:00
|
|
|
using osuTK.Input;
|
2022-11-15 20:07:05 +08:00
|
|
|
|
2022-11-17 17:18:17 +08:00
|
|
|
namespace osu.Game.Tests.Visual.UserInterface
|
2022-11-15 20:07:05 +08:00
|
|
|
{
|
|
|
|
[TestFixture]
|
2022-11-17 17:18:17 +08:00
|
|
|
public class TestSceneHistoryTextBox : OsuManualInputManagerTestScene
|
2022-11-15 20:07:05 +08:00
|
|
|
{
|
2022-11-17 17:18:17 +08:00
|
|
|
private const string temp = "Temp message";
|
2022-11-15 20:07:05 +08:00
|
|
|
|
2022-11-16 20:12:43 +08:00
|
|
|
private int messageCounter;
|
|
|
|
|
2022-11-19 23:53:35 +08:00
|
|
|
private HistoryTextBox box = null!;
|
|
|
|
private OsuSpriteText text = null!;
|
2022-11-17 17:18:17 +08:00
|
|
|
|
2022-11-15 20:07:05 +08:00
|
|
|
[SetUp]
|
|
|
|
public void SetUp()
|
|
|
|
{
|
|
|
|
Schedule(() =>
|
|
|
|
{
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
2022-11-16 06:51:57 +08:00
|
|
|
box = new HistoryTextBox(5)
|
2022-11-15 20:07:05 +08:00
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
Width = 0.99f,
|
|
|
|
},
|
|
|
|
text = new OsuSpriteText
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
Width = 0.99f,
|
|
|
|
Y = -box.Height,
|
|
|
|
Font = OsuFont.Default.With(size: 20),
|
|
|
|
}
|
|
|
|
};
|
2022-11-15 23:12:24 +08:00
|
|
|
|
2022-11-17 18:35:13 +08:00
|
|
|
box.OnCommit += (_, _) =>
|
2022-11-15 20:07:05 +08:00
|
|
|
{
|
2022-11-17 17:18:17 +08:00
|
|
|
if (string.IsNullOrEmpty(box.Text))
|
|
|
|
return;
|
|
|
|
|
2022-11-15 20:07:05 +08:00
|
|
|
text.Text = $"{nameof(box.OnCommit)}: {box.Text}";
|
|
|
|
box.Text = string.Empty;
|
|
|
|
box.TakeFocus();
|
|
|
|
text.FadeOutFromOne(1000, Easing.InQuint);
|
|
|
|
};
|
2022-11-15 23:12:24 +08:00
|
|
|
|
2022-11-16 20:12:43 +08:00
|
|
|
messageCounter = 0;
|
|
|
|
|
2022-11-15 23:12:24 +08:00
|
|
|
box.TakeFocus();
|
2022-11-15 20:07:05 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-11-23 02:47:41 +08:00
|
|
|
[Test]
|
|
|
|
public void TestEmptyHistory()
|
|
|
|
{
|
|
|
|
AddStep("Set text", () => box.Text = temp);
|
|
|
|
|
|
|
|
AddStep("Move down", () => InputManager.Key(Key.Down));
|
|
|
|
AddAssert("Text is unchanged", () => box.Text == temp);
|
|
|
|
|
|
|
|
AddStep("Move up", () => InputManager.Key(Key.Up));
|
|
|
|
AddAssert("Text is unchanged", () => box.Text == temp);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestPartialHistory()
|
|
|
|
{
|
|
|
|
addMessages(3);
|
|
|
|
AddStep("Set text", () => box.Text = temp);
|
|
|
|
|
|
|
|
AddStep("Move down", () => InputManager.Key(Key.Down));
|
|
|
|
AddAssert("Text is unchanged", () => box.Text == temp);
|
|
|
|
|
|
|
|
AddRepeatStep("Move up", () => InputManager.Key(Key.Up), 3);
|
|
|
|
AddAssert("Same as 1st message", () => box.Text == "Message 1");
|
|
|
|
|
|
|
|
AddStep("Move up", () => InputManager.Key(Key.Up));
|
|
|
|
AddAssert("Same as 1st message", () => box.Text == "Message 1");
|
|
|
|
|
|
|
|
AddStep("Move down", () => InputManager.Key(Key.Down));
|
|
|
|
AddAssert("Same as 2nd message", () => box.Text == "Message 2");
|
|
|
|
|
|
|
|
AddRepeatStep("Move down", () => InputManager.Key(Key.Down), 2);
|
|
|
|
AddAssert("Temporary message restored", () => box.Text == temp);
|
|
|
|
|
|
|
|
AddStep("Move down", () => InputManager.Key(Key.Down));
|
|
|
|
AddAssert("Text is unchanged", () => box.Text == temp);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestFullHistory()
|
|
|
|
{
|
|
|
|
addMessages(7);
|
|
|
|
AddStep("Set text", () => box.Text = temp);
|
|
|
|
|
|
|
|
AddStep("Move down", () => InputManager.Key(Key.Down));
|
|
|
|
AddAssert("Text is unchanged", () => box.Text == temp);
|
|
|
|
|
|
|
|
AddRepeatStep("Move up", () => InputManager.Key(Key.Up), 5);
|
|
|
|
AddAssert("Same as 3rd message", () => box.Text == "Message 3");
|
|
|
|
|
|
|
|
AddStep("Move up", () => InputManager.Key(Key.Up));
|
|
|
|
AddAssert("Same as 3rd message", () => box.Text == "Message 3");
|
|
|
|
|
|
|
|
AddRepeatStep("Move down", () => InputManager.Key(Key.Down), 4);
|
|
|
|
AddAssert("Same as 7th message", () => box.Text == "Message 7");
|
|
|
|
|
|
|
|
AddStep("Move down", () => InputManager.Key(Key.Down));
|
|
|
|
AddAssert("Temporary message restored", () => box.Text == temp);
|
|
|
|
|
|
|
|
AddStep("Move down", () => InputManager.Key(Key.Down));
|
|
|
|
AddAssert("Text is unchanged", () => box.Text == temp);
|
|
|
|
}
|
|
|
|
|
2022-11-16 06:51:57 +08:00
|
|
|
[Test]
|
2022-11-21 16:32:44 +08:00
|
|
|
public void TestChangedHistory()
|
2022-11-16 06:51:57 +08:00
|
|
|
{
|
2022-11-21 16:32:44 +08:00
|
|
|
addMessages(2);
|
2022-11-16 06:51:57 +08:00
|
|
|
AddStep("Set text", () => box.Text = temp);
|
2022-11-21 16:32:44 +08:00
|
|
|
AddStep("Move up", () => InputManager.Key(Key.Up));
|
2022-11-16 06:51:57 +08:00
|
|
|
|
2022-11-21 16:32:44 +08:00
|
|
|
AddStep("Change text", () => box.Text = "New message");
|
2022-11-16 06:51:57 +08:00
|
|
|
AddStep("Move down", () => InputManager.Key(Key.Down));
|
2022-11-21 16:32:44 +08:00
|
|
|
AddStep("Move up", () => InputManager.Key(Key.Up));
|
2022-11-21 16:43:36 +08:00
|
|
|
AddAssert("Changes lost", () => box.Text == "Message 2");
|
2022-11-16 06:51:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2022-11-21 16:32:44 +08:00
|
|
|
public void TestInputOnEdge()
|
2022-11-16 06:51:57 +08:00
|
|
|
{
|
|
|
|
addMessages(2);
|
|
|
|
AddStep("Set text", () => box.Text = temp);
|
|
|
|
|
|
|
|
AddStep("Move down", () => InputManager.Key(Key.Down));
|
2022-11-21 16:32:44 +08:00
|
|
|
AddAssert("Text unchanged", () => box.Text == temp);
|
2022-11-16 06:51:57 +08:00
|
|
|
|
2022-11-21 16:32:44 +08:00
|
|
|
AddRepeatStep("Move up", () => InputManager.Key(Key.Up), 2);
|
2022-11-16 06:51:57 +08:00
|
|
|
AddAssert("Same as 1st message", () => box.Text == "Message 1");
|
|
|
|
|
2022-11-21 16:32:44 +08:00
|
|
|
AddStep("Move up", () => InputManager.Key(Key.Up));
|
|
|
|
AddAssert("Text unchanged", () => box.Text == "Message 1");
|
2022-11-16 06:51:57 +08:00
|
|
|
}
|
|
|
|
|
2022-11-15 20:07:05 +08:00
|
|
|
[Test]
|
2022-11-16 20:12:43 +08:00
|
|
|
public void TestResetIndex()
|
2022-11-15 20:07:05 +08:00
|
|
|
{
|
2022-11-15 23:12:24 +08:00
|
|
|
addMessages(2);
|
|
|
|
|
2022-11-16 20:12:43 +08:00
|
|
|
AddRepeatStep("Move Up", () => InputManager.Key(Key.Up), 2);
|
|
|
|
AddAssert("Same as 1st message", () => box.Text == "Message 1");
|
2022-11-15 20:07:05 +08:00
|
|
|
|
2022-11-21 17:17:28 +08:00
|
|
|
AddStep("Change text", () => box.Text = "New message");
|
2022-11-21 17:11:26 +08:00
|
|
|
AddStep("Move Up", () => InputManager.Key(Key.Up));
|
|
|
|
AddAssert("Same as previous message", () => box.Text == "Message 2");
|
2022-11-15 23:12:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void addMessages(int count)
|
|
|
|
{
|
|
|
|
AddRepeatStep("Add messages", () =>
|
|
|
|
{
|
2022-11-16 20:12:43 +08:00
|
|
|
box.Text = $"Message {++messageCounter}";
|
2022-11-15 23:12:24 +08:00
|
|
|
InputManager.Key(Key.Enter);
|
|
|
|
}, count);
|
2022-11-15 20:07:05 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|