Fix test failures by waiting for panel load

This commit is contained in:
Bartłomiej Dach 2022-02-28 21:36:13 +01:00
parent 42b27e3050
commit 6cc972aa6a
No known key found for this signature in database
GPG Key ID: BCECCD4FA41F6497
2 changed files with 19 additions and 3 deletions

View File

@ -54,17 +54,20 @@ namespace osu.Game.Tests.Visual.UserInterface
[Test] [Test]
public void TestMultiSelection() public void TestMultiSelection()
{ {
ModColumn column = null;
AddStep("create content", () => Child = new Container AddStep("create content", () => Child = new Container
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding(30), Padding = new MarginPadding(30),
Child = new ModColumn(ModType.DifficultyIncrease, true) Child = column = new ModColumn(ModType.DifficultyIncrease, true)
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre Origin = Anchor.Centre
} }
}); });
AddUntilStep("wait for panel load", () => column.IsLoaded && column.ItemsLoaded);
clickToggle(); clickToggle();
AddUntilStep("all panels selected", () => this.ChildrenOfType<ModPanel>().All(panel => panel.Active.Value)); AddUntilStep("all panels selected", () => this.ChildrenOfType<ModPanel>().All(panel => panel.Active.Value));
@ -140,13 +143,15 @@ namespace osu.Game.Tests.Visual.UserInterface
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding(30), Padding = new MarginPadding(30),
Child = column = new ModColumn(ModType.DifficultyReduction, true, new Key[] { 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
} }
}); });
AddUntilStep("wait for panel load", () => column.IsLoaded && column.ItemsLoaded);
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);

View File

@ -5,6 +5,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks;
using Humanizer; using Humanizer;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
@ -56,6 +57,9 @@ namespace osu.Game.Overlays.Mods
private Colour4 accentColour; private Colour4 accentColour;
private Task? latestLoadTask;
internal bool ItemsLoaded => latestLoadTask == null;
private const float header_height = 42; private const float header_height = 42;
public ModColumn(ModType modType, bool allowBulkSelection, Key[]? toggleKeys = null) public ModColumn(ModType modType, bool allowBulkSelection, Key[]? toggleKeys = null)
@ -234,7 +238,9 @@ namespace osu.Game.Overlays.Mods
Shear = new Vector2(-ModPanel.SHEAR_X, 0) Shear = new Vector2(-ModPanel.SHEAR_X, 0)
}); });
LoadComponentsAsync(panels, loaded => Task? loadTask;
latestLoadTask = loadTask = LoadComponentsAsync(panels, loaded =>
{ {
panelFlow.ChildrenEnumerable = loaded; panelFlow.ChildrenEnumerable = loaded;
@ -244,6 +250,11 @@ namespace osu.Game.Overlays.Mods
updateFilter(); updateFilter();
}, (cancellationTokenSource = new CancellationTokenSource()).Token); }, (cancellationTokenSource = new CancellationTokenSource()).Token);
loadTask.ContinueWith(_ =>
{
if (loadTask == latestLoadTask)
latestLoadTask = null;
});
} }
#region Bulk select / deselect #region Bulk select / deselect