Expand number text box test scene to one holding all OsuTextBox's types

This commit is contained in:
Salman Ahmed 2020-06-05 06:45:42 +03:00
parent 178bbf16d1
commit 495f89ddae
No known key found for this signature in database
GPG Key ID: ED81FD33FD9B58BC
2 changed files with 80 additions and 48 deletions

View File

@ -1,48 +0,0 @@
// 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.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Graphics.UserInterface;
namespace osu.Game.Tests.Visual.UserInterface
{
[TestFixture]
public class TestSceneNumberBox : OsuTestScene
{
private OsuNumberBox numberBox;
[BackgroundDependencyLoader]
private void load()
{
Child = new Container
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.X,
Padding = new MarginPadding { Horizontal = 250 },
Child = numberBox = new OsuNumberBox
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.X,
PlaceholderText = "Insert numbers here"
}
};
clearInput();
AddStep("enter numbers", () => numberBox.Text = "987654321");
expectedValue("987654321");
clearInput();
AddStep("enter text + single number", () => numberBox.Text = "1 hello 2 world 3");
expectedValue("123");
clearInput();
}
private void clearInput() => AddStep("clear input", () => numberBox.Text = null);
private void expectedValue(string value) => AddAssert("expect number", () => numberBox.Text == value);
}
}

View File

@ -0,0 +1,80 @@
// 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.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics.UserInterface;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Tests.Visual.UserInterface
{
public class TestSceneOsuTextBox : OsuTestScene
{
private readonly OsuNumberBox numberBox;
public TestSceneOsuTextBox()
{
Child = new Container
{
Masking = true,
CornerRadius = 10f,
AutoSizeAxes = Axes.Both,
Padding = new MarginPadding(15f),
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.DarkSlateGray,
Alpha = 0.75f,
},
new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Vertical,
Padding = new MarginPadding(50f),
Spacing = new Vector2(0f, 50f),
Children = new[]
{
new OsuTextBox
{
Width = 500f,
PlaceholderText = "Normal textbox",
},
new OsuPasswordTextBox
{
Width = 500f,
PlaceholderText = "Password textbox",
},
numberBox = new OsuNumberBox
{
Width = 500f,
PlaceholderText = "Number textbox"
}
}
}
}
};
}
[Test]
public void TestNumberBox()
{
clearTextbox(numberBox);
AddStep("enter numbers", () => numberBox.Text = "987654321");
expectedValue(numberBox, "987654321");
clearTextbox(numberBox);
AddStep("enter text + single number", () => numberBox.Text = "1 hello 2 world 3");
expectedValue(numberBox, "123");
clearTextbox(numberBox);
}
private void clearTextbox(OsuTextBox textBox) => AddStep("clear textbox", () => textBox.Text = null);
private void expectedValue(OsuTextBox textBox, string value) => AddAssert("expected textbox value", () => textBox.Text == value);
}
}