1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-16 22:22:54 +08:00
osu-lazer/osu.Game.Tests/Visual/Ranking/TestSceneResultsScreen.cs

139 lines
4.0 KiB
C#
Raw Normal View History

// 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.
2018-04-13 17:19:50 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
2018-04-13 17:19:50 +08:00
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Screens;
2018-04-13 17:19:50 +08:00
using osu.Game.Beatmaps;
2020-03-17 16:43:16 +08:00
using osu.Game.Rulesets.Osu;
2018-04-13 17:19:50 +08:00
using osu.Game.Rulesets.Scoring;
2018-11-28 15:12:57 +08:00
using osu.Game.Scoring;
using osu.Game.Screens;
using osu.Game.Screens.Play;
2018-04-13 17:19:50 +08:00
using osu.Game.Screens.Ranking;
2020-03-17 16:43:16 +08:00
using osu.Game.Tests.Beatmaps;
2018-04-13 17:19:50 +08:00
using osu.Game.Users;
2020-03-17 16:43:16 +08:00
namespace osu.Game.Tests.Visual.Ranking
2018-04-13 17:19:50 +08:00
{
[TestFixture]
2020-03-17 16:43:16 +08:00
public class TestSceneResultsScreen : ScreenTestScene
2018-04-13 17:19:50 +08:00
{
private BeatmapManager beatmaps;
public override IReadOnlyList<Type> RequiredTypes => new[]
{
2020-03-17 16:43:16 +08:00
typeof(ResultsScreen),
2019-11-01 14:32:06 +08:00
typeof(RetryButton),
typeof(ReplayDownloadButton),
typeof(TestPlayer)
2018-04-13 17:19:50 +08:00
};
[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);
}
2018-04-13 17:19:50 +08:00
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>
2018-04-13 17:19:50 +08:00
{
{ HitResult.Great, 50 },
{ HitResult.Good, 20 },
{ HitResult.Meh, 50 },
{ HitResult.Miss, 1 }
},
2020-03-17 16:43:16 +08:00
Beatmap = new TestBeatmap(new OsuRuleset().RulesetInfo).BeatmapInfo,
User = new User
{
Username = "peppy",
}
});
[Test]
public void ResultsWithoutPlayer()
{
TestSoloResults screen = null;
OsuScreenStack stack;
AddStep("load results", () =>
{
Child = stack = new OsuScreenStack
{
RelativeSizeAxes = Axes.Both
};
stack.Push(screen = createResultsScreen());
});
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;
OsuScreenStack stack;
InternalChild = stack = new OsuScreenStack
2018-04-13 17:19:50 +08:00
{
RelativeSizeAxes = Axes.Both,
};
stack.Push(screen);
}
}
2020-03-17 16:43:16 +08:00
private class TestSoloResults : ResultsScreen
{
public HotkeyRetryOverlay RetryOverlay;
public TestSoloResults(ScoreInfo score)
: base(score)
{
}
protected override void LoadComplete()
{
base.LoadComplete();
RetryOverlay = InternalChildren.OfType<HotkeyRetryOverlay>().SingleOrDefault();
}
2018-04-13 17:19:50 +08:00
}
}
}