1
0
mirror of https://github.com/ppy/osu.git synced 2026-05-16 07:32:34 +08:00
Files
osu-lazer/osu.Game.Tests/Visual/UserInterface/TestSceneFriendsOnlineStatusControl.cs
T
Bartłomiej Dach 5eda9a0fd7 Extract all pieces of local user-related state to APIAccess subcomponent
Something I've asked to be done for a long time. Relevant because I've
complained about this on every addition of a new piece of user-local
state: friends, blocks, and now favourite beatmaps.

It's just so messy managing all this inside `APIAccess` next to
everything else, IMO.
2025-10-23 10:53:58 +02:00

110 lines
3.7 KiB
C#

// 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.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Metadata;
using osu.Game.Overlays;
using osu.Game.Overlays.Dashboard.Friends;
using osu.Game.Tests.Visual.Metadata;
using osu.Game.Users;
namespace osu.Game.Tests.Visual.UserInterface
{
public partial class TestSceneFriendsOnlineStatusControl : OsuTestScene
{
[Cached]
private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Blue);
private TestMetadataClient metadataClient = null!;
[SetUp]
public void SetUp() => Schedule(() =>
{
Child = new DependencyProvidingContainer
{
RelativeSizeAxes = Axes.Both,
CachedDependencies =
[
(typeof(MetadataClient), metadataClient = new TestMetadataClient())
],
Children = new Drawable[]
{
metadataClient,
new FriendOnlineStreamControl
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
}
}
};
});
[Test]
public void TestChangeFriends()
{
AddStep("set 10 friends", () =>
{
DummyAPIAccess api = (DummyAPIAccess)API;
api.LocalUserState.Friends.Clear();
api.LocalUserState.Friends.AddRange(Enumerable.Range(1, 10).Select(i => new APIRelation
{
RelationType = RelationType.Friend,
TargetID = i,
TargetUser = new APIUser { Id = i },
}));
});
AddStep("set 20 friends", () =>
{
DummyAPIAccess api = (DummyAPIAccess)API;
api.LocalUserState.Friends.Clear();
api.LocalUserState.Friends.AddRange(Enumerable.Range(1, 20).Select(i => new APIRelation
{
RelationType = RelationType.Friend,
TargetID = i,
TargetUser = new APIUser { Id = i },
}));
});
}
[Test]
public void TestChangeOnlineStates()
{
AddStep("set 10 friends", () =>
{
DummyAPIAccess api = (DummyAPIAccess)API;
api.LocalUserState.Friends.Clear();
api.LocalUserState.Friends.AddRange(Enumerable.Range(1, 10).Select(i => new APIRelation
{
RelationType = RelationType.Friend,
TargetID = i,
TargetUser = new APIUser { Id = i },
}));
});
AddStep("make users 1-5 online", () =>
{
for (int i = 1; i <= 5; i++)
metadataClient.FriendPresenceUpdated(i, new UserPresence { Status = UserStatus.Online });
});
AddStep("make users 1-5 DnD", () =>
{
for (int i = 1; i <= 5; i++)
metadataClient.FriendPresenceUpdated(i, new UserPresence { Status = UserStatus.DoNotDisturb });
});
AddStep("make users 1-5 offline", () =>
{
for (int i = 1; i <= 5; i++)
metadataClient.FriendPresenceUpdated(i, null);
});
}
}
}