From 64ead0fdf78ca048f9a3f799686091904c9f9180 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 20 Jul 2018 11:32:00 +0900 Subject: [PATCH] Add more tests and fix one remaining issue case --- .../Visual/TestCasePlaySongSelect.cs | 51 +++++++++++-------- osu.Game/Screens/Select/SongSelect.cs | 17 ++++--- 2 files changed, 40 insertions(+), 28 deletions(-) diff --git a/osu.Game.Tests/Visual/TestCasePlaySongSelect.cs b/osu.Game.Tests/Visual/TestCasePlaySongSelect.cs index d1f4340876..0ec7dd059d 100644 --- a/osu.Game.Tests/Visual/TestCasePlaySongSelect.cs +++ b/osu.Game.Tests/Visual/TestCasePlaySongSelect.cs @@ -82,11 +82,10 @@ namespace osu.Game.Tests.Visual public virtual void SetUp() { manager?.Delete(manager.GetAllUsableBeatmapSets()); - Child = songSelect = new TestSongSelect(); } - //[Test] + [Test] public void TestDummy() { AddAssert("dummy selected", () => songSelect.CurrentBeatmap == defaultBeatmap); @@ -99,7 +98,7 @@ namespace osu.Game.Tests.Visual AddAssert("random map selected", () => songSelect.CurrentBeatmap != defaultBeatmap); } - //[Test] + [Test] public void TestSorting() { addManyTestMaps(); @@ -114,24 +113,35 @@ namespace osu.Game.Tests.Visual } [Test] - public void TestRulesetChange() + public void ImportUnderDifferentRuleset() { - AddStep("change ruleset", () => Ruleset.Value = rulesets.AvailableRulesets.First(r => r.ID == 2)); - - AddStep("import test maps", () => - { - manager.Import(createTestBeatmapSet(0, rulesets.AvailableRulesets.Where(r => r.ID == 0).ToArray())); - manager.Import(createTestBeatmapSet(1, rulesets.AvailableRulesets.Where(r => r.ID == 2).ToArray())); - - }); - - AddStep("change ruleset", () => Ruleset.Value = rulesets.AvailableRulesets.First(r => r.ID == 1)); - + changeRuleset(2); + importForRuleset(0); AddUntilStep(() => songSelect.Carousel.SelectedBeatmap == null, "no selection"); - - AddStep("change ruleset", () => Ruleset.Value = rulesets.AvailableRulesets.First(r => r.ID == 0)); } + [Test] + public void ImportUnderCurrentRuleset() + { + changeRuleset(2); + importForRuleset(2); + importForRuleset(1); + AddUntilStep(() => songSelect.Carousel.SelectedBeatmap.RulesetID == 2, "has selection"); + + changeRuleset(1); + AddUntilStep(() => songSelect.Carousel.SelectedBeatmap.RulesetID == 1, "has selection"); + + changeRuleset(0); + AddUntilStep(() => songSelect.Carousel.SelectedBeatmap == null, "no selection"); + } + + private void importForRuleset(int id) => AddStep($"import test map for ruleset {id}", () => manager.Import(createTestBeatmapSet(getImportId(), rulesets.AvailableRulesets.Where(r => r.ID == id).ToArray()))); + + private static int importId; + private int getImportId() => ++importId; + + private void changeRuleset(int id) => AddStep($"change ruleset to {id}", () => Ruleset.Value = rulesets.AvailableRulesets.First(r => r.ID == id)); + private void addManyTestMaps() { AddStep("import test maps", () => @@ -143,18 +153,16 @@ namespace osu.Game.Tests.Visual }); } - private BeatmapSetInfo createTestBeatmapSet(int idOffset, RulesetInfo[] rulesets) + private BeatmapSetInfo createTestBeatmapSet(int setId, RulesetInfo[] rulesets) { int j = 0; RulesetInfo getRuleset() => rulesets[j++ % rulesets.Length]; var beatmaps = new List(); - int setId = 1234 + idOffset; - for (int i = 0; i < 6; i++) { - int beatmapId = 1234 + idOffset + i; + int beatmapId = setId * 10 + i; beatmaps.Add(new BeatmapInfo { @@ -169,7 +177,6 @@ namespace osu.Game.Tests.Visual }); } - return new BeatmapSetInfo { OnlineBeatmapSetID = setId, diff --git a/osu.Game/Screens/Select/SongSelect.cs b/osu.Game/Screens/Select/SongSelect.cs index 0f22d9b208..76e8d695c8 100644 --- a/osu.Game/Screens/Select/SongSelect.cs +++ b/osu.Game/Screens/Select/SongSelect.cs @@ -309,9 +309,9 @@ namespace osu.Game.Screens.Select var beatmap = beatmapNoDebounce; var ruleset = rulesetNoDebounce; - void performLoad() + void run() { - Logger.Log($"performLoad with b:{beatmap} r:{ruleset}"); + Logger.Log($"updating selection with beatmap:{beatmap?.ID.ToString() ?? "null"} ruleset:{ruleset?.ID.ToString() ?? "null"}"); WorkingBeatmap working = Beatmap.Value; @@ -319,19 +319,24 @@ namespace osu.Game.Screens.Select if (ruleset?.Equals(Ruleset.Value) == false) { - Logger.Log($"ruleset changed from {Ruleset.Value} to {ruleset}"); + Logger.Log($"ruleset changed from \"{Ruleset.Value}\" to \"{ruleset}\""); Ruleset.Value = ruleset; // force a filter before attempting to change the beatmap. // we may still be in the wrong ruleset as there is a debounce delay on ruleset changes. Carousel.Filter(null, false); + + // Filtering only completes after the carousel runs Update. + // If we also have a pending beatmap change we should delay it one frame. + selectionChangedDebounce = Schedule(run); + return; } // We may be arriving here due to another component changing the bindable Beatmap. // In these cases, the other component has already loaded the beatmap, so we don't need to do so again. if (!Equals(beatmap, Beatmap.Value.BeatmapInfo)) { - Logger.Log($"beatmap changed from {Beatmap.Value.BeatmapInfo} to {beatmap}"); + Logger.Log($"beatmap changed from \"{Beatmap.Value.BeatmapInfo}\" to \"{beatmap}\""); preview = beatmap?.BeatmapSetInfoID != Beatmap.Value?.BeatmapInfo.BeatmapSetInfoID; working = beatmaps.GetWorkingBeatmap(beatmap, Beatmap.Value); @@ -355,9 +360,9 @@ namespace osu.Game.Screens.Select selectionChangedDebounce?.Cancel(); if (beatmap == null) - performLoad(); + run(); else - selectionChangedDebounce = Scheduler.AddDelayed(performLoad, 200); + selectionChangedDebounce = Scheduler.AddDelayed(run, 200); } private void triggerRandom()