<commit_before>﻿// Copyright (c) ppy Pty Ltd <<EMAIL>>. 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;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online;
using osu.Game.Online.API;
using osuTK.Graphics;

namespace osu.Game.Tests.Visual.Online
{
    [TestFixture]
    public class TestSceneOnlineViewContainer : OsuTestScene
    {
        private readonly TestOnlineViewContainer onlineView;

        public TestSceneOnlineViewContainer()
        {
            Child = new Container
            {
                RelativeSizeAxes = Axes.Both,
                Child = onlineView = new TestOnlineViewContainer()
            };
        }

        private class TestOnlineViewContainer : OnlineViewContainer
        {
            public new LoadingAnimation LoadingAnimation => base.LoadingAnimation;

            public CompositeDrawable ViewTarget => base.Content;

            public TestOnlineViewContainer()
                : base(@"Please sign in to view dummy test content")
            {
                RelativeSizeAxes = Axes.Both;
                Children = new Drawable[]
                {
                    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,
                    }
                };
            }
        }

        [Test]
        public void TestOnlineStateVisibility()
        {
            AddStep("set status to online", () => ((DummyAPIAccess)API).State = APIState.Online);

            AddAssert("children are visible", () => onlineView.ViewTarget.IsPresent);
            AddAssert("loading animation is not visible", () => !onlineView.LoadingAnimation.IsPresent);
        }

        [Test]
        public void TestOfflineStateVisibility()
        {
            AddStep("set status to offline", () => ((DummyAPIAccess)API).State = APIState.Offline);

            AddAssert("children are hidden", () => !onlineView.ViewTarget.IsPresent);
            AddAssert("loading animation is not visible", () => !onlineView.LoadingAnimation.IsPresent);
        }

        [Test]
        public void TestConnectingStateVisibility()
        {
            AddStep("set status to connecting", () => ((DummyAPIAccess)API).State = APIState.Connecting);

            AddAssert("children are hidden", () => !onlineView.ViewTarget.IsPresent);
            AddAssert("loading animation is visible", () => onlineView.LoadingAnimation.IsPresent);
        }

        [Test]
        public void TestFailingStateVisibility()
        {
            AddStep("set status to failing", () => ((DummyAPIAccess)API).State = APIState.Failing);

            AddAssert("children are hidden", () => !onlineView.ViewTarget.IsPresent);
            AddAssert("loading animation is visible", () => onlineView.LoadingAnimation.IsPresent);
        }
    }
}
<commit_msg>Fix tests potentially failing due to timing issues<commit_after>﻿// Copyright (c) ppy Pty Ltd <<EMAIL>>. 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;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online;
using osu.Game.Online.API;
using osuTK.Graphics;

namespace osu.Game.Tests.Visual.Online
{
    [TestFixture]
    public class TestSceneOnlineViewContainer : OsuTestScene
    {
        private readonly TestOnlineViewContainer onlineView;

        public TestSceneOnlineViewContainer()
        {
            Child = new Container
            {
                RelativeSizeAxes = Axes.Both,
                Child = onlineView = new TestOnlineViewContainer()
            };
        }

        private class TestOnlineViewContainer : OnlineViewContainer
        {
            public new LoadingAnimation LoadingAnimation => base.LoadingAnimation;

            public CompositeDrawable ViewTarget => base.Content;

            public TestOnlineViewContainer()
                : base(@"Please sign in to view dummy test content")
            {
                RelativeSizeAxes = Axes.Both;
                Children = new Drawable[]
                {
                    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,
                    }
                };
            }
        }

        [Test]
        public void TestOnlineStateVisibility()
        {
            AddStep("set status to online", () => ((DummyAPIAccess)API).State = APIState.Online);

            AddUntilStep("children are visible", () => onlineView.ViewTarget.IsPresent);
            AddUntilStep("loading animation is not visible", () => !onlineView.LoadingAnimation.IsPresent);
        }

        [Test]
        public void TestOfflineStateVisibility()
        {
            AddStep("set status to offline", () => ((DummyAPIAccess)API).State = APIState.Offline);

            AddUntilStep("children are not visible", () => !onlineView.ViewTarget.IsPresent);
            AddUntilStep("loading animation is not visible", () => !onlineView.LoadingAnimation.IsPresent);
        }

        [Test]
        public void TestConnectingStateVisibility()
        {
            AddStep("set status to connecting", () => ((DummyAPIAccess)API).State = APIState.Connecting);

            AddUntilStep("children are not visible", () => !onlineView.ViewTarget.IsPresent);
            AddUntilStep("loading animation is visible", () => onlineView.LoadingAnimation.IsPresent);
        }

        [Test]
        public void TestFailingStateVisibility()
        {
            AddStep("set status to failing", () => ((DummyAPIAccess)API).State = APIState.Failing);

            AddUntilStep("children are not visible", () => !onlineView.ViewTarget.IsPresent);
            AddUntilStep("loading animation is visible", () => onlineView.LoadingAnimation.IsPresent);
        }
    }
}

{'fraction_non_alphanumeric': 0.09519675925925926, 'fraction_numerical': 0.0011574074074074073, 'mean_word_length': 1.9605995717344753, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3832905', 'n_tokens_mistral': 1783, 'n_tokens_neox': 1670, 'n_words': 390}