<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 System;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Testing;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Overlays;

namespace osu.Game.Tests.Visual.Online
{
    public class TestSceneNewsOverlay : OsuTestScene
    {
        private DummyAPIAccess dummyAPI => (DummyAPIAccess)API;

        private NewsOverlay overlay;

        [SetUp]
        public void SetUp() => Schedule(() => Child = overlay = new NewsOverlay());

        [Test]
        public void TestRequest()
        {
            setUpNewsResponse(responseExample);
            AddStep("Show", () => overlay.Show());
            AddStep("Show article", () => overlay.ShowArticle("article"));
        }

        [Test]
        public void TestCursorRequest()
        {
            setUpNewsResponse(responseWithCursor, "Set up cursor response");
            AddStep("Show", () => overlay.Show());
            AddAssert("Show More button is visible", () => showMoreButton.Alpha == 1);
            setUpNewsResponse(responseWithNoCursor, "Set up no cursor response");
            AddStep("Click Show More", () => showMoreButton.Click());
            AddAssert("Show More button is hidden", () => showMoreButton.Alpha == 0);
        }

        private ShowMoreButton showMoreButton => overlay.ChildrenOfType<ShowMoreButton>().First();

        private void setUpNewsResponse(GetNewsResponse r, string testName = "Set up response")<commit_msg>Fix potential test scene failure due to showMoreButton not being loaded in time<commit_after>﻿// Copyright (c) p<NAME> Ltd <<EMAIL>>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Testing;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Overlays;

namespace osu.Game.Tests.Visual.Online
{
    public class TestSceneNewsOverlay : OsuTestScene
    {
        private DummyAPIAccess dummyAPI => (DummyAPIAccess)API;

        private NewsOverlay overlay;

        [SetUp]
        public void SetUp() => Schedule(() => Child = overlay = new NewsOverlay());

        [Test]
        public void TestRequest()
        {
            setUpNewsResponse(responseExample);
            AddStep("Show", () => overlay.Show());
            AddStep("Show article", () => overlay.ShowArticle("article"));
        }

        [Test]
        public void TestCursorRequest()
        {
            setUpNewsResponse(responseWithCursor, "Set up cursor response");
            AddStep("Show", () => overlay.Show());
            AddUntilStep("Show more button is ready", () => showMoreButton != null);
            AddAssert("Show More button is visible", () => showMoreButton.Alpha == 1);
            setUpNewsResponse(responseWithNoCursor, "Set up no cursor response");
            AddStep("Click Show More", () => showMoreButton.Click());
            AddAssert("Show More button is hidden", () => showMoreButton.Alpha == 0);
        }

        private ShowMoreButton showMoreButton => overlay.ChildrenOfType<ShowMoreButton>().First();

        private void setUpNewsResponse(GetNewsResponse r, string testName = "Set up response")
{'fraction_non_alphanumeric': 0.11708415423585702, 'fraction_numerical': 0.001125809175344779, 'mean_word_length': 3.0112866817155757, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 31, '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': '5708000', 'n_tokens_mistral': 977, 'n_tokens_neox': 952, 'n_words': 261}