Skip to content

Commit

Permalink
Merge branch 'master' into switch-to-new-score-download-endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
peppy committed Aug 30, 2023
2 parents 99d5ff9 + 91c3ae4 commit 038e618
Show file tree
Hide file tree
Showing 11 changed files with 337 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
using osu.Framework.Screens;
using osu.Framework.Testing;
using osu.Game.Beatmaps;
using osu.Game.Configuration;
using osu.Game.Database;
using osu.Game.Rulesets.Mania;
using osu.Game.Rulesets.Osu;
using osu.Game.Screens.Edit;
using osu.Game.Screens.Edit.GameplayTest;
using osu.Game.Screens.Menu;
using osu.Game.Screens.Select;
using osu.Game.Screens.Select.Filter;
using osu.Game.Tests.Resources;
using osuTK.Input;

Expand Down Expand Up @@ -203,6 +205,33 @@ public void TestAttemptGlobalMusicOperationFromEditor()
AddUntilStep("wait for music stopped", () => !Game.MusicController.IsPlaying);
}

[TestCase(SortMode.Title)]
[TestCase(SortMode.Difficulty)]
public void TestSelectionRetainedOnExit(SortMode sortMode)
{
BeatmapSetInfo beatmapSet = null!;

AddStep("import test beatmap", () => Game.BeatmapManager.Import(TestResources.GetTestBeatmapForImport()).WaitSafely());
AddStep("retrieve beatmap", () => beatmapSet = Game.BeatmapManager.QueryBeatmapSet(set => !set.Protected).AsNonNull().Value.Detach());

AddStep($"set sort mode to {sortMode}", () => Game.LocalConfig.SetValue(OsuSetting.SongSelectSortingMode, sortMode));
AddStep("present beatmap", () => Game.PresentBeatmap(beatmapSet));
AddUntilStep("wait for song select",
() => Game.Beatmap.Value.BeatmapSetInfo.Equals(beatmapSet)
&& Game.ScreenStack.CurrentScreen is PlaySongSelect songSelect
&& songSelect.IsLoaded);

AddStep("open editor", () => ((PlaySongSelect)Game.ScreenStack.CurrentScreen).Edit(beatmapSet.Beatmaps.First(beatmap => beatmap.Ruleset.OnlineID == 0)));
AddUntilStep("wait for editor open", () => Game.ScreenStack.CurrentScreen is Editor editor && editor.ReadyForUse);

AddStep("exit editor", () => InputManager.Key(Key.Escape));
AddUntilStep("wait for editor exit", () => Game.ScreenStack.CurrentScreen is not Editor);

AddUntilStep("selection retained on song select",
() => Game.Beatmap.Value.BeatmapInfo.ID,
() => Is.EqualTo(beatmapSet.Beatmaps.First(b => b.Ruleset.OnlineID == 0).ID));
}

private EditorBeatmap getEditorBeatmap() => getEditor().ChildrenOfType<EditorBeatmap>().Single();

private Editor getEditor() => (Editor)Game.ScreenStack.CurrentScreen;
Expand Down
131 changes: 109 additions & 22 deletions osu.Game.Tests/Visual/SongSelect/TestSceneBeatmapCarousel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public partial class TestSceneBeatmapCarousel : OsuManualInputManagerTestScene
private BeatmapInfo currentSelection => carousel.SelectedBeatmapInfo;

private const int set_count = 5;
private const int diff_count = 3;

