Improve test coverage to use existing ThemeComparisonTestScene

This commit is contained in:
Salman Ahmed
2022-05-09 21:19:34 +03:00
parent 1fcfeac05f
commit 5726cf660f

View File

@ -1,78 +1,40 @@
// 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;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Extensions.IEnumerableExtensions; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Testing; using osu.Framework.Testing;
using osu.Game.Graphics.UserInterfaceV2; using osu.Game.Graphics.UserInterfaceV2;
using osu.Game.Overlays; using osu.Game.Overlays;
using osuTK;
namespace osu.Game.Tests.Visual.UserInterface namespace osu.Game.Tests.Visual.UserInterface
{ {
public class TestSceneRoundedButton : OsuTestScene public class TestSceneRoundedButton : ThemeComparisonTestScene
{ {
[Test] private readonly BindableBool enabled = new BindableBool(true);
public void TestBasic()
protected override Drawable CreateContent() => new RoundedButton
{ {
RoundedButton button = null; Width = 400,
Text = "Test button",
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Enabled = { BindTarget = enabled },
};
AddStep("create button", () => Child = new Container [Test]
{ public void TestDisabled()
RelativeSizeAxes = Axes.Both, {
Children = new Drawable[] AddToggleStep("toggle disabled", disabled => enabled.Value = !disabled);
{
button = new RoundedButton
{
Width = 400,
Text = "Test Button",
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Action = () => { }
}
}
});
AddToggleStep("toggle disabled", disabled => button.Action = disabled ? (Action)null : () => { });
} }
[Test] [Test]
public void TestOverlay() public void TestBackgroundColour()
{ {
IEnumerable<OverlayColourScheme> schemes = Enum.GetValues(typeof(OverlayColourScheme)).Cast<OverlayColourScheme>(); AddStep("set red scheme", () => CreateThemedContent(OverlayColourScheme.Red));
AddAssert("first button has correct colour", () => Cell(0, 1).ChildrenOfType<RoundedButton>().First().BackgroundColour == new OverlayColourProvider(OverlayColourScheme.Red).Highlight1);
AddStep("create buttons", () =>
{
Child = new FillFlowContainer
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Vertical,
Spacing = new Vector2(5f),
ChildrenEnumerable = schemes.Select(c => new DependencyProvidingContainer
{
AutoSizeAxes = Axes.Both,
CachedDependencies = new (Type, object)[] { (typeof(OverlayColourProvider), new OverlayColourProvider(c)) },
Child = new RoundedButton
{
Width = 400,
Text = $"Test {c}",
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Action = () => { },
}
}),
};
});
AddAssert("first button has correct colour", () => this.ChildrenOfType<RoundedButton>().First().BackgroundColour == new OverlayColourProvider(schemes.First()).Highlight1);
AddToggleStep("toggle disabled", disabled => this.ChildrenOfType<RoundedButton>().ForEach(b => b.Action = disabled ? (Action)null : () => { }));
} }
} }
} }