1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 06:42:54 +08:00

Fix hide selection, add test

This commit is contained in:
David Zhao 2019-05-28 19:15:29 +09:00
parent 436760de96
commit 1a871af552
2 changed files with 16 additions and 1 deletions

View File

@ -234,6 +234,18 @@ namespace osu.Game.Tests.Visual.SongSelect
AddAssert($"Beatmap changed {test_count} times", () => beatmapChangedCount == test_count);
}
[Test]
public void TestHideSetSelectsCorrectBeatmap()
{
int? previousID = null;
createSongSelect();
importForRuleset(0);
AddStep("Move to last difficulty", () => songSelect.Carousel.SelectBeatmap(songSelect.Carousel.BeatmapSets.First().Beatmaps.Last()));
AddStep("Store current ID", () => previousID = songSelect.Carousel.SelectedBeatmap.ID);
AddStep("Hide first beatmap", () => manager.Hide(songSelect.Carousel.SelectedBeatmapSet.Beatmaps.First()));
AddAssert("Selected beatmap has not changed", () => songSelect.Carousel.SelectedBeatmap.ID == previousID);
}
private void importForRuleset(int id) => AddStep($"import test map for ruleset {id}",
() => manager.Import(createTestBeatmapSet(getImportId(), rulesets.AvailableRulesets.Where(r => r.ID == id).ToArray())));

View File

@ -158,6 +158,9 @@ namespace osu.Game.Screens.Select
var newSet = createCarouselSet(beatmapSet);
// Since we're about to remove the selected beatmap, store its ID so we can go back if needed.
var previouslySelectedID = selectedBeatmap?.Beatmap.ID;
if (existingSet != null)
root.RemoveChild(existingSet);
@ -173,7 +176,7 @@ namespace osu.Game.Screens.Select
//check if we can/need to maintain our current selection.
if (hadSelection)
select((CarouselItem)newSet.Beatmaps.FirstOrDefault(b => b.Beatmap.ID == selectedBeatmap?.Beatmap.ID) ?? newSet);
select((CarouselItem)newSet.Beatmaps.FirstOrDefault(b => b.Beatmap.ID == previouslySelectedID) ?? newSet);
itemsCache.Invalidate();
Schedule(() => BeatmapSetsChanged?.Invoke());