1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-14 20:38:33 +08:00
osu-lazer/osu.Game.Tests/Visual/Online/TestSceneOnlineViewContainer.cs

100 lines
3.5 KiB
C#
Raw Normal View History

2020-01-14 04:12:19 +08:00
// 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 NUnit.Framework;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics.Sprites;
2020-01-25 04:10:31 +08:00
using osu.Game.Graphics.UserInterface;
2020-01-14 04:12:19 +08:00
using osu.Game.Online;
using osu.Game.Online.API;
using osuTK.Graphics;
namespace osu.Game.Tests.Visual.Online
{
[TestFixture]
public class TestSceneOnlineViewContainer : OsuTestScene
{
2020-01-25 04:10:31 +08:00
private readonly TestOnlineViewContainer onlineView;
2020-01-14 04:12:19 +08:00
public TestSceneOnlineViewContainer()
{
Child = new Container
{
RelativeSizeAxes = Axes.Both,
2020-01-25 04:10:31 +08:00
Child = onlineView = new TestOnlineViewContainer()
};
}
private class TestOnlineViewContainer : OnlineViewContainer
{
public new LoadingAnimation LoadingAnimation => base.LoadingAnimation;
2020-02-12 01:10:46 +08:00
public CompositeDrawable ViewTarget => base.Content.Parent;
2020-01-25 04:10:31 +08:00
public TestOnlineViewContainer()
: base(@"Please sign in to view dummy test content")
{
RelativeSizeAxes = Axes.Both;
Children = new Drawable[]
2020-01-14 04:12:19 +08:00
{
2020-01-25 04:10:31 +08:00
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.Blue.Opacity(0.8f),
},
new OsuSpriteText
2020-01-14 04:12:19 +08:00
{
2020-01-25 04:10:31 +08:00
Text = "dummy online content",
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
2020-01-14 04:12:19 +08:00
}
2020-01-25 04:10:31 +08:00
};
}
2020-02-12 01:10:46 +08:00
protected override void PopContentOut(Drawable content) => content.Hide();
2020-02-12 01:10:46 +08:00
protected override void PopContentIn(Drawable content) => content.Show();
2020-01-14 04:12:19 +08:00
}
2020-01-25 04:10:31 +08:00
[Test]
public void TestOnlineStateVisibility()
2020-01-14 04:12:19 +08:00
{
2020-01-25 04:10:31 +08:00
AddStep("set status to online", () => ((DummyAPIAccess)API).State = APIState.Online);
2020-01-14 04:12:19 +08:00
2020-02-12 01:10:46 +08:00
AddAssert("children are visible", () => onlineView.ViewTarget.IsPresent);
2020-01-25 04:10:31 +08:00
AddAssert("loading animation is not visible", () => !onlineView.LoadingAnimation.IsPresent);
}
2020-01-14 04:12:19 +08:00
2020-01-25 04:10:31 +08:00
[Test]
public void TestOfflineStateVisibility()
{
AddStep("set status to offline", () => ((DummyAPIAccess)API).State = APIState.Offline);
2020-01-14 04:12:19 +08:00
2020-02-12 01:10:46 +08:00
AddAssert("children are hidden", () => !onlineView.ViewTarget.IsPresent);
2020-01-25 04:10:31 +08:00
AddAssert("loading animation is not visible", () => !onlineView.LoadingAnimation.IsPresent);
}
2020-01-25 04:10:31 +08:00
[Test]
public void TestConnectingStateVisibility()
{
AddStep("set status to connecting", () => ((DummyAPIAccess)API).State = APIState.Connecting);
2020-02-12 01:10:46 +08:00
AddAssert("children are hidden", () => !onlineView.ViewTarget.IsPresent);
2020-01-25 04:10:31 +08:00
AddAssert("loading animation is visible", () => onlineView.LoadingAnimation.IsPresent);
2020-02-12 01:10:46 +08:00
}
2020-01-25 04:10:31 +08:00
2020-02-12 01:10:46 +08:00
[Test]
public void TestFailingStateVisibility()
{
2020-01-25 04:10:31 +08:00
AddStep("set status to failing", () => ((DummyAPIAccess)API).State = APIState.Failing);
2020-02-12 01:10:46 +08:00
AddAssert("children are hidden", () => !onlineView.ViewTarget.IsPresent);
2020-01-25 04:10:31 +08:00
AddAssert("loading animation is visible", () => onlineView.LoadingAnimation.IsPresent);
2020-01-14 04:12:19 +08:00
}
}
}