From 0422b326ad3faa719ba34852a4d80e3b22ce273d Mon Sep 17 00:00:00 2001 From: Lucas A Date: Mon, 13 Jan 2020 21:12:19 +0100 Subject: [PATCH] Add visual tests --- .../Online/TestSceneOnlineViewContainer.cs | 75 +++++++++++++++++++ osu.Game/Online/API/DummyAPIAccess.cs | 2 +- osu.Game/Online/OnlineViewContainer.cs | 25 ++++--- 3 files changed, 90 insertions(+), 12 deletions(-) create mode 100644 osu.Game.Tests/Visual/Online/TestSceneOnlineViewContainer.cs diff --git a/osu.Game.Tests/Visual/Online/TestSceneOnlineViewContainer.cs b/osu.Game.Tests/Visual/Online/TestSceneOnlineViewContainer.cs new file mode 100644 index 0000000000..a8c50a37e7 --- /dev/null +++ b/osu.Game.Tests/Visual/Online/TestSceneOnlineViewContainer.cs @@ -0,0 +1,75 @@ +// Copyright (c) ppy Pty Ltd . 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.Extensions.Color4Extensions; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Shapes; +using osu.Game.Graphics.Sprites; +using osu.Game.Online; +using osu.Game.Online.API; +using osuTK.Graphics; + +namespace osu.Game.Tests.Visual.Online +{ + [TestFixture] + public class TestSceneOnlineViewContainer : OsuTestScene + { + private OnlineViewContainer onlineView; + private Box box; + + public TestSceneOnlineViewContainer() + { + Child = new Container + { + RelativeSizeAxes = Axes.Both, + Child = onlineView = new OnlineViewContainer(@"Please login to view dummy test content") + { + RelativeSizeAxes = Axes.Both, + Children = new Drawable[] + { + box = new Box + { + RelativeSizeAxes = Axes.Both, + Colour = Color4.Blue.Opacity(0.8f), + }, + new OsuSpriteText + { + Text = "dummy online content", + RelativeSizeAxes = Axes.Both, + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + } + } + } + }; + } + + [BackgroundDependencyLoader] + private void load() + { + AddStep("set status to offline", () => + { + (API as DummyAPIAccess).State = APIState.Offline; + }); + + AddAssert("children are hidden", () => + { + return !onlineView.Children.First().Parent.IsPresent; + }); + + AddStep("set status to online", () => + { + (API as DummyAPIAccess).State = APIState.Online; + }); + + AddAssert("children are visible", () => + { + return onlineView.Children.First().Parent.IsPresent; + }); + } + } +} diff --git a/osu.Game/Online/API/DummyAPIAccess.cs b/osu.Game/Online/API/DummyAPIAccess.cs index 7f23f9b5d5..a1c3475fd9 100644 --- a/osu.Game/Online/API/DummyAPIAccess.cs +++ b/osu.Game/Online/API/DummyAPIAccess.cs @@ -33,7 +33,7 @@ public class DummyAPIAccess : Component, IAPIProvider public APIState State { get => state; - private set + set { if (state == value) return; diff --git a/osu.Game/Online/OnlineViewContainer.cs b/osu.Game/Online/OnlineViewContainer.cs index 6a8963599f..a7f81b4776 100644 --- a/osu.Game/Online/OnlineViewContainer.cs +++ b/osu.Game/Online/OnlineViewContainer.cs @@ -1,4 +1,7 @@ -using osu.Framework.Allocation; +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Game.Online.API; @@ -20,7 +23,7 @@ public class OnlineViewContainer : Container, IOnlineComponent protected override Container Content => content; - public OnlineViewContainer(string placeholder_message) + public OnlineViewContainer(string placeholderMessage) { InternalChildren = new Drawable[] { @@ -32,7 +35,7 @@ public OnlineViewContainer(string placeholder_message) { RelativeSizeAxes = Axes.Both, Alpha = 0, - Child = placeholder = new LoginPlaceholder(placeholder_message) + Child = placeholder = new LoginPlaceholder(placeholderMessage) }, }; } @@ -43,7 +46,7 @@ public void APIStateChanged(IAPIProvider api, APIState state) { case APIState.Offline: case APIState.Connecting: - Schedule(() =>updatePlaceholderVisibility(true)); + Schedule(() => updatePlaceholderVisibility(true)); break; default: @@ -52,18 +55,18 @@ public void APIStateChanged(IAPIProvider api, APIState state) } } - private void updatePlaceholderVisibility(bool show_placeholder) + private void updatePlaceholderVisibility(bool showPlaceholder) { - if (show_placeholder) + if (showPlaceholder) { - content.FadeOut(transform_time / 2, Easing.OutQuint); - placeholder.ScaleTo(0.8f).Then().ScaleTo(1, 3 * transform_time, Easing.OutQuint); - placeholderContainer.FadeInFromZero(2 * transform_time, Easing.OutQuint); + content.FadeOut(transform_time / 2, Easing.OutQuint); + placeholder.ScaleTo(0.8f).Then().ScaleTo(1, 3 * transform_time, Easing.OutQuint); + placeholderContainer.FadeInFromZero(2 * transform_time, Easing.OutQuint); } else { - placeholderContainer.FadeOut(transform_time / 2, Easing.OutQuint); - content.FadeIn(transform_time, Easing.OutQuint); + placeholderContainer.FadeOut(transform_time / 2, Easing.OutQuint); + content.FadeIn(transform_time, Easing.OutQuint); } }