1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 10:12:54 +08:00
osu-lazer/osu.Game.Tests/Visual/Online/TestSceneUserPanel.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

215 lines
9.5 KiB
C#
Raw Normal View History

// 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.
2018-04-13 17:19:50 +08:00
2020-03-04 19:58:15 +08:00
using System;
2018-03-02 14:34:31 +08:00
using NUnit.Framework;
2020-03-05 05:13:31 +08:00
using osu.Framework.Allocation;
using osu.Framework.Bindables;
2017-09-18 21:32:49 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Utils;
2023-06-24 22:07:01 +08:00
using osu.Game.Beatmaps;
using osu.Game.Online;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Overlays;
2020-03-05 05:13:31 +08:00
using osu.Game.Rulesets;
using osu.Game.Scoring;
using osu.Game.Tests.Beatmaps;
2017-09-18 21:32:49 +08:00
using osu.Game.Users;
2018-11-20 15:51:59 +08:00
using osuTK;
2018-04-13 17:19:50 +08:00
2019-03-25 00:02:36 +08:00
namespace osu.Game.Tests.Visual.Online
2017-09-18 21:32:49 +08:00
{
2018-03-02 14:34:31 +08:00
[TestFixture]
public partial class TestSceneUserPanel : OsuTestScene
2017-09-18 21:32:49 +08:00
{
2024-11-24 17:33:03 +08:00
private readonly Bindable<UserActivity?> activity = new Bindable<UserActivity?>();
private readonly Bindable<UserStatus?> status = new Bindable<UserStatus?>();
2019-05-06 03:11:52 +08:00
2024-11-24 17:33:03 +08:00
private UserGridPanel boundPanel1 = null!;
private TestUserListPanel boundPanel2 = null!;
2020-03-05 05:02:36 +08:00
[Cached]
private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Purple);
[Cached(typeof(LocalUserStatisticsProvider))]
private readonly TestUserStatisticsProvider statisticsProvider = new TestUserStatisticsProvider();
2020-03-05 05:13:31 +08:00
[Resolved]
2024-11-24 17:33:03 +08:00
private IRulesetStore rulesetStore { get; set; } = null!;
2020-03-05 05:13:31 +08:00
2020-03-05 05:02:36 +08:00
[SetUp]
public void SetUp() => Schedule(() =>
2017-09-18 21:32:49 +08:00
{
2020-03-26 01:58:51 +08:00
activity.Value = null;
status.Value = null;
2024-02-11 16:39:12 +08:00
Remove(statisticsProvider, false);
Clear();
Add(statisticsProvider);
Add(new FillFlowContainer
2017-09-18 21:32:49 +08:00
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
2020-03-04 19:58:15 +08:00
AutoSizeAxes = Axes.Y,
RelativeSizeAxes = Axes.X,
2017-09-18 21:32:49 +08:00
Spacing = new Vector2(10f),
2020-03-05 09:11:12 +08:00
Children = new Drawable[]
2017-09-18 21:32:49 +08:00
{
new UserBrickPanel(new APIUser
2020-07-19 01:24:38 +08:00
{
Username = @"flyte",
Id = 3103765,
CoverUrl = @"https://assets.ppy.sh/user-cover-presets/1/df28696b58541a9e67f6755918951d542d93bdf1da41720fcca2fd2c1ea8cf51.jpeg",
2020-07-19 01:24:38 +08:00
}),
new UserBrickPanel(new APIUser
2020-07-19 01:24:38 +08:00
{
Username = @"peppy",
Id = 2,
Colour = "99EB47",
CoverUrl = @"https://assets.ppy.sh/user-profile-covers/8195163/4a8e2ad5a02a2642b631438cfa6c6bd7e2f9db289be881cb27df18331f64144c.jpeg",
2020-07-19 01:24:38 +08:00
}),
2022-01-13 11:37:57 +08:00
new UserGridPanel(new APIUser
2017-09-18 21:32:49 +08:00
{
Username = @"flyte",
Id = 3103765,
2022-07-18 13:40:34 +08:00
CountryCode = CountryCode.JP,
CoverUrl = @"https://assets.ppy.sh/user-cover-presets/1/df28696b58541a9e67f6755918951d542d93bdf1da41720fcca2fd2c1ea8cf51.jpeg",
Status = { Value = UserStatus.Online }
2017-09-18 21:32:49 +08:00
}) { Width = 300 },
2022-01-13 11:37:57 +08:00
boundPanel1 = new UserGridPanel(new APIUser
2017-09-18 21:32:49 +08:00
{
Username = @"peppy",
Id = 2,
2022-07-18 13:40:34 +08:00
CountryCode = CountryCode.AU,
CoverUrl = @"https://assets.ppy.sh/user-profile-covers/8195163/4a8e2ad5a02a2642b631438cfa6c6bd7e2f9db289be881cb27df18331f64144c.jpeg",
2017-11-17 01:06:49 +08:00
IsSupporter = true,
2018-12-22 23:51:24 +08:00
SupportLevel = 3,
2017-09-18 21:32:49 +08:00
}) { Width = 300 },
2022-01-13 11:37:57 +08:00
boundPanel2 = new TestUserListPanel(new APIUser
2020-03-04 19:58:15 +08:00
{
Username = @"Evast",
Id = 8195163,
2022-07-18 13:40:34 +08:00
CountryCode = CountryCode.BY,
2020-03-04 19:58:15 +08:00
CoverUrl = @"https://assets.ppy.sh/user-profile-covers/8195163/4a8e2ad5a02a2642b631438cfa6c6bd7e2f9db289be881cb27df18331f64144c.jpeg",
IsOnline = false,
LastVisit = DateTimeOffset.Now
}),
new UserRankPanel(new APIUser
{
Username = @"flyte",
Id = 3103765,
CountryCode = CountryCode.JP,
CoverUrl = @"https://assets.ppy.sh/user-cover-presets/1/df28696b58541a9e67f6755918951d542d93bdf1da41720fcca2fd2c1ea8cf51.jpeg",
Statistics = new UserStatistics { GlobalRank = 12345, CountryRank = 1234 }
}) { Width = 300 },
new UserRankPanel(new APIUser
{
Username = @"peppy",
Id = 2,
Colour = "99EB47",
CountryCode = CountryCode.AU,
CoverUrl = @"https://assets.ppy.sh/user-profile-covers/8195163/4a8e2ad5a02a2642b631438cfa6c6bd7e2f9db289be881cb27df18331f64144c.jpeg",
Statistics = new UserStatistics { GlobalRank = null, CountryRank = null }
}) { Width = 300 }
}
2024-02-11 16:39:12 +08:00
});
2018-04-13 17:19:50 +08:00
2022-01-13 11:37:57 +08:00
boundPanel1.Status.BindTo(status);
boundPanel1.Activity.BindTo(activity);
2020-03-05 09:11:12 +08:00
2022-01-13 11:37:57 +08:00
boundPanel2.Status.BindTo(status);
boundPanel2.Activity.BindTo(activity);
2020-03-05 05:02:36 +08:00
});
2019-05-06 03:11:52 +08:00
[Test]
2020-03-05 05:05:48 +08:00
public void TestUserStatus()
2019-05-06 03:11:52 +08:00
{
AddStep("online", () => status.Value = UserStatus.Online);
AddStep("do not disturb", () => status.Value = UserStatus.DoNotDisturb);
AddStep("offline", () => status.Value = UserStatus.Offline);
AddStep("null status", () => status.Value = null);
2019-05-06 03:11:52 +08:00
}
2018-04-13 17:19:50 +08:00
2019-05-06 03:11:52 +08:00
[Test]
2020-03-05 05:05:48 +08:00
public void TestUserActivity()
2019-05-06 03:11:52 +08:00
{
AddStep("set online status", () => status.Value = UserStatus.Online);
2020-03-05 05:04:49 +08:00
AddStep("idle", () => activity.Value = null);
AddStep("watching replay", () => activity.Value = new UserActivity.WatchingReplay(createScore(@"nats")));
AddStep("spectating user", () => activity.Value = new UserActivity.SpectatingUser(createScore(@"mrekk")));
2020-03-05 05:13:31 +08:00
AddStep("solo (osu!)", () => activity.Value = soloGameStatusForRuleset(0));
AddStep("solo (osu!taiko)", () => activity.Value = soloGameStatusForRuleset(1));
AddStep("solo (osu!catch)", () => activity.Value = soloGameStatusForRuleset(2));
AddStep("solo (osu!mania)", () => activity.Value = soloGameStatusForRuleset(3));
2020-03-05 05:04:49 +08:00
AddStep("choosing", () => activity.Value = new UserActivity.ChoosingBeatmap());
2023-06-24 22:07:01 +08:00
AddStep("editing beatmap", () => activity.Value = new UserActivity.EditingBeatmap(new BeatmapInfo()));
AddStep("modding beatmap", () => activity.Value = new UserActivity.ModdingBeatmap(new BeatmapInfo()));
AddStep("testing beatmap", () => activity.Value = new UserActivity.TestingBeatmap(new BeatmapInfo()));
2017-09-18 21:32:49 +08:00
}
2020-03-05 05:13:31 +08:00
2020-03-26 01:58:51 +08:00
[Test]
public void TestUserActivityChange()
{
2022-01-13 11:37:57 +08:00
AddAssert("visit message is visible", () => boundPanel2.LastVisitMessage.IsPresent);
AddStep("set online status", () => status.Value = UserStatus.Online);
2022-01-13 11:37:57 +08:00
AddAssert("visit message is not visible", () => !boundPanel2.LastVisitMessage.IsPresent);
2020-03-26 01:58:51 +08:00
AddStep("set choosing activity", () => activity.Value = new UserActivity.ChoosingBeatmap());
AddStep("set offline status", () => status.Value = UserStatus.Offline);
2022-01-13 11:37:57 +08:00
AddAssert("visit message is visible", () => boundPanel2.LastVisitMessage.IsPresent);
AddStep("set online status", () => status.Value = UserStatus.Online);
2022-01-13 11:37:57 +08:00
AddAssert("visit message is not visible", () => !boundPanel2.LastVisitMessage.IsPresent);
2020-03-26 01:58:51 +08:00
}
[Test]
public void TestUserStatisticsChange()
{
AddStep("update statistics", () =>
{
statisticsProvider.UpdateStatistics(new UserStatistics
{
GlobalRank = RNG.Next(100000),
CountryRank = RNG.Next(100000)
}, Ruleset.Value);
});
AddStep("set statistics to something big", () =>
{
statisticsProvider.UpdateStatistics(new UserStatistics
{
GlobalRank = RNG.Next(1_000_000, 100_000_000),
CountryRank = RNG.Next(1_000_000, 100_000_000)
}, Ruleset.Value);
});
AddStep("set statistics to empty", () => statisticsProvider.UpdateStatistics(new UserStatistics(), Ruleset.Value));
}
2023-06-24 22:07:01 +08:00
private UserActivity soloGameStatusForRuleset(int rulesetId) => new UserActivity.InSoloGame(new BeatmapInfo(), rulesetStore.GetRuleset(rulesetId)!);
2020-03-26 01:58:51 +08:00
private ScoreInfo createScore(string name) => new ScoreInfo(new TestBeatmap(Ruleset.Value).BeatmapInfo)
{
User = new APIUser
{
Username = name,
}
};
2020-03-26 01:58:51 +08:00
private partial class TestUserListPanel : UserListPanel
{
public TestUserListPanel(APIUser user)
2020-03-26 01:58:51 +08:00
: base(user)
{
}
public new TextFlowContainer LastVisitMessage => base.LastVisitMessage;
}
2024-11-24 19:04:36 +08:00
public partial class TestUserStatisticsProvider : LocalUserStatisticsProvider
{
2024-11-24 17:33:03 +08:00
public new void UpdateStatistics(UserStatistics newStatistics, RulesetInfo ruleset, Action<UserStatisticsUpdate>? callback = null)
=> base.UpdateStatistics(newStatistics, ruleset, callback);
}
2017-09-18 21:32:49 +08:00
}
}