Merge pull request #19924 from peppy/fix-playlist-overlay-test-failures

Fix intermittent test failures in `TestScenePlaylistOverlay`
This commit is contained in:
Dan Balasescu 2022-08-26 23:36:16 +09:00 committed by GitHub
commit 289b6f1a58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 11 deletions

View File

@ -5,7 +5,6 @@
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Platform;
@ -39,8 +38,6 @@ private void load(GameHost host)
Dependencies.Cache(new RealmRulesetStore(Realm));
Dependencies.Cache(beatmapManager = new BeatmapManager(LocalStorage, Realm, null, Audio, Resources, host, Beatmap.Default));
Dependencies.Cache(Realm);
beatmapManager.Import(TestResources.GetQuickTestBeatmapForImport()).WaitSafely();
}
[SetUp]
@ -66,6 +63,9 @@ public void Setup() => Schedule(() =>
}
beatmapSets.First().ToLive(Realm);
// Ensure all the initial imports are present before running any tests.
Realm.Run(r => r.Refresh());
});
[Test]
@ -138,7 +138,7 @@ public void TestCollectionFiltering()
AddStep("Add collection", () =>
{
Dependencies.Get<RealmAccess>().Write(r =>
Realm.Write(r =>
{
r.RemoveAll<BeatmapCollection>();
r.Add(new BeatmapCollection("wang"));

View File

@ -75,7 +75,14 @@ private void collectionsChanged(IRealmCollection<BeatmapCollection> collections,
// changes. It's not great but honestly the whole dropdown menu structure isn't great. This needs to be fixed, but I'll issue
// a warning that it's going to be a frustrating journey.
Current.Value = allBeatmaps;
Schedule(() => Current.Value = filters.SingleOrDefault(f => f.Collection != null && f.Collection.ID == selectedItem?.ID) ?? filters[0]);
Schedule(() =>
{
// current may have changed before the scheduled call is run.
if (Current.Value != allBeatmaps)
return;
Current.Value = filters.SingleOrDefault(f => f.Collection != null && f.Collection.ID == selectedItem?.ID) ?? filters[0];
});
// Trigger a re-filter if the current item was in the change set.
if (selectedItem != null && changes != null)

View File

@ -27,6 +27,12 @@ public class Playlist : OsuRearrangeableListContainer<Live<BeatmapSetInfo>>
set => base.Padding = value;
}
protected override void OnItemsChanged()
{
base.OnItemsChanged();
Filter(currentCriteria);
}
public void Filter(FilterCriteria criteria)
{
var items = (SearchContainer<RearrangeableListItem<Live<BeatmapSetInfo>>>)ListContainer;
@ -44,9 +50,9 @@ public void Filter(FilterCriteria criteria)
public Live<BeatmapSetInfo>? FirstVisibleSet => Items.FirstOrDefault(i => ((PlaylistItem)ItemMap[i]).MatchingFilter);
protected override OsuRearrangeableListItem<Live<BeatmapSetInfo>> CreateOsuDrawable(Live<BeatmapSetInfo> item) => new PlaylistItem(item)
protected override OsuRearrangeableListItem<Live<BeatmapSetInfo>> CreateOsuDrawable(Live<BeatmapSetInfo> item) =>
new PlaylistItem(item)
{
InSelectedCollection = currentCriteria.Collection?.PerformRead(c => item.Value.Beatmaps.Select(b => b.MD5Hash).Any(c.BeatmapMD5Hashes.Contains)) != false,
SelectedSet = { BindTarget = SelectedSet },
RequestSelection = set => RequestSelection?.Invoke(set)
};