1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 20:56:12 +08:00
osu-lazer/osu.Game.Tests/Visual/UserInterface/TestSceneDeleteLocalScore.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

183 lines
7.0 KiB
C#
Raw Normal View History

// 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.
2022-06-17 15:37:17 +08:00
#nullable disable
using System.Collections.Generic;
using System.Linq;
2020-01-06 16:15:59 +08:00
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Extensions;
using osu.Framework.Graphics;
2020-01-06 16:15:59 +08:00
using osu.Framework.Graphics.Cursor;
using osu.Framework.Platform;
using osu.Framework.Testing;
2020-01-10 01:38:03 +08:00
using osu.Framework.Utils;
using osu.Game.Beatmaps;
using osu.Game.Database;
2020-01-06 16:15:59 +08:00
using osu.Game.Graphics.Cursor;
using osu.Game.Graphics.UserInterface;
using osu.Game.Models;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Leaderboards;
using osu.Game.Overlays;
2020-01-06 16:15:59 +08:00
using osu.Game.Rulesets;
using osu.Game.Rulesets.Osu;
using osu.Game.Scoring;
using osu.Game.Screens.Select.Leaderboards;
2020-01-06 16:15:59 +08:00
using osu.Game.Tests.Resources;
using osuTK;
2020-01-06 16:15:59 +08:00
using osuTK.Input;
namespace osu.Game.Tests.Visual.UserInterface
{
public partial class TestSceneDeleteLocalScore : OsuManualInputManagerTestScene
{
2020-01-06 16:15:59 +08:00
private readonly ContextMenuContainer contextMenuContainer;
private readonly BeatmapLeaderboard leaderboard;
private BeatmapManager beatmapManager;
private ScoreManager scoreManager;
private readonly List<ScoreInfo> importedScores = new List<ScoreInfo>();
2021-10-02 23:55:29 +08:00
private BeatmapInfo beatmapInfo;
[Cached(typeof(IDialogOverlay))]
2019-12-20 13:57:14 +08:00
private readonly DialogOverlay dialogOverlay;
public TestSceneDeleteLocalScore()
{
2020-01-06 16:15:59 +08:00
Children = new Drawable[]
{
2020-01-06 16:15:59 +08:00
contextMenuContainer = new OsuContextMenuContainer
{
2020-01-06 16:15:59 +08:00
RelativeSizeAxes = Axes.Both,
Child = leaderboard = new BeatmapLeaderboard
{
2020-01-06 16:15:59 +08:00
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Size = new Vector2(550f, 450f),
Scope = BeatmapLeaderboardScope.Local,
BeatmapInfo = TestResources.CreateTestBeatmapSetInfo().Beatmaps.First()
2020-01-06 16:15:59 +08:00
}
},
2020-01-06 16:15:59 +08:00
dialogOverlay = new DialogOverlay()
};
}
2020-01-06 16:15:59 +08:00
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
{
2020-01-06 16:15:59 +08:00
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
dependencies.Cache(new RealmRulesetStore(Realm));
dependencies.Cache(beatmapManager = new BeatmapManager(LocalStorage, Realm, null, dependencies.Get<AudioManager>(), Resources, dependencies.Get<GameHost>(), Beatmap.Default));
2022-08-22 20:31:30 +08:00
dependencies.Cache(scoreManager = new ScoreManager(dependencies.Get<RulesetStore>(), () => beatmapManager, LocalStorage, Realm, API));
Dependencies.Cache(Realm);
return dependencies;
}
[BackgroundDependencyLoader]
private void load() => Schedule(() =>
{
var imported = beatmapManager.Import(new ImportTask(TestResources.GetQuickTestBeatmapForImport())).GetResultSafely();
imported?.PerformRead(s =>
{
beatmapInfo = s.Beatmaps[0];
for (int i = 0; i < 50; i++)
2020-01-06 16:15:59 +08:00
{
var score = new ScoreInfo
{
OnlineID = i,
BeatmapInfo = beatmapInfo,
2023-02-07 16:52:47 +08:00
BeatmapHash = beatmapInfo.Hash,
Accuracy = RNG.NextDouble(),
TotalScore = RNG.Next(1, 1000000),
MaxCombo = RNG.Next(1, 1000),
Rank = ScoreRank.XH,
User = new APIUser { Username = "TestUser" },
Ruleset = new OsuRuleset().RulesetInfo,
Files = { new RealmNamedFileUsage(new RealmFile { Hash = $"{i}" }, string.Empty) }
};
importedScores.Add(scoreManager.Import(score).Value);
}
});
2020-01-06 16:15:59 +08:00
});
[SetUpSteps]
public void SetupSteps()
2020-01-06 16:15:59 +08:00
{
AddUntilStep("ensure scores imported", () => importedScores.Count == 50);
AddStep("undelete scores", () =>
{
Realm.Run(r =>
{
// Due to soft deletions, we can re-use deleted scores between test runs
scoreManager.Undelete(r.All<ScoreInfo>().Where(s => s.DeletePending).ToList());
});
});
AddStep("set up leaderboard", () =>
{
leaderboard.BeatmapInfo = beatmapInfo;
leaderboard.RefetchScores(); // Required in the case that the beatmap hasn't changed
});
2020-01-06 16:15:59 +08:00
// Ensure the leaderboard items have finished showing up
AddStep("finish transforms", () => leaderboard.FinishTransforms(true));
AddUntilStep("wait for drawables", () => leaderboard.ChildrenOfType<LeaderboardScore>().Any());
}
[Test]
public void TestDeleteViaRightClick()
{
ScoreInfo scoreBeingDeleted = null;
2020-01-06 16:15:59 +08:00
AddStep("open menu for top score", () =>
{
var leaderboardScore = leaderboard.ChildrenOfType<LeaderboardScore>().First();
scoreBeingDeleted = leaderboardScore.Score;
InputManager.MoveMouseTo(leaderboardScore);
2020-01-06 16:15:59 +08:00
InputManager.Click(MouseButton.Right);
});
2020-01-06 16:15:59 +08:00
// Ensure the context menu has finished showing
AddStep("finish transforms", () => contextMenuContainer.FinishTransforms(true));
2020-01-06 16:15:59 +08:00
AddStep("click delete option", () =>
{
InputManager.MoveMouseTo(contextMenuContainer.ChildrenOfType<DrawableOsuMenuItem>().First(i => i.Item.Text.Value.ToString().ToLowerInvariant() == "delete"));
2020-01-06 16:15:59 +08:00
InputManager.Click(MouseButton.Left);
});
2020-01-06 16:15:59 +08:00
// Ensure the dialog has finished showing
AddStep("finish transforms", () => dialogOverlay.FinishTransforms(true));
2020-01-06 16:15:59 +08:00
AddStep("click delete button", () =>
{
2020-01-06 16:15:59 +08:00
InputManager.MoveMouseTo(dialogOverlay.ChildrenOfType<DialogButton>().First());
InputManager.PressButton(MouseButton.Left);
2020-01-06 16:15:59 +08:00
});
2022-09-26 16:59:39 +08:00
AddUntilStep("wait for fetch", () => leaderboard.Scores.Any());
AddUntilStep("score removed from leaderboard", () => leaderboard.Scores.All(s => s.OnlineID != scoreBeingDeleted.OnlineID));
2022-04-05 05:02:07 +08:00
// "Clean up"
AddStep("release left mouse button", () => InputManager.ReleaseButton(MouseButton.Left));
}
2020-01-06 16:15:59 +08:00
[Test]
public void TestDeleteViaDatabase()
{
AddStep("delete top score", () => scoreManager.Delete(importedScores[0]));
2022-09-26 16:59:39 +08:00
AddUntilStep("wait for fetch", () => leaderboard.Scores.Any());
AddUntilStep("score removed from leaderboard", () => leaderboard.Scores.All(s => s.OnlineID != importedScores[0].OnlineID));
}
}
}