Merge pull request #16158 from bdach/is-ranked-user-profile

Fix rank graph showing for unranked users on profile overlay
This commit is contained in:
Dan Balasescu
2021-12-20 09:14:17 +09:00
committed by GitHub
4 changed files with 58 additions and 46 deletions

View File

@ -2,9 +2,10 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System; using System;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Game.Online.API; using osu.Framework.Testing;
using osu.Game.Online.API.Requests;
using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.API.Requests.Responses;
using osu.Game.Overlays; using osu.Game.Overlays;
using osu.Game.Overlays.Profile; using osu.Game.Overlays.Profile;
@ -14,72 +15,77 @@ namespace osu.Game.Tests.Visual.Online
{ {
public class TestSceneUserProfileHeader : OsuTestScene public class TestSceneUserProfileHeader : OsuTestScene
{ {
protected override bool UseOnlineAPI => true;
[Cached] [Cached]
private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Green); private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Green);
[Resolved] private ProfileHeader header;
private IAPIProvider api { get; set; }
private readonly ProfileHeader header; [SetUpSteps]
public void SetUpSteps()
public TestSceneUserProfileHeader()
{ {
header = new ProfileHeader(); AddStep("create header", () => Child = header = new ProfileHeader());
Add(header); }
AddStep("Show test dummy", () => header.User.Value = TestSceneUserProfileOverlay.TEST_USER); [Test]
public void TestBasic()
AddStep("Show null dummy", () => header.User.Value = new APIUser
{ {
Username = "Null" AddStep("Show example user", () => header.User.Value = TestSceneUserProfileOverlay.TEST_USER);
}); }
AddStep("Show online dummy", () => header.User.Value = new APIUser [Test]
public void TestOnlineState()
{ {
AddStep("Show online user", () => header.User.Value = new APIUser
{
Id = 1001,
Username = "IAmOnline", Username = "IAmOnline",
LastVisit = DateTimeOffset.Now, LastVisit = DateTimeOffset.Now,
IsOnline = true, IsOnline = true,
}); });
AddStep("Show offline dummy", () => header.User.Value = new APIUser AddStep("Show offline user", () => header.User.Value = new APIUser
{ {
Id = 1002,
Username = "IAmOffline", Username = "IAmOffline",
LastVisit = DateTimeOffset.Now, LastVisit = DateTimeOffset.Now.AddDays(-10),
IsOnline = false, IsOnline = false,
}); });
addOnlineStep("Show ppy", new APIUser
{
Username = @"peppy",
Id = 2,
IsSupporter = true,
Country = new Country { FullName = @"Australia", FlagName = @"AU" },
CoverUrl = @"https://osu.ppy.sh/images/headers/profile-covers/c3.jpg"
});
addOnlineStep("Show flyte", new APIUser
{
Username = @"flyte",
Id = 3103765,
Country = new Country { FullName = @"Japan", FlagName = @"JP" },
CoverUrl = @"https://osu.ppy.sh/images/headers/profile-covers/c6.jpg"
});
} }
private void addOnlineStep(string name, APIUser fallback) [Test]
public void TestRankedState()
{ {
AddStep(name, () => AddStep("Show ranked user", () => header.User.Value = new APIUser
{ {
if (api.IsLoggedIn) Id = 2001,
Username = "RankedUser",
Statistics = new UserStatistics
{ {
var request = new GetUserRequest(fallback.Id); IsRanked = true,
request.Success += user => header.User.Value = user; GlobalRank = 15000,
api.Queue(request); CountryRank = 1500,
RankHistory = new APIRankHistory
{
Mode = @"osu",
Data = Enumerable.Range(2345, 45).Concat(Enumerable.Range(2109, 40)).ToArray()
},
}
});
AddStep("Show unranked user", () => header.User.Value = new APIUser
{
Id = 2002,
Username = "UnrankedUser",
Statistics = new UserStatistics
{
IsRanked = false,
// web will sometimes return non-empty rank history even for unranked users.
RankHistory = new APIRankHistory
{
Mode = @"osu",
Data = Enumerable.Range(2345, 85).ToArray()
},
} }
else
header.User.Value = fallback;
}); });
} }
} }

View File

@ -29,6 +29,7 @@ namespace osu.Game.Tests.Visual.Online
ProfileOrder = new[] { "me" }, ProfileOrder = new[] { "me" },
Statistics = new UserStatistics Statistics = new UserStatistics
{ {
IsRanked = true,
GlobalRank = 2148, GlobalRank = 2148,
CountryRank = 1, CountryRank = 1,
PP = 4567.89m, PP = 4567.89m,

View File

@ -42,7 +42,9 @@ namespace osu.Game.Overlays.Profile.Header.Components
private void updateStatistics(UserStatistics statistics) private void updateStatistics(UserStatistics statistics)
{ {
int[] userRanks = statistics?.RankHistory?.Data; // checking both IsRanked and RankHistory is required.
// see https://github.com/ppy/osu-web/blob/154ceafba0f35a1dd935df53ec98ae2ea5615f9f/resources/assets/lib/profile-page/rank-chart.tsx#L46
int[] userRanks = statistics?.IsRanked == true ? statistics.RankHistory?.Data : null;
Data = userRanks?.Select((x, index) => new KeyValuePair<int, int>(index, x)).Where(x => x.Value != 0).ToArray(); Data = userRanks?.Select((x, index) => new KeyValuePair<int, int>(index, x)).Where(x => x.Value != 0).ToArray();
} }

View File

@ -27,6 +27,9 @@ namespace osu.Game.Users
public int Progress; public int Progress;
} }
[JsonProperty(@"is_ranked")]
public bool IsRanked;
[JsonProperty(@"global_rank")] [JsonProperty(@"global_rank")]
public int? GlobalRank; public int? GlobalRank;