Add test coverage of certification flow

This commit is contained in:
Dean Herbert 2022-06-07 23:02:15 +09:00
parent c1ef59ab03
commit 058760253a
2 changed files with 46 additions and 7 deletions

View File

@ -3,17 +3,55 @@
#nullable enable
using System.Linq;
using NUnit.Framework;
using osu.Framework.Testing;
using osu.Game.Graphics.UserInterface;
using osu.Game.Screens;
using osuTK.Input;
namespace osu.Game.Tests.Visual.Settings
{
public class TestSceneLatencyComparer : ScreenTestScene
{
[Test]
public void TestBasic()
private LatencyComparerScreen latencyComparer = null!;
public override void SetUpSteps()
{
AddStep("Load screen", () => LoadScreen(new LatencyComparerScreen()));
base.SetUpSteps();
AddStep("Load screen", () => LoadScreen(latencyComparer = new LatencyComparerScreen()));
}
[Test]
public void TestCertification()
{
for (int i = 0; i < 4; i++)
{
clickCorrectUntilResults();
AddAssert("check at results", () => !latencyComparer.ChildrenOfType<LatencyComparerScreen.LatencyArea>().Any());
AddStep("hit c to continue", () => InputManager.Key(Key.C));
}
AddAssert("check at results", () => !latencyComparer.ChildrenOfType<LatencyComparerScreen.LatencyArea>().Any());
AddAssert("check no buttons", () => !latencyComparer.ChildrenOfType<OsuButton>().Any());
}
private void clickCorrectUntilResults()
{
AddUntilStep("click correct button until results", () =>
{
var latencyArea = latencyComparer
.ChildrenOfType<LatencyComparerScreen.LatencyArea>()
.SingleOrDefault(a => a.TargetFrameRate == 0);
// reached results
if (latencyArea == null)
return true;
latencyArea.ChildrenOfType<OsuButton>().Single().TriggerClick();
return false;
});
}
}
}

View File

@ -358,7 +358,7 @@ private void showResults()
Origin = Anchor.Centre,
Action = () => changeDifficulty(Math.Max(difficultyLevel - 1, 1)),
},
new Button(Key.R)
new Button(Key.C)
{
Text = $"Continue towards certification at this level ({certificationRemaining} more)",
Anchor = Anchor.Centre,
@ -438,14 +438,15 @@ public class LatencyArea : CompositeDrawable
private Drawable? background;
private readonly Key key;
private readonly int targetFrameRate;
public readonly int TargetFrameRate;
public readonly BindableBool IsActiveArea = new BindableBool();
public LatencyArea(Key key, int targetFrameRate)
{
this.key = key;
this.targetFrameRate = targetFrameRate;
TargetFrameRate = targetFrameRate;
RelativeSizeAxes = Axes.Both;
Masking = true;
@ -505,7 +506,7 @@ protected override bool OnMouseMove(MouseMoveEvent e)
public override bool UpdateSubTree()
{
double elapsed = Clock.CurrentTime - lastFrameTime;
if (targetFrameRate > 0 && elapsed < 1000.0 / targetFrameRate)
if (TargetFrameRate > 0 && elapsed < 1000.0 / TargetFrameRate)
return false;
lastFrameTime = Clock.CurrentTime;