1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-19 15:02:54 +08:00

Attempt to fix tests

This commit is contained in:
Dean Herbert 2019-06-21 00:12:39 +09:00
parent 7b4180ce86
commit fa263b91a7
2 changed files with 26 additions and 6 deletions

View File

@ -216,13 +216,13 @@ namespace osu.Game.Tests.Visual.UserInterface
private void testRankedText(Mod mod) private void testRankedText(Mod mod)
{ {
AddWaitStep("wait for fade", 1); waitForLoad();
AddAssert("check for ranked", () => modSelect.UnrankedLabel.Alpha == 0); AddAssert("check for ranked", () => modSelect.UnrankedLabel.Alpha == 0);
selectNext(mod); selectNext(mod);
AddWaitStep("wait for fade", 1); waitForLoad();
AddAssert("check for unranked", () => modSelect.UnrankedLabel.Alpha != 0); AddAssert("check for unranked", () => modSelect.UnrankedLabel.Alpha != 0);
selectPrevious(mod); selectPrevious(mod);
AddWaitStep("wait for fade", 1); waitForLoad();
AddAssert("check for ranked", () => modSelect.UnrankedLabel.Alpha == 0); AddAssert("check for ranked", () => modSelect.UnrankedLabel.Alpha == 0);
} }
@ -232,15 +232,22 @@ namespace osu.Game.Tests.Visual.UserInterface
private void checkSelected(Mod mod) private void checkSelected(Mod mod)
{ {
AddUntilStep($"check {mod.Name} is selected", () => waitForLoad();
AddAssert($"check {mod.Name} is selected", () =>
{ {
var button = modSelect.GetModButton(mod); var button = modSelect.GetModButton(mod);
return modSelect.SelectedMods.Value.SingleOrDefault(m => m.Name == mod.Name) != null && button.SelectedMod.GetType() == mod.GetType() && button.Selected; return modSelect.SelectedMods.Value.Single(m => m.Name == mod.Name) != null && button.SelectedMod.GetType() == mod.GetType() && button.Selected;
}); });
} }
private void waitForLoad()
{
AddAssert("wait for icons to load", () => modSelect.AllLoaded);
}
private void checkNotSelected(Mod mod) private void checkNotSelected(Mod mod)
{ {
waitForLoad();
AddAssert($"check {mod.Name} is not selected", () => AddAssert($"check {mod.Name} is not selected", () =>
{ {
var button = modSelect.GetModButton(mod); var button = modSelect.GetModButton(mod);
@ -254,6 +261,8 @@ namespace osu.Game.Tests.Visual.UserInterface
{ {
public new Bindable<IReadOnlyList<Mod>> SelectedMods => base.SelectedMods; public new Bindable<IReadOnlyList<Mod>> SelectedMods => base.SelectedMods;
public bool AllLoaded => ModSectionsContainer.Children.All(c => c.ModIconsLoaded);
public ModButton GetModButton(Mod mod) public ModButton GetModButton(Mod mod)
{ {
var section = ModSectionsContainer.Children.Single(s => s.ModType == mod.Type); var section = ModSectionsContainer.Children.Single(s => s.ModType == mod.Type);

View File

@ -36,6 +36,11 @@ namespace osu.Game.Overlays.Mods
private CancellationTokenSource modsLoadCts; private CancellationTokenSource modsLoadCts;
/// <summary>
/// True when all mod icons have completed loading.
/// </summary>
public bool ModIconsLoaded { get; private set; } = true;
public IEnumerable<Mod> Mods public IEnumerable<Mod> Mods
{ {
set set
@ -52,7 +57,13 @@ namespace osu.Game.Overlays.Mods
}).ToArray(); }).ToArray();
modsLoadCts?.Cancel(); modsLoadCts?.Cancel();
LoadComponentsAsync(modContainers, c => ButtonsContainer.ChildrenEnumerable = c, (modsLoadCts = new CancellationTokenSource()).Token); ModIconsLoaded = false;
LoadComponentsAsync(modContainers, c =>
{
ModIconsLoaded = true;
ButtonsContainer.ChildrenEnumerable = c;
}, (modsLoadCts = new CancellationTokenSource()).Token);
buttons = modContainers.OfType<ModButton>().ToArray(); buttons = modContainers.OfType<ModButton>().ToArray();