From 6f38e6166d136bbe46ce8501e6f796402ae33911 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Wed, 20 Oct 2021 10:32:00 +0300 Subject: [PATCH 1/3] Fix and improve TestSceneUserProfilePreviousUsernames --- .../TestSceneUserProfilePreviousUsernames.cs | 81 +++++++++++++------ 1 file changed, 56 insertions(+), 25 deletions(-) diff --git a/osu.Game.Tests/Visual/Online/TestSceneUserProfilePreviousUsernames.cs b/osu.Game.Tests/Visual/Online/TestSceneUserProfilePreviousUsernames.cs index 1e9d62f379..83254b616c 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneUserProfilePreviousUsernames.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneUserProfilePreviousUsernames.cs @@ -20,44 +20,75 @@ namespace osu.Game.Tests.Visual.Online private IAPIProvider api { get; set; } private readonly Bindable user = new Bindable(); + private GetUserRequest request; + private PreviousUsernames container; - public TestSceneUserProfilePreviousUsernames() + [SetUp] + public void SetUp() { - Child = new PreviousUsernames + request?.Cancel(); + + Child = container = new PreviousUsernames { Anchor = Anchor.Centre, Origin = Anchor.Centre, User = { BindTarget = user }, }; - - User[] users = - { - new User { PreviousUsernames = new[] { "username1" } }, - new User { PreviousUsernames = new[] { "longusername", "longerusername" } }, - new User { PreviousUsernames = new[] { "test", "angelsim", "verylongusername" } }, - new User { PreviousUsernames = new[] { "ihavenoidea", "howcani", "makethistext", "anylonger" } }, - new User { PreviousUsernames = Array.Empty() }, - null - }; - - AddStep("single username", () => user.Value = users[0]); - AddStep("two usernames", () => user.Value = users[1]); - AddStep("three usernames", () => user.Value = users[2]); - AddStep("four usernames", () => user.Value = users[3]); - AddStep("no username", () => user.Value = users[4]); - AddStep("null user", () => user.Value = users[5]); } - protected override void LoadComplete() + [Test] + public void TestOffline() { - base.LoadComplete(); + AddAssert("Is Hidden", () => container?.Alpha == 0); - AddStep("online user (Angelsim)", () => + AddStep("1 username", () => user.Value = users[0]); + AddUntilStep("Is visible", () => container?.Alpha == 1); + + AddStep("2 usernames", () => user.Value = users[1]); + AddUntilStep("Is visible", () => container?.Alpha == 1); + + AddStep("3 usernames", () => user.Value = users[2]); + AddUntilStep("Is visible", () => container?.Alpha == 1); + + AddStep("4 usernames", () => user.Value = users[3]); + AddUntilStep("Is visible", () => container?.Alpha == 1); + + AddStep("No username", () => user.Value = users[4]); + AddUntilStep("Is hidden", () => container?.Alpha == 0); + + AddStep("Null user", () => user.Value = users[5]); + AddUntilStep("Is hidden", () => container?.Alpha == 0); + } + + [Test] + public void TestOnline() + { + AddAssert("Is Hidden", () => container?.Alpha == 0); + + AddStep("Create request", () => { - var request = new GetUserRequest(1777162); - request.Success += user => this.user.Value = user; - api.Queue(request); + request = new GetUserRequest(1777162); + request.Success += u => user.Value = u; + api?.Queue(request); }); + + AddUntilStep("Is visible", () => container?.Alpha == 1); + } + + private static readonly User[] users = + { + new User { Id = 1, PreviousUsernames = new[] { "username1" } }, + new User { Id = 2, PreviousUsernames = new[] { "longusername", "longerusername" } }, + new User { Id = 3, PreviousUsernames = new[] { "test", "angelsim", "verylongusername" } }, + new User { Id = 4, PreviousUsernames = new[] { "ihavenoidea", "howcani", "makethistext", "anylonger" } }, + new User { Id = 5, PreviousUsernames = Array.Empty() }, + null + }; + + protected override void Dispose(bool isDisposing) + { + request?.Cancel(); + base.Dispose(isDisposing); } } } From faabc75a3ec41f01a5a9030fbf4c6ef989d8797b Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Wed, 20 Oct 2021 10:54:08 +0300 Subject: [PATCH 2/3] Fix failing test --- .../TestSceneUserProfilePreviousUsernames.cs | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/osu.Game.Tests/Visual/Online/TestSceneUserProfilePreviousUsernames.cs b/osu.Game.Tests/Visual/Online/TestSceneUserProfilePreviousUsernames.cs index 83254b616c..303f66d893 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneUserProfilePreviousUsernames.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneUserProfilePreviousUsernames.cs @@ -4,7 +4,6 @@ using System; using NUnit.Framework; using osu.Framework.Allocation; -using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Game.Online.API; using osu.Game.Online.API.Requests; @@ -19,12 +18,11 @@ namespace osu.Game.Tests.Visual.Online [Resolved] private IAPIProvider api { get; set; } - private readonly Bindable user = new Bindable(); private GetUserRequest request; private PreviousUsernames container; [SetUp] - public void SetUp() + public void SetUp() => Schedule(() => { request?.Cancel(); @@ -32,31 +30,30 @@ namespace osu.Game.Tests.Visual.Online { Anchor = Anchor.Centre, Origin = Anchor.Centre, - User = { BindTarget = user }, }; - } + }); [Test] public void TestOffline() { AddAssert("Is Hidden", () => container?.Alpha == 0); - AddStep("1 username", () => user.Value = users[0]); + AddStep("1 username", () => container.User.Value = users[0]); AddUntilStep("Is visible", () => container?.Alpha == 1); - AddStep("2 usernames", () => user.Value = users[1]); + AddStep("2 usernames", () => container.User.Value = users[1]); AddUntilStep("Is visible", () => container?.Alpha == 1); - AddStep("3 usernames", () => user.Value = users[2]); + AddStep("3 usernames", () => container.User.Value = users[2]); AddUntilStep("Is visible", () => container?.Alpha == 1); - AddStep("4 usernames", () => user.Value = users[3]); + AddStep("4 usernames", () => container.User.Value = users[3]); AddUntilStep("Is visible", () => container?.Alpha == 1); - AddStep("No username", () => user.Value = users[4]); + AddStep("No username", () => container.User.Value = users[4]); AddUntilStep("Is hidden", () => container?.Alpha == 0); - AddStep("Null user", () => user.Value = users[5]); + AddStep("Null user", () => container.User.Value = users[5]); AddUntilStep("Is hidden", () => container?.Alpha == 0); } @@ -68,7 +65,7 @@ namespace osu.Game.Tests.Visual.Online AddStep("Create request", () => { request = new GetUserRequest(1777162); - request.Success += u => user.Value = u; + request.Success += u => container.User.Value = u; api?.Queue(request); }); From 0f8d270442b34d4155f13991e0e42adc5e41edfe Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Wed, 20 Oct 2021 11:27:24 +0300 Subject: [PATCH 3/3] Remove online part since it doesn't really check anything --- .../TestSceneUserProfilePreviousUsernames.cs | 46 ++++--------------- 1 file changed, 8 insertions(+), 38 deletions(-) diff --git a/osu.Game.Tests/Visual/Online/TestSceneUserProfilePreviousUsernames.cs b/osu.Game.Tests/Visual/Online/TestSceneUserProfilePreviousUsernames.cs index 303f66d893..b5d2d15392 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneUserProfilePreviousUsernames.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneUserProfilePreviousUsernames.cs @@ -3,10 +3,7 @@ using System; using NUnit.Framework; -using osu.Framework.Allocation; using osu.Framework.Graphics; -using osu.Game.Online.API; -using osu.Game.Online.API.Requests; using osu.Game.Overlays.Profile.Header.Components; using osu.Game.Users; @@ -15,17 +12,11 @@ namespace osu.Game.Tests.Visual.Online [TestFixture] public class TestSceneUserProfilePreviousUsernames : OsuTestScene { - [Resolved] - private IAPIProvider api { get; set; } - - private GetUserRequest request; private PreviousUsernames container; [SetUp] public void SetUp() => Schedule(() => { - request?.Cancel(); - Child = container = new PreviousUsernames { Anchor = Anchor.Centre, @@ -34,42 +25,27 @@ namespace osu.Game.Tests.Visual.Online }); [Test] - public void TestOffline() + public void TestVisibility() { - AddAssert("Is Hidden", () => container?.Alpha == 0); + AddAssert("Is Hidden", () => container.Alpha == 0); AddStep("1 username", () => container.User.Value = users[0]); - AddUntilStep("Is visible", () => container?.Alpha == 1); + AddUntilStep("Is visible", () => container.Alpha == 1); AddStep("2 usernames", () => container.User.Value = users[1]); - AddUntilStep("Is visible", () => container?.Alpha == 1); + AddUntilStep("Is visible", () => container.Alpha == 1); AddStep("3 usernames", () => container.User.Value = users[2]); - AddUntilStep("Is visible", () => container?.Alpha == 1); + AddUntilStep("Is visible", () => container.Alpha == 1); AddStep("4 usernames", () => container.User.Value = users[3]); - AddUntilStep("Is visible", () => container?.Alpha == 1); + AddUntilStep("Is visible", () => container.Alpha == 1); AddStep("No username", () => container.User.Value = users[4]); - AddUntilStep("Is hidden", () => container?.Alpha == 0); + AddUntilStep("Is hidden", () => container.Alpha == 0); AddStep("Null user", () => container.User.Value = users[5]); - AddUntilStep("Is hidden", () => container?.Alpha == 0); - } - - [Test] - public void TestOnline() - { - AddAssert("Is Hidden", () => container?.Alpha == 0); - - AddStep("Create request", () => - { - request = new GetUserRequest(1777162); - request.Success += u => container.User.Value = u; - api?.Queue(request); - }); - - AddUntilStep("Is visible", () => container?.Alpha == 1); + AddUntilStep("Is hidden", () => container.Alpha == 0); } private static readonly User[] users = @@ -81,11 +57,5 @@ namespace osu.Game.Tests.Visual.Online new User { Id = 5, PreviousUsernames = Array.Empty() }, null }; - - protected override void Dispose(bool isDisposing) - { - request?.Cancel(); - base.Dispose(isDisposing); - } } }