2019-12-20 13:29:54 +08: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.
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
2020-01-06 16:15:59 +08:00
|
|
|
using NUnit.Framework;
|
2019-12-20 13:29:54 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Allocation;
|
2020-08-12 23:29:23 +08:00
|
|
|
using osu.Framework.Audio;
|
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;
|
2019-12-20 13:29:54 +08:00
|
|
|
using osu.Game.Beatmaps;
|
2020-12-07 17:00:45 +08:00
|
|
|
using osu.Game.Database;
|
2020-01-06 16:15:59 +08:00
|
|
|
using osu.Game.Graphics.Cursor;
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2019-12-20 13:29:54 +08:00
|
|
|
using osu.Game.Online.Leaderboards;
|
|
|
|
using osu.Game.Overlays;
|
2020-01-06 16:15:59 +08:00
|
|
|
using osu.Game.Rulesets;
|
2019-12-20 13:29:54 +08:00
|
|
|
using osu.Game.Scoring;
|
|
|
|
using osu.Game.Screens.Select.Leaderboards;
|
2020-01-06 16:15:59 +08:00
|
|
|
using osu.Game.Tests.Resources;
|
2019-12-20 13:29:54 +08:00
|
|
|
using osu.Game.Users;
|
|
|
|
using osuTK;
|
2020-01-06 16:15:59 +08:00
|
|
|
using osuTK.Input;
|
2019-12-20 13:29:54 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.UserInterface
|
|
|
|
{
|
2020-03-23 09:01:33 +08:00
|
|
|
public class TestSceneDeleteLocalScore : OsuManualInputManagerTestScene
|
2019-12-20 13:29:54 +08:00
|
|
|
{
|
2020-01-06 16:15:59 +08:00
|
|
|
private readonly ContextMenuContainer contextMenuContainer;
|
|
|
|
private readonly BeatmapLeaderboard leaderboard;
|
|
|
|
|
|
|
|
private RulesetStore rulesetStore;
|
|
|
|
private BeatmapManager beatmapManager;
|
|
|
|
private ScoreManager scoreManager;
|
|
|
|
|
|
|
|
private readonly List<ScoreInfo> scores = new List<ScoreInfo>();
|
|
|
|
private BeatmapInfo beatmap;
|
2019-12-20 13:29:54 +08:00
|
|
|
|
2020-01-04 03:34:26 +08:00
|
|
|
[Cached]
|
2019-12-20 13:57:14 +08:00
|
|
|
private readonly DialogOverlay dialogOverlay;
|
2019-12-20 13:29:54 +08:00
|
|
|
|
|
|
|
public TestSceneDeleteLocalScore()
|
|
|
|
{
|
2020-01-06 16:15:59 +08:00
|
|
|
Children = new Drawable[]
|
2019-12-20 13:29:54 +08:00
|
|
|
{
|
2020-01-06 16:15:59 +08:00
|
|
|
contextMenuContainer = new OsuContextMenuContainer
|
2019-12-20 13:29:54 +08:00
|
|
|
{
|
2020-01-06 16:15:59 +08:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Child = leaderboard = new BeatmapLeaderboard
|
2019-12-20 13:29:54 +08:00
|
|
|
{
|
2020-01-06 16:15:59 +08:00
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Size = new Vector2(550f, 450f),
|
|
|
|
Scope = BeatmapLeaderboardScope.Local,
|
|
|
|
Beatmap = new BeatmapInfo
|
2019-12-20 13:29:54 +08:00
|
|
|
{
|
2020-01-06 16:15:59 +08:00
|
|
|
ID = 1,
|
|
|
|
Metadata = new BeatmapMetadata
|
|
|
|
{
|
|
|
|
ID = 1,
|
|
|
|
Title = "TestSong",
|
|
|
|
Artist = "TestArtist",
|
|
|
|
Author = new User
|
|
|
|
{
|
|
|
|
Username = "TestAuthor"
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Version = "Insane"
|
2019-12-20 13:29:54 +08:00
|
|
|
},
|
2020-01-06 16:15:59 +08:00
|
|
|
}
|
2019-12-20 13:29:54 +08:00
|
|
|
},
|
2020-01-06 16:15:59 +08:00
|
|
|
dialogOverlay = new DialogOverlay()
|
|
|
|
};
|
2019-12-20 13:29:54 +08:00
|
|
|
}
|
|
|
|
|
2020-01-06 16:15:59 +08:00
|
|
|
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
|
2019-12-20 13:29:54 +08:00
|
|
|
{
|
2020-01-06 16:15:59 +08:00
|
|
|
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
|
2019-12-20 13:29:54 +08:00
|
|
|
|
2020-01-06 16:15:59 +08:00
|
|
|
dependencies.Cache(rulesetStore = new RulesetStore(ContextFactory));
|
2020-08-12 23:29:23 +08:00
|
|
|
dependencies.Cache(beatmapManager = new BeatmapManager(LocalStorage, ContextFactory, rulesetStore, null, dependencies.Get<AudioManager>(), dependencies.Get<GameHost>(), Beatmap.Default));
|
2020-01-06 16:15:59 +08:00
|
|
|
dependencies.Cache(scoreManager = new ScoreManager(rulesetStore, () => beatmapManager, LocalStorage, null, ContextFactory));
|
2019-12-20 13:29:54 +08:00
|
|
|
|
2021-02-22 13:53:32 +08:00
|
|
|
beatmap = beatmapManager.Import(new ImportTask(TestResources.GetQuickTestBeatmapForImport())).Result.Beatmaps[0];
|
2019-12-20 13:29:54 +08:00
|
|
|
|
2020-01-06 16:15:59 +08:00
|
|
|
for (int i = 0; i < 50; i++)
|
2019-12-20 13:29:54 +08:00
|
|
|
{
|
2020-01-06 16:15:59 +08:00
|
|
|
var score = new ScoreInfo
|
|
|
|
{
|
|
|
|
OnlineScoreID = i,
|
|
|
|
Beatmap = beatmap,
|
|
|
|
BeatmapInfoID = beatmap.ID,
|
|
|
|
Accuracy = RNG.NextDouble(),
|
|
|
|
TotalScore = RNG.Next(1, 1000000),
|
|
|
|
MaxCombo = RNG.Next(1, 1000),
|
|
|
|
Rank = ScoreRank.XH,
|
|
|
|
User = new User { Username = "TestUser" },
|
|
|
|
};
|
2019-12-20 13:29:54 +08:00
|
|
|
|
2020-01-06 16:15:59 +08:00
|
|
|
scores.Add(scoreManager.Import(score).Result);
|
2019-12-20 13:29:54 +08:00
|
|
|
}
|
|
|
|
|
2020-01-06 16:15:59 +08:00
|
|
|
scores.Sort(Comparer<ScoreInfo>.Create((s1, s2) => s2.TotalScore.CompareTo(s1.TotalScore)));
|
2019-12-20 13:29:54 +08:00
|
|
|
|
2020-01-06 16:15:59 +08:00
|
|
|
return dependencies;
|
|
|
|
}
|
2019-12-20 13:29:54 +08:00
|
|
|
|
2020-01-06 16:15:59 +08:00
|
|
|
[SetUp]
|
|
|
|
public void Setup() => Schedule(() =>
|
|
|
|
{
|
|
|
|
// Due to soft deletions, we can re-use deleted scores between test runs
|
|
|
|
scoreManager.Undelete(scoreManager.QueryScores(s => s.DeletePending).ToList());
|
2019-12-20 13:29:54 +08:00
|
|
|
|
2020-01-07 12:06:30 +08:00
|
|
|
leaderboard.Scores = null;
|
|
|
|
leaderboard.FinishTransforms(true); // After setting scores, we may be waiting for transforms to expire drawables
|
|
|
|
|
2020-01-06 16:15:59 +08:00
|
|
|
leaderboard.Beatmap = beatmap;
|
2020-01-07 12:06:30 +08:00
|
|
|
leaderboard.RefreshScores(); // Required in the case that the beatmap hasn't changed
|
2020-01-06 16:15:59 +08:00
|
|
|
});
|
2019-12-20 13:29:54 +08:00
|
|
|
|
2020-01-07 12:06:30 +08:00
|
|
|
[SetUpSteps]
|
|
|
|
public void SetupSteps()
|
2020-01-06 16:15:59 +08:00
|
|
|
{
|
2020-01-07 12:06:30 +08:00
|
|
|
// Ensure the leaderboard has finished async-loading drawables
|
|
|
|
AddUntilStep("wait for drawables", () => leaderboard.ChildrenOfType<LeaderboardScore>().Any());
|
|
|
|
|
2020-01-06 16:15:59 +08:00
|
|
|
// Ensure the leaderboard items have finished showing up
|
|
|
|
AddStep("finish transforms", () => leaderboard.FinishTransforms(true));
|
2020-01-07 12:06:30 +08:00
|
|
|
}
|
2019-12-20 13:29:54 +08:00
|
|
|
|
2020-01-07 12:06:30 +08:00
|
|
|
[Test]
|
|
|
|
public void TestDeleteViaRightClick()
|
|
|
|
{
|
2020-01-06 16:15:59 +08:00
|
|
|
AddStep("open menu for top score", () =>
|
2019-12-20 13:29:54 +08:00
|
|
|
{
|
2020-01-06 16:15:59 +08:00
|
|
|
InputManager.MoveMouseTo(leaderboard.ChildrenOfType<LeaderboardScore>().First());
|
|
|
|
InputManager.Click(MouseButton.Right);
|
|
|
|
});
|
2019-12-20 13:29:54 +08:00
|
|
|
|
2020-01-06 16:15:59 +08:00
|
|
|
// Ensure the context menu has finished showing
|
|
|
|
AddStep("finish transforms", () => contextMenuContainer.FinishTransforms(true));
|
2019-12-20 13:29:54 +08:00
|
|
|
|
2020-01-06 16:15:59 +08:00
|
|
|
AddStep("click delete option", () =>
|
|
|
|
{
|
2021-02-22 16:14:00 +08:00
|
|
|
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);
|
|
|
|
});
|
2019-12-20 13:29:54 +08:00
|
|
|
|
2020-01-06 16:15:59 +08:00
|
|
|
// Ensure the dialog has finished showing
|
|
|
|
AddStep("finish transforms", () => dialogOverlay.FinishTransforms(true));
|
2019-12-20 13:29:54 +08:00
|
|
|
|
2020-01-06 16:15:59 +08:00
|
|
|
AddStep("click delete button", () =>
|
2019-12-20 13:29:54 +08:00
|
|
|
{
|
2020-01-06 16:15:59 +08:00
|
|
|
InputManager.MoveMouseTo(dialogOverlay.ChildrenOfType<DialogButton>().First());
|
|
|
|
InputManager.Click(MouseButton.Left);
|
|
|
|
});
|
2019-12-20 13:29:54 +08:00
|
|
|
|
2020-01-06 16:15:59 +08:00
|
|
|
AddUntilStep("score removed from leaderboard", () => leaderboard.Scores.All(s => s.OnlineScoreID != scores[0].OnlineScoreID));
|
2019-12-20 13:29:54 +08:00
|
|
|
}
|
|
|
|
|
2020-01-06 16:15:59 +08:00
|
|
|
[Test]
|
|
|
|
public void TestDeleteViaDatabase()
|
2019-12-20 13:29:54 +08:00
|
|
|
{
|
2020-01-06 16:15:59 +08:00
|
|
|
AddStep("delete top score", () => scoreManager.Delete(scores[0]));
|
|
|
|
AddUntilStep("score removed from leaderboard", () => leaderboard.Scores.All(s => s.OnlineScoreID != scores[0].OnlineScoreID));
|
2019-12-20 13:29:54 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|