2019-12-20 05:29:54 +00:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
2021-11-22 05:26:51 +00:00
|
|
|
using System;
|
2019-12-20 05:29:54 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
2020-01-06 08:15:59 +00:00
|
|
|
using NUnit.Framework;
|
2019-12-20 05:29:54 +00:00
|
|
|
using osu.Framework.Allocation;
|
2020-08-12 15:29:23 +00:00
|
|
|
using osu.Framework.Audio;
|
2022-01-03 08:31:12 +00:00
|
|
|
using osu.Framework.Extensions;
|
2021-12-14 10:47:11 +00:00
|
|
|
using osu.Framework.Graphics;
|
2020-01-06 08:15:59 +00:00
|
|
|
using osu.Framework.Graphics.Cursor;
|
|
|
|
using osu.Framework.Platform;
|
|
|
|
using osu.Framework.Testing;
|
2020-01-09 17:38:03 +00:00
|
|
|
using osu.Framework.Utils;
|
2019-12-20 05:29:54 +00:00
|
|
|
using osu.Game.Beatmaps;
|
2020-12-07 09:00:45 +00:00
|
|
|
using osu.Game.Database;
|
2020-01-06 08:15:59 +00:00
|
|
|
using osu.Game.Graphics.Cursor;
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2021-11-22 06:52:55 +00:00
|
|
|
using osu.Game.Models;
|
2021-11-04 09:02:44 +00:00
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2019-12-20 05:29:54 +00:00
|
|
|
using osu.Game.Online.Leaderboards;
|
|
|
|
using osu.Game.Overlays;
|
2020-01-06 08:15:59 +00:00
|
|
|
using osu.Game.Rulesets;
|
2019-12-20 05:29:54 +00:00
|
|
|
using osu.Game.Scoring;
|
|
|
|
using osu.Game.Screens.Select.Leaderboards;
|
2020-01-06 08:15:59 +00:00
|
|
|
using osu.Game.Tests.Resources;
|
2019-12-20 05:29:54 +00:00
|
|
|
using osuTK;
|
2020-01-06 08:15:59 +00:00
|
|
|
using osuTK.Input;
|
2019-12-20 05:29:54 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.UserInterface
|
|
|
|
{
|
2020-03-23 01:01:33 +00:00
|
|
|
public class TestSceneDeleteLocalScore : OsuManualInputManagerTestScene
|
2019-12-20 05:29:54 +00:00
|
|
|
{
|
2020-01-06 08:15:59 +00:00
|
|
|
private readonly ContextMenuContainer contextMenuContainer;
|
|
|
|
private readonly BeatmapLeaderboard leaderboard;
|
|
|
|
|
|
|
|
private RulesetStore rulesetStore;
|
|
|
|
private BeatmapManager beatmapManager;
|
|
|
|
private ScoreManager scoreManager;
|
|
|
|
|
2021-09-07 07:46:27 +00:00
|
|
|
private readonly List<ScoreInfo> importedScores = new List<ScoreInfo>();
|
2021-10-02 15:55:29 +00:00
|
|
|
|
|
|
|
private BeatmapInfo beatmapInfo;
|
2019-12-20 05:29:54 +00:00
|
|
|
|
2021-12-13 10:01:20 +00:00
|
|
|
[Resolved]
|
|
|
|
private RealmContextFactory realmFactory { get; set; }
|
|
|
|
|
2020-01-03 19:34:26 +00:00
|
|
|
[Cached]
|
2019-12-20 05:57:14 +00:00
|
|
|
private readonly DialogOverlay dialogOverlay;
|
2019-12-20 05:29:54 +00:00
|
|
|
|
|
|
|
public TestSceneDeleteLocalScore()
|
|
|
|
{
|
2020-01-06 08:15:59 +00:00
|
|
|
Children = new Drawable[]
|
2019-12-20 05:29:54 +00:00
|
|
|
{
|
2020-01-06 08:15:59 +00:00
|
|
|
contextMenuContainer = new OsuContextMenuContainer
|
2019-12-20 05:29:54 +00:00
|
|
|
{
|
2020-01-06 08:15:59 +00:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Child = leaderboard = new BeatmapLeaderboard
|
2019-12-20 05:29:54 +00:00
|
|
|
{
|
2020-01-06 08:15:59 +00:00
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Size = new Vector2(550f, 450f),
|
|
|
|
Scope = BeatmapLeaderboardScope.Local,
|
2021-10-02 15:55:29 +00:00
|
|
|
BeatmapInfo = new BeatmapInfo
|
2019-12-20 05:29:54 +00:00
|
|
|
{
|
2021-11-22 05:26:51 +00:00
|
|
|
ID = Guid.NewGuid(),
|
2020-01-06 08:15:59 +00:00
|
|
|
Metadata = new BeatmapMetadata
|
|
|
|
{
|
|
|
|
Title = "TestSong",
|
|
|
|
Artist = "TestArtist",
|
2021-11-22 06:52:55 +00:00
|
|
|
Author = new RealmUser
|
2020-01-06 08:15:59 +00:00
|
|
|
{
|
|
|
|
Username = "TestAuthor"
|
|
|
|
},
|
|
|
|
},
|
2021-11-11 08:19:53 +00:00
|
|
|
DifficultyName = "Insane"
|
2019-12-20 05:29:54 +00:00
|
|
|
},
|
2020-01-06 08:15:59 +00:00
|
|
|
}
|
2019-12-20 05:29:54 +00:00
|
|
|
},
|
2020-01-06 08:15:59 +00:00
|
|
|
dialogOverlay = new DialogOverlay()
|
|
|
|
};
|
2019-12-20 05:29:54 +00:00
|
|
|
}
|
|
|
|
|
2020-01-06 08:15:59 +00:00
|
|
|
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
|
2019-12-20 05:29:54 +00:00
|
|
|
{
|
2020-01-06 08:15:59 +00:00
|
|
|
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
|
2019-12-20 05:29:54 +00:00
|
|
|
|
2020-01-06 08:15:59 +00:00
|
|
|
dependencies.Cache(rulesetStore = new RulesetStore(ContextFactory));
|
2021-05-31 09:37:32 +00:00
|
|
|
dependencies.Cache(beatmapManager = new BeatmapManager(LocalStorage, ContextFactory, rulesetStore, null, dependencies.Get<AudioManager>(), Resources, dependencies.Get<GameHost>(), Beatmap.Default));
|
2021-12-14 10:47:11 +00:00
|
|
|
dependencies.Cache(scoreManager = new ScoreManager(dependencies.Get<RulesetStore>(), () => beatmapManager, LocalStorage, dependencies.Get<RealmContextFactory>(), Scheduler));
|
2019-12-20 05:29:54 +00:00
|
|
|
|
2022-01-06 13:54:43 +00:00
|
|
|
beatmapInfo = beatmapManager.Import(new ImportTask(TestResources.GetQuickTestBeatmapForImport())).GetResultSafely().Value.Beatmaps[0];
|
2019-12-20 05:29:54 +00:00
|
|
|
|
2020-01-06 08:15:59 +00:00
|
|
|
for (int i = 0; i < 50; i++)
|
2019-12-20 05:29:54 +00:00
|
|
|
{
|
2020-01-06 08:15:59 +00:00
|
|
|
var score = new ScoreInfo
|
|
|
|
{
|
2021-12-10 06:37:12 +00:00
|
|
|
OnlineID = i,
|
2021-10-04 08:35:53 +00:00
|
|
|
BeatmapInfo = beatmapInfo,
|
2020-01-06 08:15:59 +00:00
|
|
|
Accuracy = RNG.NextDouble(),
|
|
|
|
TotalScore = RNG.Next(1, 1000000),
|
|
|
|
MaxCombo = RNG.Next(1, 1000),
|
|
|
|
Rank = ScoreRank.XH,
|
2021-11-04 09:02:44 +00:00
|
|
|
User = new APIUser { Username = "TestUser" },
|
2020-01-06 08:15:59 +00:00
|
|
|
};
|
2019-12-20 05:29:54 +00:00
|
|
|
|
2022-01-06 13:54:43 +00:00
|
|
|
importedScores.Add(scoreManager.Import(score).GetResultSafely().Value);
|
2019-12-20 05:29:54 +00:00
|
|
|
}
|
|
|
|
|
2020-01-06 08:15:59 +00:00
|
|
|
return dependencies;
|
|
|
|
}
|
2019-12-20 05:29:54 +00:00
|
|
|
|
2020-01-06 08:15:59 +00:00
|
|
|
[SetUp]
|
|
|
|
public void Setup() => Schedule(() =>
|
|
|
|
{
|
2021-12-13 10:01:20 +00:00
|
|
|
using (var realm = realmFactory.CreateContext())
|
|
|
|
{
|
|
|
|
// Due to soft deletions, we can re-use deleted scores between test runs
|
|
|
|
scoreManager.Undelete(realm.All<ScoreInfo>().Where(s => s.DeletePending).ToList());
|
|
|
|
}
|
2019-12-20 05:29:54 +00:00
|
|
|
|
2020-01-07 04:06:30 +00:00
|
|
|
leaderboard.Scores = null;
|
|
|
|
leaderboard.FinishTransforms(true); // After setting scores, we may be waiting for transforms to expire drawables
|
|
|
|
|
2021-10-02 15:55:29 +00:00
|
|
|
leaderboard.BeatmapInfo = beatmapInfo;
|
2020-01-07 04:06:30 +00:00
|
|
|
leaderboard.RefreshScores(); // Required in the case that the beatmap hasn't changed
|
2020-01-06 08:15:59 +00:00
|
|
|
});
|
2019-12-20 05:29:54 +00:00
|
|
|
|
2020-01-07 04:06:30 +00:00
|
|
|
[SetUpSteps]
|
|
|
|
public void SetupSteps()
|
2020-01-06 08:15:59 +00:00
|
|
|
{
|
2020-01-07 04:06:30 +00:00
|
|
|
// Ensure the leaderboard has finished async-loading drawables
|
|
|
|
AddUntilStep("wait for drawables", () => leaderboard.ChildrenOfType<LeaderboardScore>().Any());
|
|
|
|
|
2020-01-06 08:15:59 +00:00
|
|
|
// Ensure the leaderboard items have finished showing up
|
|
|
|
AddStep("finish transforms", () => leaderboard.FinishTransforms(true));
|
2020-01-07 04:06:30 +00:00
|
|
|
}
|
2019-12-20 05:29:54 +00:00
|
|
|
|
2020-01-07 04:06:30 +00:00
|
|
|
[Test]
|
|
|
|
public void TestDeleteViaRightClick()
|
|
|
|
{
|
2021-09-07 07:46:27 +00:00
|
|
|
ScoreInfo scoreBeingDeleted = null;
|
2020-01-06 08:15:59 +00:00
|
|
|
AddStep("open menu for top score", () =>
|
2019-12-20 05:29:54 +00:00
|
|
|
{
|
2021-09-07 07:46:27 +00:00
|
|
|
var leaderboardScore = leaderboard.ChildrenOfType<LeaderboardScore>().First();
|
|
|
|
|
|
|
|
scoreBeingDeleted = leaderboardScore.Score;
|
|
|
|
|
|
|
|
InputManager.MoveMouseTo(leaderboardScore);
|
2020-01-06 08:15:59 +00:00
|
|
|
InputManager.Click(MouseButton.Right);
|
|
|
|
});
|
2019-12-20 05:29:54 +00:00
|
|
|
|
2020-01-06 08:15:59 +00:00
|
|
|
// Ensure the context menu has finished showing
|
|
|
|
AddStep("finish transforms", () => contextMenuContainer.FinishTransforms(true));
|
2019-12-20 05:29:54 +00:00
|
|
|
|
2020-01-06 08:15:59 +00:00
|
|
|
AddStep("click delete option", () =>
|
|
|
|
{
|
2021-02-22 08:14:00 +00:00
|
|
|
InputManager.MoveMouseTo(contextMenuContainer.ChildrenOfType<DrawableOsuMenuItem>().First(i => i.Item.Text.Value.ToString().ToLowerInvariant() == "delete"));
|
2020-01-06 08:15:59 +00:00
|
|
|
InputManager.Click(MouseButton.Left);
|
|
|
|
});
|
2019-12-20 05:29:54 +00:00
|
|
|
|
2020-01-06 08:15:59 +00:00
|
|
|
// Ensure the dialog has finished showing
|
|
|
|
AddStep("finish transforms", () => dialogOverlay.FinishTransforms(true));
|
2019-12-20 05:29:54 +00:00
|
|
|
|
2020-01-06 08:15:59 +00:00
|
|
|
AddStep("click delete button", () =>
|
2019-12-20 05:29:54 +00:00
|
|
|
{
|
2020-01-06 08:15:59 +00:00
|
|
|
InputManager.MoveMouseTo(dialogOverlay.ChildrenOfType<DialogButton>().First());
|
|
|
|
InputManager.Click(MouseButton.Left);
|
|
|
|
});
|
2019-12-20 05:29:54 +00:00
|
|
|
|
2021-10-05 09:17:20 +00:00
|
|
|
AddUntilStep("wait for fetch", () => leaderboard.Scores != null);
|
2021-12-10 06:28:41 +00:00
|
|
|
AddUntilStep("score removed from leaderboard", () => leaderboard.Scores.All(s => s.OnlineID != scoreBeingDeleted.OnlineID));
|
2019-12-20 05:29:54 +00:00
|
|
|
}
|
|
|
|
|
2020-01-06 08:15:59 +00:00
|
|
|
[Test]
|
|
|
|
public void TestDeleteViaDatabase()
|
2019-12-20 05:29:54 +00:00
|
|
|
{
|
2021-09-07 07:46:27 +00:00
|
|
|
AddStep("delete top score", () => scoreManager.Delete(importedScores[0]));
|
2021-10-08 06:26:25 +00:00
|
|
|
AddUntilStep("wait for fetch", () => leaderboard.Scores != null);
|
2021-12-10 06:28:41 +00:00
|
|
|
AddUntilStep("score removed from leaderboard", () => leaderboard.Scores.All(s => s.OnlineID != importedScores[0].OnlineID));
|
2019-12-20 05:29:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|