1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-16 02:23:10 +08:00

Fix test logic and add regression test

This commit is contained in:
Dean Herbert 2019-12-12 17:12:01 +09:00
parent a0792f82e8
commit c4bc57484f

View File

@ -2,15 +2,20 @@
// 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;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using osu.Framework.Allocation; using NUnit.Framework;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Game.Beatmaps;
using osu.Game.Configuration; using osu.Game.Configuration;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays.Mods; using osu.Game.Overlays.Mods;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Difficulty;
using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.UI;
namespace osu.Game.Tests.Visual.UserInterface namespace osu.Game.Tests.Visual.UserInterface
{ {
@ -18,26 +23,49 @@ namespace osu.Game.Tests.Visual.UserInterface
{ {
private TestModSelectOverlay modSelect; private TestModSelectOverlay modSelect;
[BackgroundDependencyLoader] Mod testCustomisableMod = new TestModCustomisable1();
private void load()
[Test]
public void TestButtonShowsOnCustomisableMod()
{ {
Add(modSelect = new TestModSelectOverlay createModSelect();
AddStep("open", () => modSelect.Show());
AddAssert("button disabled", () => !modSelect.CustomiseButton.Enabled.Value);
AddUntilStep("wait for button load", () => modSelect.ButtonsLoaded);
AddStep("select mod", () => modSelect.SelectMod(testCustomisableMod));
AddAssert("button enabled", () => modSelect.CustomiseButton.Enabled.Value);
AddStep("open Customisation", () => modSelect.CustomiseButton.Click());
AddStep("deselect mod", () => modSelect.SelectMod(testCustomisableMod));
AddAssert("controls hidden", () => modSelect.ModSettingsContainer.Alpha == 0);
}
[Test]
public void TestButtonShowsOnModAlreadyAdded()
{
AddStep("set active mods", () => Mods.Value = new List<Mod> { testCustomisableMod });
createModSelect();
AddAssert("mods still active", () => Mods.Value.Count == 1);
AddStep("open", () => modSelect.Show());
AddAssert("button enabled", () => modSelect.CustomiseButton.Enabled.Value);
}
private void createModSelect()
{
AddStep("create mod select", () =>
{
Ruleset.Value = new TestRulesetInfo();
Child = modSelect = new TestModSelectOverlay
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
Origin = Anchor.BottomCentre, Origin = Anchor.BottomCentre,
Anchor = Anchor.BottomCentre, Anchor = Anchor.BottomCentre,
};
}); });
var testMod = new TestModCustomisable1();
AddStep("open", modSelect.Show);
AddAssert("button disabled", () => !modSelect.CustomiseButton.Enabled.Value);
AddUntilStep("wait for button load", () => modSelect.ButtonsLoaded);
AddStep("select mod", () => modSelect.SelectMod(testMod));
AddAssert("button enabled", () => modSelect.CustomiseButton.Enabled.Value);
AddStep("open Customisation", () => modSelect.CustomiseButton.Click());
AddStep("deselect mod", () => modSelect.SelectMod(testMod));
AddAssert("controls hidden", () => modSelect.ModSettingsContainer.Alpha == 0);
} }
private class TestModSelectOverlay : ModSelectOverlay private class TestModSelectOverlay : ModSelectOverlay
@ -50,24 +78,36 @@ namespace osu.Game.Tests.Visual.UserInterface
public void SelectMod(Mod mod) => public void SelectMod(Mod mod) =>
ModSectionsContainer.Children.Single(s => s.ModType == mod.Type) ModSectionsContainer.Children.Single(s => s.ModType == mod.Type)
.ButtonsContainer.OfType<ModButton>().Single(b => b.Mods.Any(m => m.GetType() == mod.GetType())).SelectNext(1); .ButtonsContainer.OfType<ModButton>().Single(b => b.Mods.Any(m => m.GetType() == mod.GetType())).SelectNext(1);
}
protected override void LoadComplete() public class TestRulesetInfo : RulesetInfo
{ {
base.LoadComplete(); public override Ruleset CreateInstance() => new TestCustomisableModRuleset();
foreach (var section in ModSectionsContainer) public class TestCustomisableModRuleset : Ruleset
{ {
if (section.ModType == ModType.Conversion) public override IEnumerable<Mod> GetModsFor(ModType type)
{ {
section.Mods = new Mod[] if (type == ModType.Conversion)
{
return new Mod[]
{ {
new TestModCustomisable1(), new TestModCustomisable1(),
new TestModCustomisable2() new TestModCustomisable2()
}; };
} }
else
section.Mods = Array.Empty<Mod>(); return Array.Empty<Mod>();
} }
public override DrawableRuleset CreateDrawableRulesetWith(IWorkingBeatmap beatmap, IReadOnlyList<Mod> mods) => throw new NotImplementedException();
public override IBeatmapConverter CreateBeatmapConverter(IBeatmap beatmap) => throw new NotImplementedException();
public override DifficultyCalculator CreateDifficultyCalculator(WorkingBeatmap beatmap) => throw new NotImplementedException();
public override string Description { get; }
public override string ShortName { get; }
} }
} }