mirror of
https://github.com/osukey/osukey.git
synced 2025-07-01 16:29:58 +09:00
Fix column test scene to work
This commit is contained in:
@ -1,6 +1,8 @@
|
|||||||
// 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.
|
||||||
|
|
||||||
|
#nullable enable
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
@ -12,11 +14,9 @@ using osu.Framework.Testing;
|
|||||||
using osu.Game.Graphics.UserInterface;
|
using osu.Game.Graphics.UserInterface;
|
||||||
using osu.Game.Overlays;
|
using osu.Game.Overlays;
|
||||||
using osu.Game.Overlays.Mods;
|
using osu.Game.Overlays.Mods;
|
||||||
using osu.Game.Rulesets.Catch;
|
|
||||||
using osu.Game.Rulesets.Mania;
|
|
||||||
using osu.Game.Rulesets.Mods;
|
using osu.Game.Rulesets.Mods;
|
||||||
using osu.Game.Rulesets.Osu;
|
using osu.Game.Rulesets.Osu;
|
||||||
using osu.Game.Rulesets.Taiko;
|
using osu.Game.Utils;
|
||||||
using osuTK.Input;
|
using osuTK.Input;
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual.UserInterface
|
namespace osu.Game.Tests.Visual.UserInterface
|
||||||
@ -41,20 +41,16 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
Child = new ModColumn(modType, false)
|
Child = new ModColumn(modType, false)
|
||||||
{
|
{
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Origin = Anchor.Centre
|
Origin = Anchor.Centre,
|
||||||
|
AvailableMods = getExampleModsFor(modType)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
AddStep("change ruleset to osu!", () => Ruleset.Value = new OsuRuleset().RulesetInfo);
|
|
||||||
AddStep("change ruleset to taiko", () => Ruleset.Value = new TaikoRuleset().RulesetInfo);
|
|
||||||
AddStep("change ruleset to catch", () => Ruleset.Value = new CatchRuleset().RulesetInfo);
|
|
||||||
AddStep("change ruleset to mania", () => Ruleset.Value = new ManiaRuleset().RulesetInfo);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestMultiSelection()
|
public void TestMultiSelection()
|
||||||
{
|
{
|
||||||
ModColumn column = null;
|
ModColumn column = null!;
|
||||||
AddStep("create content", () => Child = new Container
|
AddStep("create content", () => Child = new Container
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
@ -62,7 +58,8 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
Child = column = new ModColumn(ModType.DifficultyIncrease, true)
|
Child = column = new ModColumn(ModType.DifficultyIncrease, true)
|
||||||
{
|
{
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Origin = Anchor.Centre
|
Origin = Anchor.Centre,
|
||||||
|
AvailableMods = getExampleModsFor(ModType.DifficultyIncrease)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -91,7 +88,7 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestFiltering()
|
public void TestFiltering()
|
||||||
{
|
{
|
||||||
TestModColumn column = null;
|
TestModColumn column = null!;
|
||||||
|
|
||||||
AddStep("create content", () => Child = new Container
|
AddStep("create content", () => Child = new Container
|
||||||
{
|
{
|
||||||
@ -100,30 +97,31 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
Child = column = new TestModColumn(ModType.Fun, true)
|
Child = column = new TestModColumn(ModType.Fun, true)
|
||||||
{
|
{
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Origin = Anchor.Centre
|
Origin = Anchor.Centre,
|
||||||
|
AvailableMods = getExampleModsFor(ModType.Fun)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
AddStep("set filter", () => column.Filter = mod => mod.Name.Contains("Wind", StringComparison.CurrentCultureIgnoreCase));
|
AddStep("set filter", () => setFilter(mod => mod.Name.Contains("Wind", StringComparison.CurrentCultureIgnoreCase)));
|
||||||
AddUntilStep("two panels visible", () => column.ChildrenOfType<ModPanel>().Count(panel => !panel.Filtered.Value) == 2);
|
AddUntilStep("two panels visible", () => column.ChildrenOfType<ModPanel>().Count(panel => !panel.Filtered.Value) == 2);
|
||||||
|
|
||||||
clickToggle();
|
clickToggle();
|
||||||
AddUntilStep("wait for animation", () => !column.SelectionAnimationRunning);
|
AddUntilStep("wait for animation", () => !column.SelectionAnimationRunning);
|
||||||
AddAssert("only visible items selected", () => column.ChildrenOfType<ModPanel>().Where(panel => panel.Active.Value).All(panel => !panel.Filtered.Value));
|
AddAssert("only visible items selected", () => column.ChildrenOfType<ModPanel>().Where(panel => panel.Active.Value).All(panel => !panel.Filtered.Value));
|
||||||
|
|
||||||
AddStep("unset filter", () => column.Filter = null);
|
AddStep("unset filter", () => setFilter(null));
|
||||||
AddUntilStep("all panels visible", () => column.ChildrenOfType<ModPanel>().All(panel => !panel.Filtered.Value));
|
AddUntilStep("all panels visible", () => column.ChildrenOfType<ModPanel>().All(panel => !panel.Filtered.Value));
|
||||||
AddAssert("checkbox not selected", () => !column.ChildrenOfType<OsuCheckbox>().Single().Current.Value);
|
AddAssert("checkbox not selected", () => !column.ChildrenOfType<OsuCheckbox>().Single().Current.Value);
|
||||||
|
|
||||||
AddStep("set filter", () => column.Filter = mod => mod.Name.Contains("Wind", StringComparison.CurrentCultureIgnoreCase));
|
AddStep("set filter", () => setFilter(mod => mod.Name.Contains("Wind", StringComparison.CurrentCultureIgnoreCase)));
|
||||||
AddUntilStep("two panels visible", () => column.ChildrenOfType<ModPanel>().Count(panel => !panel.Filtered.Value) == 2);
|
AddUntilStep("two panels visible", () => column.ChildrenOfType<ModPanel>().Count(panel => !panel.Filtered.Value) == 2);
|
||||||
AddAssert("checkbox selected", () => column.ChildrenOfType<OsuCheckbox>().Single().Current.Value);
|
AddAssert("checkbox selected", () => column.ChildrenOfType<OsuCheckbox>().Single().Current.Value);
|
||||||
|
|
||||||
AddStep("filter out everything", () => column.Filter = _ => false);
|
AddStep("filter out everything", () => setFilter(_ => false));
|
||||||
AddUntilStep("no panels visible", () => column.ChildrenOfType<ModPanel>().All(panel => panel.Filtered.Value));
|
AddUntilStep("no panels visible", () => column.ChildrenOfType<ModPanel>().All(panel => panel.Filtered.Value));
|
||||||
AddUntilStep("checkbox hidden", () => !column.ChildrenOfType<OsuCheckbox>().Single().IsPresent);
|
AddUntilStep("checkbox hidden", () => !column.ChildrenOfType<OsuCheckbox>().Single().IsPresent);
|
||||||
|
|
||||||
AddStep("inset filter", () => column.Filter = null);
|
AddStep("inset filter", () => setFilter(null));
|
||||||
AddUntilStep("all panels visible", () => column.ChildrenOfType<ModPanel>().All(panel => !panel.Filtered.Value));
|
AddUntilStep("all panels visible", () => column.ChildrenOfType<ModPanel>().All(panel => !panel.Filtered.Value));
|
||||||
AddUntilStep("checkbox visible", () => column.ChildrenOfType<OsuCheckbox>().Single().IsPresent);
|
AddUntilStep("checkbox visible", () => column.ChildrenOfType<OsuCheckbox>().Single().IsPresent);
|
||||||
|
|
||||||
@ -138,7 +136,7 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestKeyboardSelection()
|
public void TestKeyboardSelection()
|
||||||
{
|
{
|
||||||
ModColumn column = null;
|
ModColumn column = null!;
|
||||||
AddStep("create content", () => Child = new Container
|
AddStep("create content", () => Child = new Container
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
@ -146,7 +144,8 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
Child = column = new ModColumn(ModType.DifficultyReduction, true, new[] { Key.Q, Key.W, Key.E, Key.R, Key.T, Key.Y, Key.U, Key.I, Key.O, Key.P })
|
Child = column = new ModColumn(ModType.DifficultyReduction, true, new[] { Key.Q, Key.W, Key.E, Key.R, Key.T, Key.Y, Key.U, Key.I, Key.O, Key.P })
|
||||||
{
|
{
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Origin = Anchor.Centre
|
Origin = Anchor.Centre,
|
||||||
|
AvailableMods = getExampleModsFor(ModType.DifficultyReduction)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -158,7 +157,7 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
AddStep("press W again", () => InputManager.Key(Key.W));
|
AddStep("press W again", () => InputManager.Key(Key.W));
|
||||||
AddAssert("NF panel deselected", () => !this.ChildrenOfType<ModPanel>().Single(panel => panel.Mod.Acronym == "NF").Active.Value);
|
AddAssert("NF panel deselected", () => !this.ChildrenOfType<ModPanel>().Single(panel => panel.Mod.Acronym == "NF").Active.Value);
|
||||||
|
|
||||||
AddStep("set filter to NF", () => column.Filter = mod => mod.Acronym == "NF");
|
AddStep("set filter to NF", () => setFilter(mod => mod.Acronym == "NF"));
|
||||||
|
|
||||||
AddStep("press W", () => InputManager.Key(Key.W));
|
AddStep("press W", () => InputManager.Key(Key.W));
|
||||||
AddAssert("NF panel selected", () => this.ChildrenOfType<ModPanel>().Single(panel => panel.Mod.Acronym == "NF").Active.Value);
|
AddAssert("NF panel selected", () => this.ChildrenOfType<ModPanel>().Single(panel => panel.Mod.Acronym == "NF").Active.Value);
|
||||||
@ -166,12 +165,18 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
AddStep("press W again", () => InputManager.Key(Key.W));
|
AddStep("press W again", () => InputManager.Key(Key.W));
|
||||||
AddAssert("NF panel deselected", () => !this.ChildrenOfType<ModPanel>().Single(panel => panel.Mod.Acronym == "NF").Active.Value);
|
AddAssert("NF panel deselected", () => !this.ChildrenOfType<ModPanel>().Single(panel => panel.Mod.Acronym == "NF").Active.Value);
|
||||||
|
|
||||||
AddStep("filter out everything", () => column.Filter = _ => false);
|
AddStep("filter out everything", () => setFilter(_ => false));
|
||||||
|
|
||||||
AddStep("press W", () => InputManager.Key(Key.W));
|
AddStep("press W", () => InputManager.Key(Key.W));
|
||||||
AddAssert("NF panel not selected", () => !this.ChildrenOfType<ModPanel>().Single(panel => panel.Mod.Acronym == "NF").Active.Value);
|
AddAssert("NF panel not selected", () => !this.ChildrenOfType<ModPanel>().Single(panel => panel.Mod.Acronym == "NF").Active.Value);
|
||||||
|
|
||||||
AddStep("clear filter", () => column.Filter = null);
|
AddStep("clear filter", () => setFilter(null));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setFilter(Func<Mod, bool>? filter)
|
||||||
|
{
|
||||||
|
foreach (var modState in this.ChildrenOfType<ModColumn>().Single().AvailableMods)
|
||||||
|
modState.Filtered.Value = filter?.Invoke(modState.Mod) == false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private class TestModColumn : ModColumn
|
private class TestModColumn : ModColumn
|
||||||
@ -183,5 +188,13 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static ModState[] getExampleModsFor(ModType modType)
|
||||||
|
{
|
||||||
|
return new OsuRuleset().GetModsFor(modType)
|
||||||
|
.SelectMany(ModUtils.FlattenMod)
|
||||||
|
.Select(mod => new ModState(mod))
|
||||||
|
.ToArray();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user