Fix TestSceneDeleteLocalScore not properly comparing post-delete scores

This commit is contained in:
Dean Herbert 2021-09-07 16:46:27 +09:00
parent f3d2d93aa1
commit d922210d2f
2 changed files with 25 additions and 21 deletions

View File

@ -36,7 +36,7 @@ namespace osu.Game.Tests.Visual.UserInterface
private BeatmapManager beatmapManager; private BeatmapManager beatmapManager;
private ScoreManager scoreManager; private ScoreManager scoreManager;
private readonly List<ScoreInfo> scores = new List<ScoreInfo>(); private readonly List<ScoreInfo> importedScores = new List<ScoreInfo>();
private BeatmapInfo beatmap; private BeatmapInfo beatmap;
[Cached] [Cached]
@ -100,11 +100,9 @@ namespace osu.Game.Tests.Visual.UserInterface
User = new User { Username = "TestUser" }, User = new User { Username = "TestUser" },
}; };
scores.Add(scoreManager.Import(score).Result); importedScores.Add(scoreManager.Import(score).Result);
} }
scores.Sort(Comparer<ScoreInfo>.Create((s1, s2) => s2.TotalScore.CompareTo(s1.TotalScore)));
return dependencies; return dependencies;
} }
@ -134,9 +132,14 @@ namespace osu.Game.Tests.Visual.UserInterface
[Test] [Test]
public void TestDeleteViaRightClick() public void TestDeleteViaRightClick()
{ {
ScoreInfo scoreBeingDeleted = null;
AddStep("open menu for top score", () => AddStep("open menu for top score", () =>
{ {
InputManager.MoveMouseTo(leaderboard.ChildrenOfType<LeaderboardScore>().First()); var leaderboardScore = leaderboard.ChildrenOfType<LeaderboardScore>().First();
scoreBeingDeleted = leaderboardScore.Score;
InputManager.MoveMouseTo(leaderboardScore);
InputManager.Click(MouseButton.Right); InputManager.Click(MouseButton.Right);
}); });
@ -158,14 +161,14 @@ namespace osu.Game.Tests.Visual.UserInterface
InputManager.Click(MouseButton.Left); InputManager.Click(MouseButton.Left);
}); });
AddUntilStep("score removed from leaderboard", () => leaderboard.Scores.All(s => s != scores[0])); AddUntilStep("score removed from leaderboard", () => leaderboard.Scores.All(s => s.OnlineScoreID != scoreBeingDeleted.OnlineScoreID));
} }
[Test] [Test]
public void TestDeleteViaDatabase() public void TestDeleteViaDatabase()
{ {
AddStep("delete top score", () => scoreManager.Delete(scores[0])); AddStep("delete top score", () => scoreManager.Delete(importedScores[0]));
AddUntilStep("score removed from leaderboard", () => leaderboard.Scores.All(s => s != scores[0])); AddUntilStep("score removed from leaderboard", () => leaderboard.Scores.All(s => s.OnlineScoreID != importedScores[0].OnlineScoreID));
} }
} }
} }

View File

@ -34,6 +34,8 @@ namespace osu.Game.Online.Leaderboards
{ {
public const float HEIGHT = 60; public const float HEIGHT = 60;
public readonly ScoreInfo Score;
private const float corner_radius = 5; private const float corner_radius = 5;
private const float edge_margin = 5; private const float edge_margin = 5;
private const float background_alpha = 0.25f; private const float background_alpha = 0.25f;
@ -41,7 +43,6 @@ namespace osu.Game.Online.Leaderboards
protected Container RankContainer { get; private set; } protected Container RankContainer { get; private set; }
private readonly ScoreInfo score;
private readonly int? rank; private readonly int? rank;
private readonly bool allowHighlight; private readonly bool allowHighlight;
@ -67,7 +68,7 @@ namespace osu.Game.Online.Leaderboards
public LeaderboardScore(ScoreInfo score, int? rank, bool allowHighlight = true) public LeaderboardScore(ScoreInfo score, int? rank, bool allowHighlight = true)
{ {
this.score = score; this.Score = score;
this.rank = rank; this.rank = rank;
this.allowHighlight = allowHighlight; this.allowHighlight = allowHighlight;
@ -78,9 +79,9 @@ namespace osu.Game.Online.Leaderboards
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(IAPIProvider api, OsuColour colour, ScoreManager scoreManager) private void load(IAPIProvider api, OsuColour colour, ScoreManager scoreManager)
{ {
var user = score.User; var user = Score.User;
statisticsLabels = GetStatistics(score).Select(s => new ScoreComponentLabel(s)).ToList(); statisticsLabels = GetStatistics(Score).Select(s => new ScoreComponentLabel(s)).ToList();
ClickableAvatar innerAvatar; ClickableAvatar innerAvatar;
@ -198,7 +199,7 @@ namespace osu.Game.Online.Leaderboards
{ {
TextColour = Color4.White, TextColour = Color4.White,
GlowColour = Color4Extensions.FromHex(@"83ccfa"), GlowColour = Color4Extensions.FromHex(@"83ccfa"),
Current = scoreManager.GetBindableTotalScoreString(score), Current = scoreManager.GetBindableTotalScoreString(Score),
Font = OsuFont.Numeric.With(size: 23), Font = OsuFont.Numeric.With(size: 23),
}, },
RankContainer = new Container RankContainer = new Container
@ -206,7 +207,7 @@ namespace osu.Game.Online.Leaderboards
Size = new Vector2(40f, 20f), Size = new Vector2(40f, 20f),
Children = new[] Children = new[]
{ {
scoreRank = new UpdateableRank(score.Rank) scoreRank = new UpdateableRank(Score.Rank)
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
@ -223,7 +224,7 @@ namespace osu.Game.Online.Leaderboards
AutoSizeAxes = Axes.Both, AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal, Direction = FillDirection.Horizontal,
Spacing = new Vector2(1), Spacing = new Vector2(1),
ChildrenEnumerable = score.Mods.Select(mod => new ModIcon(mod) { Scale = new Vector2(0.375f) }) ChildrenEnumerable = Score.Mods.Select(mod => new ModIcon(mod) { Scale = new Vector2(0.375f) })
}, },
}, },
}, },
@ -389,14 +390,14 @@ namespace osu.Game.Online.Leaderboards
{ {
List<MenuItem> items = new List<MenuItem>(); List<MenuItem> items = new List<MenuItem>();
if (score.Mods.Length > 0 && modsContainer.Any(s => s.IsHovered) && songSelect != null) if (Score.Mods.Length > 0 && modsContainer.Any(s => s.IsHovered) && songSelect != null)
items.Add(new OsuMenuItem("Use these mods", MenuItemType.Highlighted, () => songSelect.Mods.Value = score.Mods)); items.Add(new OsuMenuItem("Use these mods", MenuItemType.Highlighted, () => songSelect.Mods.Value = Score.Mods));
if (score.Files?.Count > 0) if (Score.Files?.Count > 0)
items.Add(new OsuMenuItem("Export", MenuItemType.Standard, () => scoreManager.Export(score))); items.Add(new OsuMenuItem("Export", MenuItemType.Standard, () => scoreManager.Export(Score)));
if (score.ID != 0) if (Score.ID != 0)
items.Add(new OsuMenuItem("Delete", MenuItemType.Destructive, () => dialogOverlay?.Push(new LocalScoreDeleteDialog(score)))); items.Add(new OsuMenuItem("Delete", MenuItemType.Destructive, () => dialogOverlay?.Push(new LocalScoreDeleteDialog(Score))));
return items.ToArray(); return items.ToArray();
} }