Merge pull request #17788 from peppy/fix-replay-download-button-tests

Fix multiple issues in `ReplayDownloadButton` test scene
This commit is contained in:
Dan Balasescu 2022-04-13 16:00:45 +09:00 committed by GitHub
commit 59ff9be316
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 7 deletions

View File

@ -26,6 +26,8 @@ namespace osu.Game.Tests.Visual.Gameplay
[TestFixture]
public class TestSceneReplayDownloadButton : OsuManualInputManagerTestScene
{
private const long online_score_id = 2553163309;
[Resolved]
private RulesetStore rulesets { get; set; }
@ -43,6 +45,15 @@ namespace osu.Game.Tests.Visual.Gameplay
beatmapManager.Import(TestResources.GetQuickTestBeatmapForImport()).WaitSafely();
}
[SetUpSteps]
public void SetUpSteps()
{
AddStep("delete previous imports", () =>
{
scoreManager.Delete(s => s.OnlineID == online_score_id);
});
}
[Test]
public void TestDisplayStates()
{
@ -180,7 +191,7 @@ namespace osu.Game.Tests.Visual.Gameplay
{
return new APIScore
{
OnlineID = 2553163309,
OnlineID = online_score_id,
RulesetID = 0,
Beatmap = CreateAPIBeatmapSet(new OsuRuleset().RulesetInfo).Beatmaps.First(),
HasReplay = replayAvailable,

View File

@ -47,7 +47,10 @@ namespace osu.Game.Online
Downloader.DownloadBegan += downloadBegan;
Downloader.DownloadFailed += downloadFailed;
realmSubscription = realm.RegisterForNotifications(r => r.All<ScoreInfo>().Where(s => ((s.OnlineID > 0 && s.OnlineID == TrackedItem.OnlineID) || s.Hash == TrackedItem.Hash) && !s.DeletePending), (items, changes, ___) =>
realmSubscription = realm.RegisterForNotifications(r => r.All<ScoreInfo>().Where(s =>
((s.OnlineID > 0 && s.OnlineID == TrackedItem.OnlineID)
|| (!string.IsNullOrEmpty(s.Hash) && s.Hash == TrackedItem.Hash))
&& !s.DeletePending), (items, changes, ___) =>
{
if (items.Any())
Schedule(() => UpdateState(DownloadState.LocallyAvailable));

View File

@ -351,8 +351,7 @@ namespace osu.Game.Stores
using (var transaction = realm.BeginWrite())
{
if (existing.DeletePending)
UndeleteForReuse(existing);
UndeleteForReuse(existing);
transaction.Commit();
}
@ -388,9 +387,7 @@ namespace osu.Game.Stores
{
LogForModel(item, @$"Found existing {HumanisedModelName} for {item} (ID {existing.ID}) skipping import.");
if (existing.DeletePending)
UndeleteForReuse(existing);
UndeleteForReuse(existing);
transaction.Commit();
return existing.ToLive(Realm);
@ -536,6 +533,10 @@ namespace osu.Game.Stores
/// <param name="existing">The existing model.</param>
protected virtual void UndeleteForReuse(TModel existing)
{
if (!existing.DeletePending)
return;
LogForModel(existing, $@"Existing {HumanisedModelName}'s deletion flag has been removed to allow for reuse.");
existing.DeletePending = false;
}