Add testing for customisation panel show/hide logic

This commit is contained in:
Bartłomiej Dach 2022-03-26 23:21:17 +01:00
parent 293ef44836
commit e46c2df409
No known key found for this signature in database
GPG Key ID: BCECCD4FA41F6497
2 changed files with 63 additions and 15 deletions

View File

@ -1,28 +1,76 @@
// 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 System.Linq;
using NUnit.Framework;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Testing;
using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays.Mods;
using osu.Game.Rulesets.Osu.Mods;
using osuTK.Input;
namespace osu.Game.Tests.Visual.UserInterface
{
[TestFixture]
public class TestSceneModSelectScreen : OsuTestScene
public class TestSceneModSelectScreen : OsuManualInputManagerTestScene
{
[Test]
public void TestModSelectScreen()
{
ModSelectScreen modSelectScreen = null;
private ModSelectScreen modSelectScreen;
[SetUpSteps]
public void SetUpSteps()
{
AddStep("create screen", () => Child = modSelectScreen = new ModSelectScreen
{
RelativeSizeAxes = Axes.Both,
State = { Value = Visibility.Visible }
State = { Value = Visibility.Visible },
SelectedMods = { BindTarget = SelectedMods }
});
}
[Test]
public void TestStateChange()
{
AddToggleStep("toggle state", visible => modSelectScreen.State.Value = visible ? Visibility.Visible : Visibility.Hidden);
}
[Test]
public void TestCustomisationToggleState()
{
assertCustomisationToggleState(disabled: true, active: false);
AddStep("select customisable mod", () => SelectedMods.Value = new[] { new OsuModDoubleTime() });
assertCustomisationToggleState(disabled: false, active: false);
AddStep("select mod requiring configuration", () => SelectedMods.Value = new[] { new OsuModDifficultyAdjust() });
assertCustomisationToggleState(disabled: false, active: true);
AddStep("dismiss mod customisation", () =>
{
InputManager.MoveMouseTo(modSelectScreen.ChildrenOfType<ShearedToggleButton>().Single());
InputManager.Click(MouseButton.Left);
});
AddToggleStep("toggle state", visible => modSelectScreen.State.Value = visible ? Visibility.Visible : Visibility.Hidden);
AddStep("append another mod not requiring config", () => SelectedMods.Value = SelectedMods.Value.Append(new OsuModFlashlight()).ToArray());
assertCustomisationToggleState(disabled: false, active: false);
AddStep("select mod without configuration", () => SelectedMods.Value = new[] { new OsuModAutoplay() });
assertCustomisationToggleState(disabled: true, active: false);
AddStep("select mod requiring configuration", () => SelectedMods.Value = new[] { new OsuModDifficultyAdjust() });
assertCustomisationToggleState(disabled: false, active: true);
AddStep("select mod without configuration", () => SelectedMods.Value = new[] { new OsuModAutoplay() });
assertCustomisationToggleState(disabled: true, active: false); // config was dismissed without explicit user action.
}
private void assertCustomisationToggleState(bool disabled, bool active)
{
ShearedToggleButton getToggle() => modSelectScreen.ChildrenOfType<ShearedToggleButton>().Single();
AddAssert($"customisation toggle is {(disabled ? "" : "not ")}disabled", () => getToggle().Active.Disabled == disabled);
AddAssert($"customisation toggle is {(active ? "" : "not ")}active", () => getToggle().Active.Value == active);
}
}
}

View File

@ -27,7 +27,7 @@ namespace osu.Game.Overlays.Mods
private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Green);
[Cached]
private Bindable<IReadOnlyList<Mod>> selectedMods = new Bindable<IReadOnlyList<Mod>>(Array.Empty<Mod>());
public Bindable<IReadOnlyList<Mod>> SelectedMods { get; private set; } = new Bindable<IReadOnlyList<Mod>>(Array.Empty<Mod>());
private readonly BindableBool customisationVisible = new BindableBool();
@ -169,9 +169,9 @@ namespace osu.Game.Overlays.Mods
foreach (var column in columnFlow)
{
column.ModStateChanged = (mod, active) => selectedMods.Value = active
? selectedMods.Value.Append(mod).ToArray()
: selectedMods.Value.Except(new[] { mod }).ToArray();
column.ModStateChanged = (mod, active) => SelectedMods.Value = active
? SelectedMods.Value.Append(mod).ToArray()
: SelectedMods.Value.Except(new[] { mod }).ToArray();
}
columnFlow.Shear = new Vector2(ModPanel.SHEAR_X, 0);
@ -181,8 +181,8 @@ namespace osu.Game.Overlays.Mods
{
base.LoadComplete();
((IBindable<IReadOnlyList<Mod>>)modSettingsArea.SelectedMods).BindTo(selectedMods);
selectedMods.BindValueChanged(val =>
((IBindable<IReadOnlyList<Mod>>)modSettingsArea.SelectedMods).BindTo(SelectedMods);
SelectedMods.BindValueChanged(val =>
{
updateMultiplier();
updateCustomisation(val);
@ -196,7 +196,7 @@ namespace osu.Game.Overlays.Mods
{
double multiplier = 1.0;
foreach (var mod in selectedMods.Value)
foreach (var mod in SelectedMods.Value)
multiplier *= mod.ScoreMultiplier;
multiplierDisplay.Current.Value = multiplier;
@ -207,7 +207,7 @@ namespace osu.Game.Overlays.Mods
bool anyCustomisableMod = false;
bool anyModWithRequiredCustomisationAdded = false;
foreach (var mod in selectedMods.Value)
foreach (var mod in SelectedMods.Value)
{
anyCustomisableMod |= mod.GetSettingsSourceProperties().Any();
anyModWithRequiredCustomisationAdded |= !valueChangedEvent.OldValue.Contains(mod) && mod.RequiresConfiguration;