[BackgroundDependencyLoader]
private void load(RulesetStore rulesets)
Expand Down Expand Up @@ -111,7 +112,7 @@ public void TestExternalRulesetChange()
[Test]
public void TestScrollPositionMaintainedOnAdd()
{
loadBeatmaps(count: 1, randomDifficulties: false);
loadBeatmaps(setCount: 1);

for (int i = 0; i < 10; i++)
{
Expand All @@ -124,7 +125,7 @@ public void TestScrollPositionMaintainedOnAdd()
[Test]
public void TestDeletion()
{
loadBeatmaps(count: 5, randomDifficulties: true);
loadBeatmaps(setCount: 5, randomDifficulties: true);

AddStep("remove first set", () => carousel.RemoveBeatmapSet(carousel.Items.Select(item => item.Item).OfType<CarouselBeatmapSet>().First().BeatmapSet));
AddUntilStep("4 beatmap sets visible", () => this.ChildrenOfType<DrawableCarouselBeatmapSet>().Count(set => set.Alpha > 0) == 4);
Expand All @@ -133,7 +134,7 @@ public void TestDeletion()
[Test]
public void TestScrollPositionMaintainedOnDelete()
{
loadBeatmaps(count: 50, randomDifficulties: false);
loadBeatmaps(setCount: 50);

for (int i = 0; i < 10; i++)
{
Expand All @@ -150,7 +151,7 @@ public void TestScrollPositionMaintainedOnDelete()
[Test]
public void TestManyPanels()
{
loadBeatmaps(count: 5000, randomDifficulties: true);
loadBeatmaps(setCount: 5000, randomDifficulties: true);
}

[Test]
Expand Down Expand Up @@ -501,6 +502,33 @@ public void TestAddRemove()
waitForSelection(set_count);
}

[Test]
public void TestAddRemoveDifficultySort()
{
const int local_set_count = 2;
const int local_diff_count = 2;

loadBeatmaps(setCount: local_set_count, diffCount: local_diff_count);

AddStep("Sort by difficulty", () => carousel.Filter(new FilterCriteria { Sort = SortMode.Difficulty }, false));

checkVisibleItemCount(false, local_set_count * local_diff_count);

var firstAdded = TestResources.CreateTestBeatmapSetInfo(local_diff_count);

AddStep("Add new set", () => carousel.UpdateBeatmapSet(firstAdded));

checkVisibleItemCount(false, (local_set_count + 1) * local_diff_count);

AddStep("Remove set", () => carousel.RemoveBeatmapSet(firstAdded));

checkVisibleItemCount(false, (local_set_count) * local_diff_count);

setSelected(local_set_count, 1);

waitForSelection(local_set_count);
}

[Test]
public void TestSelectionEnteringFromEmptyRuleset()
{
Expand Down Expand Up @@ -662,7 +690,7 @@ public void TestSortingStabilityWithRemovedAndReaddedItem()
for (int i = 0; i < 3; i++)
{
var set = TestResources.CreateTestBeatmapSetInfo(3);
var set = TestResources.CreateTestBeatmapSetInfo(diff_count);
// only need to set the first as they are a shared reference.
var beatmap = set.Beatmaps.First();
Expand Down Expand Up @@ -709,7 +737,7 @@ public void TestSortingStabilityWithNewItems()
for (int i = 0; i < 3; i++)
{
var set = TestResources.CreateTestBeatmapSetInfo(3);
var set = TestResources.CreateTestBeatmapSetInfo(diff_count);
// only need to set the first as they are a shared reference.
var beatmap = set.Beatmaps.First();
Expand Down Expand Up @@ -758,32 +786,54 @@ public void TestSortingStabilityWithNewItems()
}

[Test]
public void TestSortingWithFiltered()
public void TestSortingWithDifficultyFiltered()
{
const int local_diff_count = 3;
const int local_set_count = 2;

List<BeatmapSetInfo> sets = new List<BeatmapSetInfo>();

AddStep("Populuate beatmap sets", () =>
{
sets.Clear();
for (int i = 0; i < 3; i++)
for (int i = 0; i < local_set_count; i++)
{
var set = TestResources.CreateTestBeatmapSetInfo(3);
var set = TestResources.CreateTestBeatmapSetInfo(local_diff_count);
set.Beatmaps[0].StarRating = 3 - i;
set.Beatmaps[2].StarRating = 6 + i;
set.Beatmaps[1].StarRating = 6 + i;
sets.Add(set);
}
});

loadBeatmaps(sets);

AddStep("Sort by difficulty", () => carousel.Filter(new FilterCriteria { Sort = SortMode.Difficulty }, false));

checkVisibleItemCount(false, local_set_count * local_diff_count);
checkVisibleItemCount(true, 1);

AddStep("Filter to normal", () => carousel.Filter(new FilterCriteria { Sort = SortMode.Difficulty, SearchText = "Normal" }, false));
AddAssert("Check first set at end", () => carousel.BeatmapSets.First().Equals(sets.Last()));
AddAssert("Check last set at start", () => carousel.BeatmapSets.Last().Equals(sets.First()));
checkVisibleItemCount(false, local_set_count);
checkVisibleItemCount(true, 1);

AddUntilStep("Check all visible sets have one normal", () =>
{
return carousel.Items.OfType<DrawableCarouselBeatmapSet>()
.Where(p => p.IsPresent)
.Count(p => ((CarouselBeatmapSet)p.Item)!.Beatmaps.Single().BeatmapInfo.DifficultyName.StartsWith("Normal", StringComparison.Ordinal)) == local_set_count;
});

AddStep("Filter to insane", () => carousel.Filter(new FilterCriteria { Sort = SortMode.Difficulty, SearchText = "Insane" }, false));
AddAssert("Check first set at start", () => carousel.BeatmapSets.First().Equals(sets.First()));
AddAssert("Check last set at end", () => carousel.BeatmapSets.Last().Equals(sets.Last()));
checkVisibleItemCount(false, local_set_count);
checkVisibleItemCount(true, 1);

AddUntilStep("Check all visible sets have one insane", () =>
{
return carousel.Items.OfType<DrawableCarouselBeatmapSet>()
.Where(p => p.IsPresent)
.Count(p => ((CarouselBeatmapSet)p.Item)!.Beatmaps.Single().BeatmapInfo.DifficultyName.StartsWith("Insane", StringComparison.Ordinal)) == local_set_count;
});
}

[Test]
Expand Down Expand Up @@ -838,7 +888,7 @@ public void TestHiding()

AddStep("create hidden set", () =>
{
hidingSet = TestResources.CreateTestBeatmapSetInfo(3);
hidingSet = TestResources.CreateTestBeatmapSetInfo(diff_count);
hidingSet.Beatmaps[1].Hidden = true;
hiddenList.Clear();
Expand Down Expand Up @@ -885,7 +935,7 @@ public void TestSelectingFilteredRuleset()

AddStep("add mixed ruleset beatmapset", () =>
{
testMixed = TestResources.CreateTestBeatmapSetInfo(3);
testMixed = TestResources.CreateTestBeatmapSetInfo(diff_count);
for (int i = 0; i <= 2; i++)
{
Expand All @@ -907,7 +957,7 @@ public void TestSelectingFilteredRuleset()
BeatmapSetInfo testSingle = null;
AddStep("add single ruleset beatmapset", () =>
{
testSingle = TestResources.CreateTestBeatmapSetInfo(3);
testSingle = TestResources.CreateTestBeatmapSetInfo(diff_count);
testSingle.Beatmaps.ForEach(b =>
{
b.Ruleset = rulesets.AvailableRulesets.ElementAt(1);
Expand All @@ -930,11 +980,48 @@ public void TestCarouselRemembersSelection()
manySets.Clear();
for (int i = 1; i <= 50; i++)
manySets.Add(TestResources.CreateTestBeatmapSetInfo(3));
manySets.Add(TestResources.CreateTestBeatmapSetInfo(diff_count));
});

loadBeatmaps(manySets);

advanceSelection(direction: 1, diff: false);

for (int i = 0; i < 5; i++)
{
AddStep("Toggle non-matching filter", () =>
{
carousel.Filter(new FilterCriteria { SearchText = Guid.NewGuid().ToString() }, false);
});

AddStep("Restore no filter", () =>
{
carousel.Filter(new FilterCriteria(), false);
eagerSelectedIDs.Add(carousel.SelectedBeatmapSet!.ID);
});
}

// always returns to same selection as long as it's available.
AddAssert("Selection was remembered", () => eagerSelectedIDs.Count == 1);
}

[Test]
public void TestCarouselRemembersSelectionDifficultySort()
{
List<BeatmapSetInfo> manySets = new List<BeatmapSetInfo>();

AddStep("Populate beatmap sets", () =>
{
manySets.Clear();
for (int i = 1; i <= 50; i++)
manySets.Add(TestResources.CreateTestBeatmapSetInfo(diff_count));
});

loadBeatmaps(manySets);

AddStep("Sort by difficulty", () => carousel.Filter(new FilterCriteria { Sort = SortMode.Difficulty }, false));

advanceSelection(direction: 1, diff: false);

for (int i = 0; i < 5; i++)
Expand Down Expand Up @@ -1081,20 +1168,20 @@ static RulesetInfo getRuleset(int index)
}
}

private void loadBeatmaps(List<BeatmapSetInfo> beatmapSets = null, Func<FilterCriteria> initialCriteria = null, Action<BeatmapCarousel> carouselAdjust = null, int? count = null,
bool randomDifficulties = false)
private void loadBeatmaps(List<BeatmapSetInfo> beatmapSets = null, Func<FilterCriteria> initialCriteria = null, Action<BeatmapCarousel> carouselAdjust = null,
int? setCount = null, int? diffCount = null, bool randomDifficulties = false)
{
bool changed = false;

if (beatmapSets == null)
{
beatmapSets = new List<BeatmapSetInfo>();

for (int i = 1; i <= (count ?? set_count); i++)
for (int i = 1; i <= (setCount ?? set_count); i++)
{
beatmapSets.Add(randomDifficulties
? TestResources.CreateTestBeatmapSetInfo()
: TestResources.CreateTestBeatmapSetInfo(3));
: TestResources.CreateTestBeatmapSetInfo(diffCount ?? diff_count));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using osu.Game.Overlays.Dialog;
using osu.Game.Screens.Select;
using osu.Game.Screens.Select.Carousel;
using osu.Game.Screens.Select.Filter;
using osu.Game.Tests.Online;
using osu.Game.Tests.Resources;
using osuTK.Input;
Expand Down Expand Up @@ -192,14 +193,65 @@ public void TestUpdateLocalBeatmap()
AddStep("release mouse button", () => InputManager.ReleaseButton(MouseButton.Left));
}

[Test]
public void TestSplitDisplay()
{
ArchiveDownloadRequest<IBeatmapSetInfo>? downloadRequest = null;

AddStep("set difficulty sort mode", () => carousel.Filter(new FilterCriteria { Sort = SortMode.Difficulty }));
AddStep("update online hash", () =>
{
testBeatmapSetInfo.Beatmaps.First().OnlineMD5Hash = "different hash";
testBeatmapSetInfo.Beatmaps.First().LastOnlineUpdate = DateTimeOffset.Now;
carousel.UpdateBeatmapSet(testBeatmapSetInfo);
});

AddUntilStep("multiple \"sets\" visible", () => carousel.ChildrenOfType<DrawableCarouselBeatmapSet>().Count(), () => Is.GreaterThan(1));
AddUntilStep("update button visible", getUpdateButton, () => Is.Not.Null);

AddStep("click button", () => getUpdateButton()?.TriggerClick());

AddUntilStep("wait for download started", () =>
{
downloadRequest = beatmapDownloader.GetExistingDownload(testBeatmapSetInfo);
return downloadRequest != null;
});

AddUntilStep("wait for button disabled", () => getUpdateButton()?.Enabled.Value == false);

AddUntilStep("progress download to completion", () =>
{
if (downloadRequest is TestSceneOnlinePlayBeatmapAvailabilityTracker.TestDownloadRequest testRequest)
{
testRequest.SetProgress(testRequest.Progress + 0.1f);
if (testRequest.Progress >= 1)
{
testRequest.TriggerSuccess();
// usually this would be done by the import process.
testBeatmapSetInfo.Beatmaps.First().MD5Hash = "different hash";
testBeatmapSetInfo.Beatmaps.First().LastOnlineUpdate = DateTimeOffset.Now;
// usually this would be done by a realm subscription.
carousel.UpdateBeatmapSet(testBeatmapSetInfo);
return true;
}
}
return false;
});
}

private BeatmapCarousel createCarousel()
{
return carousel = new BeatmapCarousel
{
RelativeSizeAxes = Axes.Both,
BeatmapSets = new List<BeatmapSetInfo>
{
(testBeatmapSetInfo = TestResources.CreateTestBeatmapSetInfo()),
(testBeatmapSetInfo = TestResources.CreateTestBeatmapSetInfo(5)),
}
};
}
Expand Down
Loading

0 comments on commit 038e618

Please sign in to comment.