mirror of
https://github.com/ppy/osu.git
synced 2024-12-15 05:42:56 +08:00
Update beatmap carousel tests code style
Also fixes one issue I spotted in BeatmapCarousel related to incorrectly holding a selection after new sets are loaded.
This commit is contained in:
parent
4271b3bb50
commit
4a59e3351e
@ -43,7 +43,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
private readonly Stack<BeatmapSetInfo> selectedSets = new Stack<BeatmapSetInfo>();
|
private readonly Stack<BeatmapSetInfo> selectedSets = new Stack<BeatmapSetInfo>();
|
||||||
private readonly HashSet<int> eagerSelectedIDs = new HashSet<int>();
|
private readonly HashSet<int> eagerSelectedIDs = new HashSet<int>();
|
||||||
|
|
||||||
private BeatmapInfo currentSelection;
|
private BeatmapInfo currentSelection => carousel.SelectedBeatmap;
|
||||||
|
|
||||||
private const int set_count = 5;
|
private const int set_count = 5;
|
||||||
|
|
||||||
@ -56,37 +56,26 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
});
|
});
|
||||||
|
|
||||||
List<BeatmapSetInfo> beatmapSets = new List<BeatmapSetInfo>();
|
|
||||||
|
|
||||||
for (int i = 1; i <= set_count; i++)
|
|
||||||
beatmapSets.Add(createTestBeatmapSet(i));
|
|
||||||
|
|
||||||
carousel.SelectionChanged = s => currentSelection = s;
|
|
||||||
|
|
||||||
loadBeatmaps(beatmapSets);
|
|
||||||
|
|
||||||
testTraversal();
|
|
||||||
testFiltering();
|
|
||||||
testRandom();
|
|
||||||
testAddRemove();
|
|
||||||
testSorting();
|
|
||||||
|
|
||||||
testRemoveAll();
|
|
||||||
testEmptyTraversal();
|
|
||||||
testHiding();
|
|
||||||
testSelectingFilteredRuleset();
|
|
||||||
testCarouselRootIsRandom();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadBeatmaps(List<BeatmapSetInfo> beatmapSets)
|
private void loadBeatmaps(List<BeatmapSetInfo> beatmapSets = null)
|
||||||
{
|
{
|
||||||
|
if (beatmapSets == null)
|
||||||
|
{
|
||||||
|
beatmapSets = new List<BeatmapSetInfo>();
|
||||||
|
|
||||||
|
for (int i = 1; i <= set_count; i++)
|
||||||
|
beatmapSets.Add(createTestBeatmapSet(i));
|
||||||
|
}
|
||||||
|
|
||||||
bool changed = false;
|
bool changed = false;
|
||||||
AddStep($"Load {beatmapSets.Count} Beatmaps", () =>
|
AddStep($"Load {beatmapSets.Count} Beatmaps", () =>
|
||||||
{
|
{
|
||||||
|
carousel.Filter(new FilterCriteria());
|
||||||
carousel.BeatmapSetsChanged = () => changed = true;
|
carousel.BeatmapSetsChanged = () => changed = true;
|
||||||
carousel.BeatmapSets = beatmapSets;
|
carousel.BeatmapSets = beatmapSets;
|
||||||
});
|
});
|
||||||
|
|
||||||
AddUntilStep("Wait for load", () => changed);
|
AddUntilStep("Wait for load", () => changed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,8 +162,11 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Test keyboard traversal
|
/// Test keyboard traversal
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void testTraversal()
|
[Test]
|
||||||
|
public void TestTraversal()
|
||||||
{
|
{
|
||||||
|
loadBeatmaps();
|
||||||
|
|
||||||
advanceSelection(direction: 1, diff: false);
|
advanceSelection(direction: 1, diff: false);
|
||||||
checkSelected(1, 1);
|
checkSelected(1, 1);
|
||||||
|
|
||||||
@ -199,8 +191,11 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Test filtering
|
/// Test filtering
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void testFiltering()
|
[Test]
|
||||||
|
public void TestFiltering()
|
||||||
{
|
{
|
||||||
|
loadBeatmaps();
|
||||||
|
|
||||||
// basic filtering
|
// basic filtering
|
||||||
|
|
||||||
setSelected(1, 1);
|
setSelected(1, 1);
|
||||||
@ -262,8 +257,11 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Test random non-repeating algorithm
|
/// Test random non-repeating algorithm
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void testRandom()
|
[Test]
|
||||||
|
public void TestRandom()
|
||||||
{
|
{
|
||||||
|
loadBeatmaps();
|
||||||
|
|
||||||
setSelected(1, 1);
|
setSelected(1, 1);
|
||||||
|
|
||||||
nextRandom();
|
nextRandom();
|
||||||
@ -299,8 +297,11 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Test adding and removing beatmap sets
|
/// Test adding and removing beatmap sets
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void testAddRemove()
|
[Test]
|
||||||
|
public void TestAddRemove()
|
||||||
{
|
{
|
||||||
|
loadBeatmaps();
|
||||||
|
|
||||||
AddStep("Add new set", () => carousel.UpdateBeatmapSet(createTestBeatmapSet(set_count + 1)));
|
AddStep("Add new set", () => carousel.UpdateBeatmapSet(createTestBeatmapSet(set_count + 1)));
|
||||||
AddStep("Add new set", () => carousel.UpdateBeatmapSet(createTestBeatmapSet(set_count + 2)));
|
AddStep("Add new set", () => carousel.UpdateBeatmapSet(createTestBeatmapSet(set_count + 2)));
|
||||||
|
|
||||||
@ -322,16 +323,22 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Test sorting
|
/// Test sorting
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void testSorting()
|
[Test]
|
||||||
|
public void TestSorting()
|
||||||
{
|
{
|
||||||
|
loadBeatmaps();
|
||||||
|
|
||||||
AddStep("Sort by author", () => carousel.Filter(new FilterCriteria { Sort = SortMode.Author }, false));
|
AddStep("Sort by author", () => carousel.Filter(new FilterCriteria { Sort = SortMode.Author }, false));
|
||||||
AddAssert("Check zzzzz is at bottom", () => carousel.BeatmapSets.Last().Metadata.AuthorString == "zzzzz");
|
AddAssert("Check zzzzz is at bottom", () => carousel.BeatmapSets.Last().Metadata.AuthorString == "zzzzz");
|
||||||
AddStep("Sort by artist", () => carousel.Filter(new FilterCriteria { Sort = SortMode.Artist }, false));
|
AddStep("Sort by artist", () => carousel.Filter(new FilterCriteria { Sort = SortMode.Artist }, false));
|
||||||
AddAssert($"Check #{set_count} is at bottom", () => carousel.BeatmapSets.Last().Metadata.Title.EndsWith($"#{set_count}!"));
|
AddAssert($"Check #{set_count} is at bottom", () => carousel.BeatmapSets.Last().Metadata.Title.EndsWith($"#{set_count}!"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void testRemoveAll()
|
[Test]
|
||||||
|
public void TestRemoveAll()
|
||||||
{
|
{
|
||||||
|
loadBeatmaps();
|
||||||
|
|
||||||
setSelected(2, 1);
|
setSelected(2, 1);
|
||||||
AddAssert("Selection is non-null", () => currentSelection != null);
|
AddAssert("Selection is non-null", () => currentSelection != null);
|
||||||
|
|
||||||
@ -353,8 +360,11 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
checkNoSelection();
|
checkNoSelection();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void testEmptyTraversal()
|
[Test]
|
||||||
|
public void TestEmptyTraversal()
|
||||||
{
|
{
|
||||||
|
loadBeatmaps(new List<BeatmapSetInfo>());
|
||||||
|
|
||||||
advanceSelection(direction: 1, diff: false);
|
advanceSelection(direction: 1, diff: false);
|
||||||
checkNoSelection();
|
checkNoSelection();
|
||||||
|
|
||||||
@ -368,11 +378,18 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
checkNoSelection();
|
checkNoSelection();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void testHiding()
|
[Test]
|
||||||
|
public void TestHiding()
|
||||||
{
|
{
|
||||||
var hidingSet = createTestBeatmapSet(1);
|
BeatmapSetInfo hidingSet = null;
|
||||||
hidingSet.Beatmaps[1].Hidden = true;
|
|
||||||
AddStep("Add set with diff 2 hidden", () => carousel.UpdateBeatmapSet(hidingSet));
|
AddStep("Add set with diff 2 hidden", () =>
|
||||||
|
{
|
||||||
|
hidingSet = createTestBeatmapSet(1);
|
||||||
|
hidingSet.Beatmaps[1].Hidden = true;
|
||||||
|
carousel.UpdateBeatmapSet(hidingSet);
|
||||||
|
});
|
||||||
|
|
||||||
setSelected(1, 1);
|
setSelected(1, 1);
|
||||||
|
|
||||||
checkVisibleItemCount(true, 2);
|
checkVisibleItemCount(true, 2);
|
||||||
@ -402,7 +419,8 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void testSelectingFilteredRuleset()
|
[Test]
|
||||||
|
public void TestSelectingFilteredRuleset()
|
||||||
{
|
{
|
||||||
var testMixed = createTestBeatmapSet(set_count + 1);
|
var testMixed = createTestBeatmapSet(set_count + 1);
|
||||||
AddStep("add mixed ruleset beatmapset", () =>
|
AddStep("add mixed ruleset beatmapset", () =>
|
||||||
@ -437,14 +455,16 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
AddStep("remove single ruleset set", () => carousel.RemoveBeatmapSet(testSingle));
|
AddStep("remove single ruleset set", () => carousel.RemoveBeatmapSet(testSingle));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void testCarouselRootIsRandom()
|
[Test]
|
||||||
|
public void TestCarouselRootIsRandom()
|
||||||
{
|
{
|
||||||
List<BeatmapSetInfo> beatmapSets = new List<BeatmapSetInfo>();
|
List<BeatmapSetInfo> manySets = new List<BeatmapSetInfo>();
|
||||||
|
|
||||||
for (int i = 1; i <= 50; i++)
|
for (int i = 1; i <= 50; i++)
|
||||||
beatmapSets.Add(createTestBeatmapSet(i));
|
manySets.Add(createTestBeatmapSet(i));
|
||||||
|
|
||||||
|
loadBeatmaps(manySets);
|
||||||
|
|
||||||
loadBeatmaps(beatmapSets);
|
|
||||||
advanceSelection(direction: 1, diff: false);
|
advanceSelection(direction: 1, diff: false);
|
||||||
checkNonmatchingFilter();
|
checkNonmatchingFilter();
|
||||||
checkNonmatchingFilter();
|
checkNonmatchingFilter();
|
||||||
|
@ -82,6 +82,9 @@ namespace osu.Game.Screens.Select
|
|||||||
var _ = newRoot.Drawables;
|
var _ = newRoot.Drawables;
|
||||||
|
|
||||||
root = newRoot;
|
root = newRoot;
|
||||||
|
if (selectedBeatmapSet != null && !beatmapSets.Contains(selectedBeatmapSet.BeatmapSet))
|
||||||
|
selectedBeatmapSet = null;
|
||||||
|
|
||||||
scrollableContent.Clear(false);
|
scrollableContent.Clear(false);
|
||||||
itemsCache.Invalidate();
|
itemsCache.Invalidate();
|
||||||
scrollPositionCache.Invalidate();
|
scrollPositionCache.Invalidate();
|
||||||
|
Loading…
Reference in New Issue
Block a user