mirror of
https://github.com/ppy/osu.git
synced 2024-11-15 07:27:33 +08:00
Add basic tests for external search
This commit is contained in:
parent
cbb9f0100e
commit
5aca3a78da
@ -288,6 +288,49 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
AddAssert("no change", () => this.ChildrenOfType<ModPanel>().Count(panel => panel.Active.Value) == 2);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestApplySearchTerms()
|
||||
{
|
||||
Mod hidden = getExampleModsFor(ModType.DifficultyIncrease).Where(modState => modState.Mod is ModHidden).Select(modState => modState.Mod).Single();
|
||||
|
||||
ModColumn column = null!;
|
||||
AddStep("create content", () => Child = new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Padding = new MarginPadding(30),
|
||||
Child = column = new ModColumn(ModType.DifficultyIncrease, false)
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
AvailableMods = getExampleModsFor(ModType.DifficultyIncrease)
|
||||
}
|
||||
});
|
||||
|
||||
applySearchAndAssert(hidden.Name);
|
||||
|
||||
clearSearch();
|
||||
|
||||
applySearchAndAssert(hidden.Acronym);
|
||||
|
||||
clearSearch();
|
||||
|
||||
applySearchAndAssert(hidden.Description.ToString());
|
||||
|
||||
void applySearchAndAssert(string searchTerm)
|
||||
{
|
||||
AddStep("search by mod name", () => column.SearchTerm = searchTerm);
|
||||
|
||||
AddAssert("only hidden is visible", () => column.ChildrenOfType<ModPanel>().Where(panel => panel.IsValid).All(panel => panel.Mod is ModHidden));
|
||||
}
|
||||
|
||||
void clearSearch()
|
||||
{
|
||||
AddStep("clear search", () => column.SearchTerm = string.Empty);
|
||||
|
||||
AddAssert("all mods are visible", () => column.ChildrenOfType<ModPanel>().All(panel => panel.IsValid));
|
||||
}
|
||||
}
|
||||
|
||||
private void setFilter(Func<Mod, bool>? filter)
|
||||
{
|
||||
foreach (var modState in this.ChildrenOfType<ModColumn>().Single().AvailableMods)
|
||||
|
@ -521,8 +521,11 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
AddAssert("mod select hidden", () => modSelectOverlay.State.Value == Visibility.Hidden);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Internal search applies from code by setting <see cref="ModSelectOverlay.IsValidMod"/>
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestColumnHiding()
|
||||
public void TestColumnHidingOnInternalSearch()
|
||||
{
|
||||
AddStep("create screen", () => Child = modSelectOverlay = new TestModSelectOverlay
|
||||
{
|
||||
@ -551,6 +554,56 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
AddUntilStep("3 columns visible", () => this.ChildrenOfType<ModColumn>().Count(col => col.IsPresent) == 3);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// External search applies by user by entering search term into search bar
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestColumnHidingOnExternalSearch()
|
||||
{
|
||||
AddStep("create screen", () => Child = modSelectOverlay = new TestModSelectOverlay
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
State = { Value = Visibility.Visible },
|
||||
SelectedMods = { BindTarget = SelectedMods }
|
||||
});
|
||||
waitForColumnLoad();
|
||||
changeRuleset(0);
|
||||
|
||||
AddAssert("all columns visible", () => this.ChildrenOfType<ModColumn>().All(col => col.IsPresent));
|
||||
|
||||
AddStep("set search", () => modSelectOverlay.SearchTerm = "HD");
|
||||
AddAssert("one column visible", () => this.ChildrenOfType<ModColumn>().Count(col => col.IsPresent) == 1);
|
||||
|
||||
AddStep("filter out everything", () => modSelectOverlay.SearchTerm = "Some long search term with no matches");
|
||||
AddAssert("no columns visible", () => this.ChildrenOfType<ModColumn>().All(col => !col.IsPresent));
|
||||
|
||||
AddStep("clear search bar", () => modSelectOverlay.SearchTerm = "");
|
||||
AddAssert("all columns visible", () => this.ChildrenOfType<ModColumn>().All(col => col.IsPresent));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestHidingOverlayClearsSearch()
|
||||
{
|
||||
AddStep("create screen", () => Child = modSelectOverlay = new TestModSelectOverlay
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
State = { Value = Visibility.Visible },
|
||||
SelectedMods = { BindTarget = SelectedMods }
|
||||
});
|
||||
waitForColumnLoad();
|
||||
changeRuleset(0);
|
||||
|
||||
AddAssert("all columns visible", () => this.ChildrenOfType<ModColumn>().All(col => col.IsPresent));
|
||||
|
||||
AddStep("set search", () => modSelectOverlay.SearchTerm = "fail");
|
||||
AddAssert("one column visible", () => this.ChildrenOfType<ModColumn>().Count(col => col.IsPresent) == 2);
|
||||
|
||||
AddStep("hide", () => modSelectOverlay.Hide());
|
||||
AddStep("show", () => modSelectOverlay.Show());
|
||||
|
||||
AddAssert("all columns visible", () => this.ChildrenOfType<ModColumn>().All(col => col.IsPresent));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestColumnHidingOnRulesetChange()
|
||||
{
|
||||
@ -605,12 +658,10 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
{
|
||||
public override string ShortName => "unimplemented";
|
||||
|
||||
public override IEnumerable<Mod> GetModsFor(ModType type)
|
||||
{
|
||||
if (type == ModType.Conversion) return base.GetModsFor(type).Concat(new[] { new TestUnimplementedMod() });
|
||||
|
||||
return base.GetModsFor(type);
|
||||
}
|
||||
public override IEnumerable<Mod> GetModsFor(ModType type) =>
|
||||
type == ModType.Conversion
|
||||
? base.GetModsFor(type).Concat(new[] { new TestUnimplementedMod() })
|
||||
: base.GetModsFor(type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user