2020-06-05 03:45:42 +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.
|
|
|
|
|
2021-10-17 10:36:21 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
2020-06-05 03:45:42 +00:00
|
|
|
using NUnit.Framework;
|
2021-10-17 10:36:21 +00:00
|
|
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
2020-06-05 03:45:42 +00:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2021-10-17 10:36:21 +00:00
|
|
|
using osu.Framework.Testing;
|
2020-06-05 03:45:42 +00:00
|
|
|
using osu.Game.Graphics.UserInterface;
|
2021-10-17 10:36:21 +00:00
|
|
|
using osu.Game.Overlays;
|
2020-06-05 03:45:42 +00:00
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.UserInterface
|
|
|
|
{
|
2021-10-17 10:36:21 +00:00
|
|
|
public class TestSceneOsuTextBox : ThemeComparisonTestScene
|
2020-06-05 03:45:42 +00:00
|
|
|
{
|
2021-10-17 10:36:21 +00:00
|
|
|
private IEnumerable<OsuNumberBox> numberBoxes => this.ChildrenOfType<OsuNumberBox>();
|
2020-06-05 03:45:42 +00:00
|
|
|
|
2021-10-17 10:36:21 +00:00
|
|
|
protected override Drawable CreateContent() => new FillFlowContainer
|
2020-06-05 03:45:42 +00:00
|
|
|
{
|
2021-10-17 10:36:21 +00:00
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
Padding = new MarginPadding(50f),
|
|
|
|
Spacing = new Vector2(0f, 50f),
|
|
|
|
Children = new[]
|
2020-06-05 03:45:42 +00:00
|
|
|
{
|
2021-10-17 10:36:21 +00:00
|
|
|
new OsuTextBox
|
2020-06-05 03:45:42 +00:00
|
|
|
{
|
2021-10-17 10:36:21 +00:00
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
PlaceholderText = "Normal textbox",
|
|
|
|
},
|
|
|
|
new OsuPasswordTextBox
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
PlaceholderText = "Password textbox",
|
|
|
|
},
|
|
|
|
new OsuNumberBox
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
PlaceholderText = "Number textbox"
|
2020-06-05 03:45:42 +00:00
|
|
|
}
|
2021-10-17 10:36:21 +00:00
|
|
|
}
|
|
|
|
};
|
2020-06-05 03:45:42 +00:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestNumberBox()
|
|
|
|
{
|
2021-10-17 10:36:21 +00:00
|
|
|
AddStep("create themed content", () => CreateThemedContent(OverlayColourScheme.Red));
|
|
|
|
|
|
|
|
clearTextboxes(numberBoxes);
|
|
|
|
AddStep("enter numbers", () => numberBoxes.ForEach(numberBox => numberBox.Text = "987654321"));
|
|
|
|
expectedValue(numberBoxes, "987654321");
|
2020-06-05 03:45:42 +00:00
|
|
|
|
2021-10-17 10:36:21 +00:00
|
|
|
clearTextboxes(numberBoxes);
|
|
|
|
AddStep("enter text + single number", () => numberBoxes.ForEach(numberBox => numberBox.Text = "1 hello 2 world 3"));
|
|
|
|
expectedValue(numberBoxes, "123");
|
2020-06-05 03:45:42 +00:00
|
|
|
|
2021-10-17 10:36:21 +00:00
|
|
|
clearTextboxes(numberBoxes);
|
2020-06-05 03:45:42 +00:00
|
|
|
}
|
|
|
|
|
2021-10-17 10:36:21 +00:00
|
|
|
private void clearTextboxes(IEnumerable<OsuTextBox> textBoxes) => AddStep("clear textbox", () => textBoxes.ForEach(textBox => textBox.Text = null));
|
2021-12-10 05:15:00 +00:00
|
|
|
private void expectedValue(IEnumerable<OsuTextBox> textBoxes, string value) => AddAssert("expected textbox value", () => textBoxes.All(textBox => textBox.Text == value));
|
2020-06-05 03:45:42 +00:00
|
|
|
}
|
|
|
|
}
|