mirror of
https://github.com/ppy/osu.git
synced 2025-01-21 09:33:21 +08:00
Rewrite tests
* Use [Cached] injection instead of modifying beatmaps read from store. * Add assertion steps verifying the presence of mapper name (or lack thereof).
This commit is contained in:
parent
7186e3466b
commit
944f0b0285
@ -3,13 +3,18 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Extensions.Color4Extensions;
|
using osu.Framework.Extensions.Color4Extensions;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics.Shapes;
|
using osu.Framework.Graphics.Shapes;
|
||||||
|
using osu.Framework.Testing;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
|
using osu.Game.Graphics.Sprites;
|
||||||
|
using osu.Game.Rulesets;
|
||||||
using osu.Game.Rulesets.Mods;
|
using osu.Game.Rulesets.Mods;
|
||||||
using osu.Game.Rulesets.Osu;
|
using osu.Game.Rulesets.Osu;
|
||||||
using osu.Game.Rulesets.Osu.Mods;
|
using osu.Game.Rulesets.Osu.Mods;
|
||||||
@ -27,9 +32,7 @@ namespace osu.Game.Tests.Visual.Ranking
|
|||||||
public class TestSceneExpandedPanelMiddleContent : OsuTestScene
|
public class TestSceneExpandedPanelMiddleContent : OsuTestScene
|
||||||
{
|
{
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private BeatmapManager beatmaps { get; set; }
|
private RulesetStore rulesetStore { get; set; }
|
||||||
|
|
||||||
private User author;
|
|
||||||
|
|
||||||
public override IReadOnlyList<Type> RequiredTypes => new[]
|
public override IReadOnlyList<Type> RequiredTypes => new[]
|
||||||
{
|
{
|
||||||
@ -43,57 +46,37 @@ namespace osu.Game.Tests.Visual.Ranking
|
|||||||
typeof(TotalScoreCounter)
|
typeof(TotalScoreCounter)
|
||||||
};
|
};
|
||||||
|
|
||||||
protected override void LoadComplete()
|
[Test]
|
||||||
|
public void TestMapWithKnownMapper()
|
||||||
{
|
{
|
||||||
base.LoadComplete();
|
var author = new User { Username = "mapper_name" };
|
||||||
|
|
||||||
var beatmapInfo = beatmaps.QueryBeatmap(b => b.RulesetID == 0);
|
AddStep("show example score", () => showPanel(createTestBeatmap(author), createTestScore()));
|
||||||
|
|
||||||
if (beatmapInfo != null)
|
AddAssert("mapper name present", () => this.ChildrenOfType<OsuSpriteText>().Any(spriteText => spriteText.Text == "mapper_name"));
|
||||||
{
|
|
||||||
Beatmap.Value = beatmaps.GetWorkingBeatmap(beatmapInfo);
|
|
||||||
author = Beatmap.Value.Metadata.Author;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestExampleScore()
|
public void TestMapWithUnknownMapper()
|
||||||
{
|
{
|
||||||
addScoreStep(createTestScore());
|
AddStep("show example score", () => showPanel(createTestBeatmap(null), createTestScore()));
|
||||||
|
|
||||||
|
AddAssert("mapped by text not present", () =>
|
||||||
|
this.ChildrenOfType<OsuSpriteText>().All(spriteText => !containsAny(spriteText.Text, "mapped", "by")));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
private void showPanel(WorkingBeatmap workingBeatmap, ScoreInfo score)
|
||||||
public void TestScoreWithNullAuthor()
|
|
||||||
{
|
{
|
||||||
AddStep("set author to null", () =>
|
Child = new ExpandedPanelMiddleContentContainer(workingBeatmap, score);
|
||||||
{
|
|
||||||
Beatmap.Value.Metadata.Author = null;
|
|
||||||
});
|
|
||||||
addScoreStep(createTestScore());
|
|
||||||
AddStep("set author to not null", () =>
|
|
||||||
{
|
|
||||||
Beatmap.Value.Metadata.Author = author;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addScoreStep(ScoreInfo score) => AddStep("add panel", () =>
|
private WorkingBeatmap createTestBeatmap(User author)
|
||||||
{
|
{
|
||||||
Child = new Container
|
var beatmap = new TestBeatmap(rulesetStore.GetRuleset(0));
|
||||||
{
|
beatmap.Metadata.Author = author;
|
||||||
Anchor = Anchor.Centre,
|
|
||||||
Origin = Anchor.Centre,
|
return new TestWorkingBeatmap(beatmap);
|
||||||
Size = new Vector2(500, 700),
|
}
|
||||||
Children = new Drawable[]
|
|
||||||
{
|
|
||||||
new Box
|
|
||||||
{
|
|
||||||
RelativeSizeAxes = Axes.Both,
|
|
||||||
Colour = Color4Extensions.FromHex("#444"),
|
|
||||||
},
|
|
||||||
new ExpandedPanelMiddleContent(score)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
private ScoreInfo createTestScore() => new ScoreInfo
|
private ScoreInfo createTestScore() => new ScoreInfo
|
||||||
{
|
{
|
||||||
@ -117,5 +100,31 @@ namespace osu.Game.Tests.Visual.Ranking
|
|||||||
{ HitResult.Great, 300 },
|
{ HitResult.Great, 300 },
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private bool containsAny(string text, params string[] stringsToMatch) => stringsToMatch.Any(text.Contains);
|
||||||
|
|
||||||
|
private class ExpandedPanelMiddleContentContainer : Container
|
||||||
|
{
|
||||||
|
[Cached]
|
||||||
|
private Bindable<WorkingBeatmap> workingBeatmap { get; set; }
|
||||||
|
|
||||||
|
public ExpandedPanelMiddleContentContainer(WorkingBeatmap beatmap, ScoreInfo score)
|
||||||
|
{
|
||||||
|
workingBeatmap = new Bindable<WorkingBeatmap>(beatmap);
|
||||||
|
|
||||||
|
Anchor = Anchor.Centre;
|
||||||
|
Origin = Anchor.Centre;
|
||||||
|
Size = new Vector2(500, 700);
|
||||||
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
new Box
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Colour = Color4Extensions.FromHex("#444"),
|
||||||
|
},
|
||||||
|
new ExpandedPanelMiddleContent(score)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user