From a7f3beabe3561d371e248025f62532f0541e7cd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Sun, 17 Oct 2021 12:36:21 +0200 Subject: [PATCH] Modify `OsuTextBox` test scene to test against colour provider --- .../UserInterface/TestSceneOsuTextBox.cs | 93 ++++++++----------- .../UserInterface/ThemeComparisonTestScene.cs | 4 +- 2 files changed, 42 insertions(+), 55 deletions(-) diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneOsuTextBox.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneOsuTextBox.cs index 756928d3ec..fc1866cdf3 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneOsuTextBox.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneOsuTextBox.cs @@ -1,80 +1,67 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System.Collections.Generic; +using System.Linq; using NUnit.Framework; +using osu.Framework.Extensions.IEnumerableExtensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.Shapes; +using osu.Framework.Testing; using osu.Game.Graphics.UserInterface; +using osu.Game.Overlays; using osuTK; -using osuTK.Graphics; namespace osu.Game.Tests.Visual.UserInterface { - public class TestSceneOsuTextBox : OsuTestScene + public class TestSceneOsuTextBox : ThemeComparisonTestScene { - private readonly OsuNumberBox numberBox; + private IEnumerable numberBoxes => this.ChildrenOfType(); - public TestSceneOsuTextBox() + protected override Drawable CreateContent() => new FillFlowContainer { - Child = new Container + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + Direction = FillDirection.Vertical, + Padding = new MarginPadding(50f), + Spacing = new Vector2(0f, 50f), + Children = new[] { - Masking = true, - CornerRadius = 10f, - AutoSizeAxes = Axes.Both, - Padding = new MarginPadding(15f), - Children = new Drawable[] + new OsuTextBox { - 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" - } - } - } + RelativeSizeAxes = Axes.X, + PlaceholderText = "Normal textbox", + }, + new OsuPasswordTextBox + { + RelativeSizeAxes = Axes.X, + PlaceholderText = "Password textbox", + }, + new OsuNumberBox + { + RelativeSizeAxes = Axes.X, + PlaceholderText = "Number textbox" } - }; - } + } + }; [Test] public void TestNumberBox() { - clearTextbox(numberBox); - AddStep("enter numbers", () => numberBox.Text = "987654321"); - expectedValue(numberBox, "987654321"); + AddStep("create themed content", () => CreateThemedContent(OverlayColourScheme.Red)); - clearTextbox(numberBox); - AddStep("enter text + single number", () => numberBox.Text = "1 hello 2 world 3"); - expectedValue(numberBox, "123"); + clearTextboxes(numberBoxes); + AddStep("enter numbers", () => numberBoxes.ForEach(numberBox => numberBox.Text = "987654321")); + 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 expectedValue(OsuTextBox textBox, string value) => AddAssert("expected textbox value", () => textBox.Text == value); + private void clearTextboxes(IEnumerable textBoxes) => AddStep("clear textbox", () => textBoxes.ForEach(textBox => textBox.Text = null)); + private void expectedValue(IEnumerable textBoxes, string value) => AddAssert("expected textbox value", () => textBoxes.All(textbox => textbox.Text == value)); } } diff --git a/osu.Game.Tests/Visual/UserInterface/ThemeComparisonTestScene.cs b/osu.Game.Tests/Visual/UserInterface/ThemeComparisonTestScene.cs index f8b9e8223b..db1c90f287 100644 --- a/osu.Game.Tests/Visual/UserInterface/ThemeComparisonTestScene.cs +++ b/osu.Game.Tests/Visual/UserInterface/ThemeComparisonTestScene.cs @@ -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); @@ -63,7 +63,7 @@ namespace osu.Game.Tests.Visual.UserInterface public void TestAllColourSchemes() { foreach (var scheme in Enum.GetValues(typeof(OverlayColourScheme)).Cast()) - AddStep($"set {scheme} scheme", () => createThemedContent(scheme)); + AddStep($"set {scheme} scheme", () => CreateThemedContent(scheme)); } } }