<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.Collections.Generic;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Scoring;
using osu.Game.Scoring;
using osu.Game.Screens.Play;
using osu.Game.Screens.Ranking;
using osu.Game.Screens.Ranking.Pages;
using osu.Game.Users;

namespace osu.Game.Tests.Visual.Gameplay
{
    [TestFixture]
    public class TestSceneResults : ScreenTestScene
    {
        private BeatmapManager beatmaps;

        public override IReadOnlyList<Type> RequiredTypes => new[]
        {
            typeof(Results),
            typeof(ResultsPage),
            typeof(ScoreResultsPage),
            typeof(RetryButton),
            typeof(ReplayDownloadButton),
            typeof(LocalLeaderboardPage)
        };

        [BackgroundDependencyLoader]
        private void load(BeatmapManager beatmaps)
        {
            this.beatmaps = beatmaps;
        }

        protected override void LoadComplete()
        {
            base.LoadComplete();

            var beatmapInfo = beatmaps.QueryBeatmap(b => b.RulesetID == 0);
            if (beatmapInfo != null)
                Beatmap.Value = beatmaps.GetWorkingBeatmap(beatmapInfo);

            LoadScreen(new SoloResults(new ScoreInfo
            {
                TotalScore = 2845370,
                Accuracy = 0.98,
                MaxCombo = 123,
                Rank = ScoreRank.A,
                Date = DateTimeOffset.Now,
                Statistics = new Dictionary<HitResult, int>
                {
                    { HitResult.Great, 50 },
                    { HitResult.Good, 20 },
                    { HitResult.Meh, 50 },
                    { HitResult.Miss, 1 }
                },
                User = new User
                {
                    Username = "peppy",
                }
            }));
        }
    }
}<commit_msg>Add test for retry overlay presence<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.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Screens;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Scoring;
using osu.Game.Scoring;
using osu.Game.Screens;
using osu.Game.Screens.Play;
using osu.Game.Screens.Ranking;
using osu.Game.Screens.Ranking.Pages;
using osu.Game.Users;

namespace osu.Game.Tests.Visual.Gameplay
{
    [TestFixture]
    public class TestSceneResults : ScreenTestScene
    {
        private BeatmapManager beatmaps;

        public override IReadOnlyList<Type> RequiredTypes => new[]
        {
            typeof(Results),
            typeof(ResultsPage),
            typeof(ScoreResultsPage),
            typeof(RetryButton),
            typeof(ReplayDownloadButton),
            typeof(LocalLeaderboardPage),
            typeof(TestPlayer)
        };

        [BackgroundDependencyLoader]
        private void load(BeatmapManager beatmaps)
        {
            this.beatmaps = beatmaps;
        }

        protected override void LoadComplete()
        {
            base.LoadComplete();

            var beatmapInfo = beatmaps.QueryBeatmap(b => b.RulesetID == 0);
            if (beatmapInfo != null)
                Beatmap.Value = beatmaps.GetWorkingBeatmap(beatmapInfo);
        }

        private TestSoloResults createResultsScreen() => new TestSoloResults(new ScoreInfo
        {
            TotalScore = 2845370,
            Accuracy = 0.98,
            MaxCombo = 123,
            Rank = ScoreRank.A,
            Date = DateTimeOffset.Now,
            Statistics = new Dictionary<HitResult, int>
            {
                { HitResult.Great, 50 },
                { HitResult.Good, 20 },
                { HitResult.Meh, 50 },
                { HitResult.Miss, 1 }
            },
            User = new User
            {
                Username = "peppy",
            }
        });

        [Test]
        public void ResultsWithoutPlayer()
        {
            TestSoloResults screen = null;

            AddStep("load results", () => Child = new OsuScreenStack(screen = createResultsScreen())
            {
                RelativeSizeAxes = Axes.Both
            });
            AddUntilStep("wait for loaded", () => screen.IsLoaded);
            AddAssert("retry overlay not present", () => screen.RetryOverlay == null);
        }

        [Test]
        public void ResultsWithPlayer()
        {
            TestSoloResults screen = null;

            AddStep("load results", () => Child = new TestResultsContainer(screen = createResultsScreen()));
            AddUntilStep("wait for loaded", () => screen.IsLoaded);
            AddAssert("retry overlay present", () => screen.RetryOverlay != null);
        }

        private class TestResultsContainer : Container
        {
            [Cached(typeof(Player))]
            private readonly Player player = new TestPlayer();

            public TestResultsContainer(IScreen screen)
            {
                RelativeSizeAxes = Axes.Both;

                InternalChild = new OsuScreenStack(screen)
                {
                    RelativeSizeAxes = Axes.Both,
                };
            }
        }

        private class TestSoloResults : SoloResults
        {
            public HotkeyRetryOverlay RetryOverlay;

            public TestSoloResults(ScoreInfo score)
                : base(score)
            {
            }

            protected override void LoadComplete()
            {
                base.LoadComplete();

                RetryOverlay = InternalChildren.OfType<HotkeyRetryOverlay>().SingleOrDefault();
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.09057363300905737, 'fraction_numerical': 0.007044615900704461, 'mean_word_length': 1.7403492647058822, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2362174', 'n_tokens_mistral': 1640, 'n_tokens_neox': 1529, 'n_words': 342}