1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 15:27:24 +08:00

Merge pull request #16481 from peppy/fix-scores-container-tests

Rewrite `TestSceneScoresContainer` to work again
This commit is contained in:
Dan Balasescu 2022-01-17 20:39:14 +09:00 committed by GitHub
commit e9c96908d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 142 additions and 108 deletions

View File

@ -1,11 +1,15 @@
// 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;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Testing;
using osu.Framework.Utils;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests.Responses;
@ -24,10 +28,11 @@ namespace osu.Game.Tests.Visual.Online
[Cached]
private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Blue);
public TestSceneScoresContainer()
{
TestScoresContainer scoresContainer;
private TestScoresContainer scoresContainer;
[SetUpSteps]
public void SetUp() => Schedule(() =>
{
Child = new Container
{
Anchor = Anchor.TopCentre,
@ -41,16 +46,110 @@ namespace osu.Game.Tests.Visual.Online
RelativeSizeAxes = Axes.Both,
Colour = Color4.Black,
},
scoresContainer = new TestScoresContainer(),
scoresContainer = new TestScoresContainer
{
Beatmap = { Value = CreateAPIBeatmap() }
}
}
};
});
var allScores = new APIScoresCollection
[Test]
public void TestNoUserBest()
{
AddStep("Scores with no user best", () =>
{
var allScores = createScores();
allScores.UserScore = null;
scoresContainer.Scores = allScores;
});
AddUntilStep("wait for scores displayed", () => scoresContainer.ChildrenOfType<ScoreTableRowBackground>().Any());
AddAssert("no user best displayed", () => scoresContainer.ChildrenOfType<DrawableTopScore>().Count() == 1);
AddStep("Load null scores", () => scoresContainer.Scores = null);
AddUntilStep("wait for scores not displayed", () => !scoresContainer.ChildrenOfType<ScoreTableRowBackground>().Any());
AddAssert("no best score displayed", () => !scoresContainer.ChildrenOfType<DrawableTopScore>().Any());
AddStep("Load only one score", () =>
{
var allScores = createScores();
allScores.Scores.RemoveRange(1, allScores.Scores.Count - 1);
scoresContainer.Scores = allScores;
});
AddUntilStep("wait for scores not displayed", () => scoresContainer.ChildrenOfType<ScoreTableRowBackground>().Count() == 1);
AddAssert("no best score displayed", () => scoresContainer.ChildrenOfType<DrawableTopScore>().Count() == 1);
}
[Test]
public void TestUserBest()
{
AddStep("Load scores with personal best", () =>
{
var allScores = createScores();
allScores.UserScore = createUserBest();
scoresContainer.Scores = allScores;
});
AddUntilStep("wait for scores displayed", () => scoresContainer.ChildrenOfType<ScoreTableRowBackground>().Any());
AddAssert("best score displayed", () => scoresContainer.ChildrenOfType<DrawableTopScore>().Count() == 2);
AddStep("Load scores with personal best (null position)", () =>
{
var allScores = createScores();
var userBest = createUserBest();
userBest.Position = null;
allScores.UserScore = userBest;
scoresContainer.Scores = allScores;
});
AddUntilStep("wait for scores displayed", () => scoresContainer.ChildrenOfType<ScoreTableRowBackground>().Any());
AddAssert("best score displayed", () => scoresContainer.ChildrenOfType<DrawableTopScore>().Count() == 2);
AddStep("Load scores with personal best (first place)", () =>
{
var allScores = createScores();
allScores.UserScore = new APIScoreWithPosition
{
Score = allScores.Scores.First(),
Position = 1,
};
scoresContainer.Scores = allScores;
});
AddUntilStep("wait for scores displayed", () => scoresContainer.ChildrenOfType<ScoreTableRowBackground>().Any());
AddAssert("best score displayed", () => scoresContainer.ChildrenOfType<DrawableTopScore>().Count() == 1);
AddStep("Scores with no user best", () =>
{
var allScores = createScores();
allScores.UserScore = null;
scoresContainer.Scores = allScores;
});
AddUntilStep("best score not displayed", () => scoresContainer.ChildrenOfType<DrawableTopScore>().Count() == 1);
}
private int onlineID = 1;
private APIScoresCollection createScores()
{
var scores = new APIScoresCollection
{
Scores = new List<APIScore>
{
new APIScore
{
Date = DateTimeOffset.Now,
OnlineID = onlineID++,
User = new APIUser
{
Id = 6602580,
@ -76,6 +175,8 @@ namespace osu.Game.Tests.Visual.Online
},
new APIScore
{
Date = DateTimeOffset.Now,
OnlineID = onlineID++,
User = new APIUser
{
Id = 4608074,
@ -100,6 +201,8 @@ namespace osu.Game.Tests.Visual.Online
},
new APIScore
{
Date = DateTimeOffset.Now,
OnlineID = onlineID++,
User = new APIUser
{
Id = 1014222,
@ -123,6 +226,8 @@ namespace osu.Game.Tests.Visual.Online
},
new APIScore
{
Date = DateTimeOffset.Now,
OnlineID = onlineID++,
User = new APIUser
{
Id = 1541390,
@ -145,6 +250,8 @@ namespace osu.Game.Tests.Visual.Online
},
new APIScore
{
Date = DateTimeOffset.Now,
OnlineID = onlineID++,
User = new APIUser
{
Id = 7151382,
@ -164,85 +271,7 @@ namespace osu.Game.Tests.Visual.Online
}
};
var myBestScore = new APIScoreWithPosition
{
Score = new APIScore
{
User = new APIUser
{
Id = 7151382,
Username = @"Mayuri Hana",
Country = new Country
{
FullName = @"Thailand",
FlagName = @"TH",
},
},
Rank = ScoreRank.D,
PP = 160,
MaxCombo = 1234,
TotalScore = 123456,
Accuracy = 0.6543,
},
Position = 1337,
};
var myBestScoreWithNullPosition = new APIScoreWithPosition
{
Score = new APIScore
{
User = new APIUser
{
Id = 7151382,
Username = @"Mayuri Hana",
Country = new Country
{
FullName = @"Thailand",
FlagName = @"TH",
},
},
Rank = ScoreRank.D,
PP = 160,
MaxCombo = 1234,
TotalScore = 123456,
Accuracy = 0.6543,
},
Position = null,
};
var oneScore = new APIScoresCollection
{
Scores = new List<APIScore>
{
new APIScore
{
User = new APIUser
{
Id = 6602580,
Username = @"waaiiru",
Country = new Country
{
FullName = @"Spain",
FlagName = @"ES",
},
},
Mods = new[]
{
new APIMod { Acronym = new OsuModDoubleTime().Acronym },
new APIMod { Acronym = new OsuModHidden().Acronym },
new APIMod { Acronym = new OsuModFlashlight().Acronym },
new APIMod { Acronym = new OsuModHardRock().Acronym },
},
Rank = ScoreRank.XH,
PP = 200,
MaxCombo = 1234,
TotalScore = 1234567890,
Accuracy = 1,
}
}
};
foreach (var s in allScores.Scores)
foreach (var s in scores.Scores)
{
s.Statistics = new Dictionary<string, int>
{
@ -253,26 +282,34 @@ namespace osu.Game.Tests.Visual.Online
};
}
AddStep("Load all scores", () =>
{
allScores.UserScore = null;
scoresContainer.Scores = allScores;
});
AddStep("Load null scores", () => scoresContainer.Scores = null);
AddStep("Load only one score", () => scoresContainer.Scores = oneScore);
AddStep("Load scores with my best", () =>
{
allScores.UserScore = myBestScore;
scoresContainer.Scores = allScores;
});
AddStep("Load scores with null my best position", () =>
{
allScores.UserScore = myBestScoreWithNullPosition;
scoresContainer.Scores = allScores;
});
return scores;
}
private APIScoreWithPosition createUserBest() => new APIScoreWithPosition
{
Score = new APIScore
{
Date = DateTimeOffset.Now,
OnlineID = onlineID++,
User = new APIUser
{
Id = 7151382,
Username = @"Mayuri Hana",
Country = new Country
{
FullName = @"Thailand",
FlagName = @"TH",
},
},
Rank = ScoreRank.D,
PP = 160,
MaxCombo = 1234,
TotalScore = 123456,
Accuracy = 0.6543,
},
Position = 1337,
};
private class TestScoresContainer : ScoresContainer
{
public new APIScoresCollection Scores

View File

@ -65,6 +65,9 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
scoreTable.ClearScores();
scoreTable.Hide();
loading.Hide();
loading.FinishTransforms();
if (value?.Scores.Any() != true)
return;
@ -258,9 +261,6 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
{
Scores = null;
notSupporterPlaceholder.Show();
loading.Hide();
loading.FinishTransforms();
return;
}
@ -272,9 +272,6 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
getScoresRequest = new GetScoresRequest(Beatmap.Value, Beatmap.Value.Ruleset, scope.Value, modSelector.SelectedMods);
getScoresRequest.Success += scores =>
{
loading.Hide();
loading.FinishTransforms();
Scores = scores;
if (!scores.Scores.Any())