1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-25 15:13:22 +08:00
osu-lazer/osu.Game.Tests/Visual/TestCaseUserProfile.cs

124 lines
4.1 KiB
C#
Raw Normal View History

2018-04-13 17:19:50 +08:00
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
2018-04-13 17:19:50 +08:00
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.API;
2018-04-13 17:19:50 +08:00
using osu.Game.Overlays;
using osu.Game.Overlays.Profile;
2018-04-16 05:44:59 +08:00
using osu.Game.Overlays.Profile.Header;
2018-04-13 17:19:50 +08:00
using osu.Game.Users;
namespace osu.Game.Tests.Visual
{
[TestFixture]
public class TestCaseUserProfile : OsuTestCase
{
private readonly TestUserProfileOverlay profile;
private APIAccess api;
2018-04-13 17:19:50 +08:00
public override IReadOnlyList<Type> RequiredTypes => new[]
{
typeof(ProfileHeader),
typeof(UserProfileOverlay),
typeof(RankGraph),
typeof(LineGraph),
2018-04-16 05:44:59 +08:00
typeof(BadgeContainer)
2018-04-13 17:19:50 +08:00
};
public TestCaseUserProfile()
{
Add(profile = new TestUserProfileOverlay());
}
[BackgroundDependencyLoader]
private void load(APIAccess api)
{
this.api = api;
}
2018-04-13 17:19:50 +08:00
protected override void LoadComplete()
{
base.LoadComplete();
AddStep("Show offline dummy", () => profile.ShowUser(new User
2018-04-13 17:19:50 +08:00
{
Username = @"Somebody",
Id = 1,
Country = new Country { FullName = @"Alien" },
CoverUrl = @"https://osu.ppy.sh/images/headers/profile-covers/c1.jpg",
JoinDate = DateTimeOffset.Now.AddDays(-1),
LastVisit = DateTimeOffset.Now,
ProfileOrder = new[] { "me" },
Statistics = new UserStatistics
{
Ranks = new UserStatistics.UserRanks { Global = 2148, Country = 1 },
PP = 4567.89m,
},
RankHistory = new User.RankHistoryData
2018-04-13 17:19:50 +08:00
{
Mode = @"osu",
Data = Enumerable.Range(2345, 45).Concat(Enumerable.Range(2109, 40)).ToArray()
},
Badges = new[]
{
new Badge
{
AwardedAt = DateTimeOffset.FromUnixTimeSeconds(1505741569),
Description = "Outstanding help by being a voluntary test subject.",
ImageUrl = "https://assets.ppy.sh/profile-badges/contributor.jpg"
}
2018-04-13 17:19:50 +08:00
}
}, false));
2018-04-13 17:19:50 +08:00
checkSupporterTag(false);
AddStep("Show null dummy", () => profile.ShowUser(new User
{
Username = @"Null",
Id = 1,
}, false));
AddStep("Show ppy", () => profile.ShowUser(new User
{
Username = @"peppy",
Id = 2,
IsSupporter = true,
2018-04-13 17:19:50 +08:00
Country = new Country { FullName = @"Australia", FlagName = @"AU" },
CoverUrl = @"https://osu.ppy.sh/images/headers/profile-covers/c3.jpg"
}, api.IsLoggedIn));
2018-04-13 17:19:50 +08:00
checkSupporterTag(true);
AddStep("Show flyte", () => profile.ShowUser(new User
{
Username = @"flyte",
Id = 3103765,
Country = new Country { FullName = @"Japan", FlagName = @"JP" },
CoverUrl = @"https://osu.ppy.sh/images/headers/profile-covers/c6.jpg"
}, api.IsLoggedIn));
2018-04-13 17:19:50 +08:00
AddStep("Hide", profile.Hide);
AddStep("Show without reload", profile.Show);
}
private void checkSupporterTag(bool isSupporter)
{
AddUntilStep(() => profile.Header.User != null, "wait for load");
if (isSupporter)
AddAssert("is supporter", () => profile.Header.SupporterTag.Alpha == 1);
else
AddAssert("no supporter", () => profile.Header.SupporterTag.Alpha == 0);
}
private class TestUserProfileOverlay : UserProfileOverlay
{
public new ProfileHeader Header => base.Header;
}
}
}