1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-13 17:53:21 +08:00

Rewrite user profile overlay test to not depend on online API

This commit is contained in:
Bartłomiej Dach 2022-12-30 16:11:56 +01:00
parent d7294ac3e6
commit ae3a211da7
No known key found for this signature in database

View File

@ -4,9 +4,12 @@
using System;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Graphics.Containers;
using osu.Framework.Testing;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Overlays;
using osu.Game.Overlays.Profile;
using osu.Game.Users;
namespace osu.Game.Tests.Visual.Online
@ -14,9 +17,41 @@ namespace osu.Game.Tests.Visual.Online
[TestFixture]
public partial class TestSceneUserProfileOverlay : OsuTestScene
{
protected override bool UseOnlineAPI => true;
private DummyAPIAccess dummyAPI => (DummyAPIAccess)API;
private readonly TestUserProfileOverlay profile;
private UserProfileOverlay profile = null!;
[SetUpSteps]
public void SetUp()
{
AddStep("create profile overlay", () => Child = profile = new UserProfileOverlay());
}
[Test]
public void TestBlank()
{
AddStep("show overlay", () => profile.Show());
}
[Test]
public void TestActualUser()
{
AddStep("set up request handling", () =>
{
dummyAPI.HandleRequest = req =>
{
if (req is GetUserRequest getUserRequest)
{
getUserRequest.TriggerSuccess(TEST_USER);
return true;
}
return false;
};
});
AddStep("show user", () => profile.ShowUser(new APIUser { Id = 1 }));
AddToggleStep("toggle visibility", visible => profile.State.Value = visible ? Visibility.Visible : Visibility.Hidden);
}
public static readonly APIUser TEST_USER = new APIUser
{
@ -64,60 +99,5 @@ namespace osu.Game.Tests.Visual.Online
Colour = "ff0000",
Achievements = Array.Empty<APIUserAchievement>(),
};
public TestSceneUserProfileOverlay()
{
Add(profile = new TestUserProfileOverlay());
}
protected override void LoadComplete()
{
base.LoadComplete();
AddStep("Show offline dummy", () => profile.ShowUser(TEST_USER));
AddStep("Show null dummy", () => profile.ShowUser(new APIUser
{
Username = @"Null",
Id = 1,
}));
AddStep("Show ppy", () => profile.ShowUser(new APIUser
{
Username = @"peppy",
Id = 2,
IsSupporter = true,
CountryCode = CountryCode.AU,
CoverUrl = @"https://osu.ppy.sh/images/headers/profile-covers/c3.jpg"
}));
AddStep("Show flyte", () => profile.ShowUser(new APIUser
{
Username = @"flyte",
Id = 3103765,
CountryCode = CountryCode.JP,
CoverUrl = @"https://osu.ppy.sh/images/headers/profile-covers/c6.jpg"
}));
AddStep("Show bancho", () => profile.ShowUser(new APIUser
{
Username = @"BanchoBot",
Id = 3,
IsBot = true,
CountryCode = CountryCode.SH,
CoverUrl = @"https://osu.ppy.sh/images/headers/profile-covers/c4.jpg"
}));
AddStep("Show ppy from username", () => profile.ShowUser(new APIUser { Username = @"peppy" }));
AddStep("Show flyte from username", () => profile.ShowUser(new APIUser { Username = @"flyte" }));
AddStep("Hide", profile.Hide);
AddStep("Show without reload", profile.Show);
}
private partial class TestUserProfileOverlay : UserProfileOverlay
{
public new ProfileHeader Header => base.Header;
}
}
}