diff --git a/osu.Game.Tests/Visual/Online/TestSceneCurrentlyOnlineDisplay.cs b/osu.Game.Tests/Visual/Online/TestSceneCurrentlyOnlineDisplay.cs index a1d0d40811..8e99212bcb 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneCurrentlyOnlineDisplay.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneCurrentlyOnlineDisplay.cs @@ -9,6 +9,7 @@ using NUnit.Framework; using osu.Framework.Graphics; using osu.Framework.Testing; using osu.Game.Database; +using osu.Game.Online.API; using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.Metadata; using osu.Game.Online.Spectator; @@ -99,6 +100,87 @@ namespace osu.Game.Tests.Visual.Online AddStep("End watching user presence", () => token.Dispose()); } + [Test] + public void TestBlockedUsersHidden() + { + IDisposable token = null!; + + AddStep("Clear blocks", () => + { + DummyAPIAccess api = (DummyAPIAccess)API; + api.Blocks.Clear(); + }); + + AddStep("Begin watching user presence", () => token = metadataClient.BeginWatchingUserPresence()); + AddStep("Add online user", () => metadataClient.UserPresenceUpdated(streamingUser.Id, new UserPresence { Status = UserStatus.Online, Activity = new UserActivity.InSoloGame() })); + AddUntilStep("Panel loaded", () => currentlyOnline.ChildrenOfType().FirstOrDefault()?.User.Id == streamingUser.Id); + + AddStep("Block online user", () => + { + DummyAPIAccess api = (DummyAPIAccess)API; + api.Blocks.Add(new APIRelation() + { + RelationType = RelationType.Block, + TargetUser = streamingUser, + TargetID = streamingUser.Id + }); + }); + + AddAssert("Blocked user not shown", () => currentlyOnline.ChildrenOfType().All(p => p.User.Id != streamingUser.Id)); + + AddStep("Unblock online user", () => + { + DummyAPIAccess api = (DummyAPIAccess)API; + api.Blocks.RemoveAll(b => b.TargetID == streamingUser.Id); + }); + + AddAssert("Unblocked user shown again", () => currentlyOnline.ChildrenOfType().Any(p => p.User.Id == streamingUser.Id)); + + AddStep("Remove playing user", () => metadataClient.UserPresenceUpdated(streamingUser.Id, null)); + AddStep("End watching user presence", () => token.Dispose()); + } + + [Test] + public void TestUnblockedOfflineUsersHidden() + { + IDisposable token = null!; + + AddStep("Clear blocks", () => + { + DummyAPIAccess api = (DummyAPIAccess)API; + api.Blocks.Clear(); + }); + + AddStep("Begin watching user presence", () => token = metadataClient.BeginWatchingUserPresence()); + AddStep("Add online user", () => metadataClient.UserPresenceUpdated(streamingUser.Id, new UserPresence { Status = UserStatus.Online, Activity = new UserActivity.InSoloGame() })); + AddUntilStep("Panel loaded", () => currentlyOnline.ChildrenOfType().FirstOrDefault()?.User.Id == streamingUser.Id); + + AddStep("Block online user", () => + { + DummyAPIAccess api = (DummyAPIAccess)API; + api.Blocks.Add(new APIRelation() + { + RelationType = RelationType.Block, + TargetUser = streamingUser, + TargetID = streamingUser.Id + }); + }); + + AddAssert("Blocked user not shown", () => currentlyOnline.ChildrenOfType().All(p => p.User.Id != streamingUser.Id)); + + AddStep("Remove playing user", () => metadataClient.UserPresenceUpdated(streamingUser.Id, null)); + + AddStep("Unblock offline user", () => + { + DummyAPIAccess api = (DummyAPIAccess)API; + api.Blocks.RemoveAll(b => b.TargetID == streamingUser.Id); + }); + + AddAssert("Unblocked offline user not shown", () => currentlyOnline.ChildrenOfType().All(p => p.User.Id != streamingUser.Id)); + + AddStep("End watching user presence", () => token.Dispose()); + } + internal partial class TestUserLookupCache : UserLookupCache { private static readonly string[] usernames =