1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 09:42:54 +08:00

Add test coverage

This commit is contained in:
Salman Ahmed 2021-01-12 11:14:05 +03:00
parent 24c1839739
commit 80fa2cf693

View File

@ -7,6 +7,7 @@ using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Configuration;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Overlays; using osu.Game.Overlays;
using osu.Game.Overlays.BeatmapListing; using osu.Game.Overlays.BeatmapListing;
@ -19,9 +20,18 @@ namespace osu.Game.Tests.Visual.UserInterface
[Cached] [Cached]
private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Blue); private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Blue);
private readonly BeatmapListingSearchControl control; private BeatmapListingSearchControl control;
public TestSceneBeatmapListingSearchControl() private OsuConfigManager localConfig;
[BackgroundDependencyLoader]
private void load()
{
Dependencies.Cache(localConfig = new OsuConfigManager(LocalStorage));
}
[SetUp]
public void SetUp() => Schedule(() =>
{ {
OsuSpriteText query; OsuSpriteText query;
OsuSpriteText ruleset; OsuSpriteText ruleset;
@ -31,30 +41,34 @@ namespace osu.Game.Tests.Visual.UserInterface
OsuSpriteText extra; OsuSpriteText extra;
OsuSpriteText ranks; OsuSpriteText ranks;
OsuSpriteText played; OsuSpriteText played;
OsuSpriteText explicitMap;
Add(control = new BeatmapListingSearchControl Children = new Drawable[]
{ {
Anchor = Anchor.Centre, control = new BeatmapListingSearchControl
Origin = Anchor.Centre,
});
Add(new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Vertical,
Spacing = new Vector2(0, 5),
Children = new Drawable[]
{ {
query = new OsuSpriteText(), Anchor = Anchor.Centre,
ruleset = new OsuSpriteText(), Origin = Anchor.Centre,
category = new OsuSpriteText(), },
genre = new OsuSpriteText(), new FillFlowContainer
language = new OsuSpriteText(), {
extra = new OsuSpriteText(), AutoSizeAxes = Axes.Both,
ranks = new OsuSpriteText(), Direction = FillDirection.Vertical,
played = new OsuSpriteText() Spacing = new Vector2(0, 5),
Children = new Drawable[]
{
query = new OsuSpriteText(),
ruleset = new OsuSpriteText(),
category = new OsuSpriteText(),
genre = new OsuSpriteText(),
language = new OsuSpriteText(),
extra = new OsuSpriteText(),
ranks = new OsuSpriteText(),
played = new OsuSpriteText(),
explicitMap = new OsuSpriteText(),
}
} }
}); };
control.Query.BindValueChanged(q => query.Text = $"Query: {q.NewValue}", true); control.Query.BindValueChanged(q => query.Text = $"Query: {q.NewValue}", true);
control.Ruleset.BindValueChanged(r => ruleset.Text = $"Ruleset: {r.NewValue}", true); control.Ruleset.BindValueChanged(r => ruleset.Text = $"Ruleset: {r.NewValue}", true);
@ -64,7 +78,8 @@ namespace osu.Game.Tests.Visual.UserInterface
control.Extra.BindCollectionChanged((u, v) => extra.Text = $"Extra: {(control.Extra.Any() ? string.Join('.', control.Extra.Select(i => i.ToString().ToLowerInvariant())) : "")}", true); control.Extra.BindCollectionChanged((u, v) => extra.Text = $"Extra: {(control.Extra.Any() ? string.Join('.', control.Extra.Select(i => i.ToString().ToLowerInvariant())) : "")}", true);
control.Ranks.BindCollectionChanged((u, v) => ranks.Text = $"Ranks: {(control.Ranks.Any() ? string.Join('.', control.Ranks.Select(i => i.ToString())) : "")}", true); control.Ranks.BindCollectionChanged((u, v) => ranks.Text = $"Ranks: {(control.Ranks.Any() ? string.Join('.', control.Ranks.Select(i => i.ToString())) : "")}", true);
control.Played.BindValueChanged(p => played.Text = $"Played: {p.NewValue}", true); control.Played.BindValueChanged(p => played.Text = $"Played: {p.NewValue}", true);
} control.Explicit.BindValueChanged(e => explicitMap.Text = $"Explicit Maps: {e.NewValue}", true);
});
[Test] [Test]
public void TestCovers() public void TestCovers()
@ -74,6 +89,16 @@ namespace osu.Game.Tests.Visual.UserInterface
AddStep("Set null beatmap", () => control.BeatmapSet = null); AddStep("Set null beatmap", () => control.BeatmapSet = null);
} }
[Test]
public void TestExplicitConfig()
{
AddStep("configure explicit content to allowed", () => localConfig.Set(OsuSetting.AllowExplicitContent, true));
AddAssert("explicit control set to show", () => control.Explicit.Value == SearchExplicit.Show);
AddStep("configure explicit content to disallowed", () => localConfig.Set(OsuSetting.AllowExplicitContent, false));
AddAssert("explicit control set to hide", () => control.Explicit.Value == SearchExplicit.Hide);
}
private static readonly BeatmapSetInfo beatmap_set = new BeatmapSetInfo private static readonly BeatmapSetInfo beatmap_set = new BeatmapSetInfo
{ {
OnlineInfo = new BeatmapSetOnlineInfo OnlineInfo = new BeatmapSetOnlineInfo