Modify OsuTextBox test scene to test against colour provider

This commit is contained in:
Bartłomiej Dach 2021-10-17 12:36:21 +02:00
parent e9a35cbe7e
commit a7f3beabe3
No known key found for this signature in database
GPG Key ID: BCECCD4FA41F6497
2 changed files with 42 additions and 55 deletions

View File

@ -1,39 +1,27 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes; using osu.Framework.Testing;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays;
using osuTK; using osuTK;
using osuTK.Graphics;
namespace osu.Game.Tests.Visual.UserInterface namespace osu.Game.Tests.Visual.UserInterface
{ {
public class TestSceneOsuTextBox : OsuTestScene public class TestSceneOsuTextBox : ThemeComparisonTestScene
{ {
private readonly OsuNumberBox numberBox; private IEnumerable<OsuNumberBox> numberBoxes => this.ChildrenOfType<OsuNumberBox>();
public TestSceneOsuTextBox() protected override Drawable CreateContent() => new FillFlowContainer
{ {
Child = new Container RelativeSizeAxes = Axes.X,
{ AutoSizeAxes = Axes.Y,
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, Direction = FillDirection.Vertical,
Padding = new MarginPadding(50f), Padding = new MarginPadding(50f),
Spacing = new Vector2(0f, 50f), Spacing = new Vector2(0f, 50f),
@ -41,40 +29,39 @@ namespace osu.Game.Tests.Visual.UserInterface
{ {
new OsuTextBox new OsuTextBox
{ {
Width = 500f, RelativeSizeAxes = Axes.X,
PlaceholderText = "Normal textbox", PlaceholderText = "Normal textbox",
}, },
new OsuPasswordTextBox new OsuPasswordTextBox
{ {
Width = 500f, RelativeSizeAxes = Axes.X,
PlaceholderText = "Password textbox", PlaceholderText = "Password textbox",
}, },
numberBox = new OsuNumberBox new OsuNumberBox
{ {
Width = 500f, RelativeSizeAxes = Axes.X,
PlaceholderText = "Number textbox" PlaceholderText = "Number textbox"
} }
} }
}
}
}; };
}
[Test] [Test]
public void TestNumberBox() public void TestNumberBox()
{ {
clearTextbox(numberBox); AddStep("create themed content", () => CreateThemedContent(OverlayColourScheme.Red));
AddStep("enter numbers", () => numberBox.Text = "987654321");
expectedValue(numberBox, "987654321");
clearTextbox(numberBox); clearTextboxes(numberBoxes);
AddStep("enter text + single number", () => numberBox.Text = "1 hello 2 world 3"); AddStep("enter numbers", () => numberBoxes.ForEach(numberBox => numberBox.Text = "987654321"));
expectedValue(numberBox, "123"); expectedValue(numberBoxes, "987654321");
clearTextbox(numberBox); clearTextboxes(numberBoxes);
AddStep("enter text + single number", () => numberBoxes.ForEach(numberBox => numberBox.Text = "1 hello 2 world 3"));
expectedValue(numberBoxes, "123");
clearTextboxes(numberBoxes);
} }
private void clearTextbox(OsuTextBox textBox) => AddStep("clear textbox", () => textBox.Text = null); private void clearTextboxes(IEnumerable<OsuTextBox> textBoxes) => AddStep("clear textbox", () => textBoxes.ForEach(textBox => textBox.Text = null));
private void expectedValue(OsuTextBox textBox, string value) => AddAssert("expected textbox value", () => textBox.Text == value); private void expectedValue(IEnumerable<OsuTextBox> textBoxes, string value) => AddAssert("expected textbox value", () => textBoxes.All(textbox => textbox.Text == value));
} }
} }

View File

@ -33,7 +33,7 @@ namespace osu.Game.Tests.Visual.UserInterface
}); });
} }
private void createThemedContent(OverlayColourScheme colourScheme) protected void CreateThemedContent(OverlayColourScheme colourScheme)
{ {
var colourProvider = new OverlayColourProvider(colourScheme); var colourProvider = new OverlayColourProvider(colourScheme);
@ -63,7 +63,7 @@ namespace osu.Game.Tests.Visual.UserInterface
public void TestAllColourSchemes() public void TestAllColourSchemes()
{ {
foreach (var scheme in Enum.GetValues(typeof(OverlayColourScheme)).Cast<OverlayColourScheme>()) foreach (var scheme in Enum.GetValues(typeof(OverlayColourScheme)).Cast<OverlayColourScheme>())
AddStep($"set {scheme} scheme", () => createThemedContent(scheme)); AddStep($"set {scheme} scheme", () => CreateThemedContent(scheme));
} }
} }
} }