1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-21 17:23:05 +08:00
osu-lazer/osu.Game.Tests/Visual/UserInterface/TestSceneBeatmapListingSearchControl.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

132 lines
5.3 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.
2022-06-17 15:37:17 +08:00
#nullable disable
using System.Linq;
using Humanizer;
2020-02-18 22:47:44 +08:00
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
2020-02-18 22:47:44 +08:00
using osu.Framework.Graphics.Containers;
using osu.Game.Beatmaps;
2021-01-12 16:14:05 +08:00
using osu.Game.Configuration;
2020-02-18 22:47:44 +08:00
using osu.Game.Graphics.Sprites;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Overlays;
using osu.Game.Overlays.BeatmapListing;
2020-02-18 22:47:44 +08:00
using osuTK;
namespace osu.Game.Tests.Visual.UserInterface
{
2020-04-21 14:13:19 +08:00
public class TestSceneBeatmapListingSearchControl : OsuTestScene
{
[Cached]
private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Blue);
2021-01-12 16:14:05 +08:00
private BeatmapListingSearchControl control;
2020-02-18 22:47:44 +08:00
2021-01-12 16:14:05 +08:00
private OsuConfigManager localConfig;
[BackgroundDependencyLoader]
private void load()
{
Dependencies.Cache(localConfig = new OsuConfigManager(LocalStorage));
}
[SetUp]
public void SetUp() => Schedule(() =>
{
2020-02-18 22:47:44 +08:00
OsuSpriteText query;
2021-03-26 06:20:26 +08:00
OsuSpriteText general;
2020-02-18 22:47:44 +08:00
OsuSpriteText ruleset;
OsuSpriteText category;
OsuSpriteText genre;
OsuSpriteText language;
2020-10-28 02:22:20 +08:00
OsuSpriteText extra;
2020-10-28 04:14:48 +08:00
OsuSpriteText ranks;
2020-10-28 02:30:53 +08:00
OsuSpriteText played;
2021-01-12 16:14:05 +08:00
OsuSpriteText explicitMap;
2021-01-12 16:14:05 +08:00
Children = new Drawable[]
{
2021-01-12 16:14:05 +08:00
control = new BeatmapListingSearchControl
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
},
new FillFlowContainer
{
2021-01-12 16:14:05 +08:00
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Vertical,
Spacing = new Vector2(0, 5),
Children = new Drawable[]
{
query = new OsuSpriteText(),
2021-03-26 06:20:26 +08:00
general = new OsuSpriteText(),
2021-01-12 16:14:05 +08:00
ruleset = new OsuSpriteText(),
category = new OsuSpriteText(),
genre = new OsuSpriteText(),
language = new OsuSpriteText(),
extra = new OsuSpriteText(),
ranks = new OsuSpriteText(),
played = new OsuSpriteText(),
explicitMap = new OsuSpriteText(),
}
}
2021-01-12 16:14:05 +08:00
};
2020-04-21 14:13:19 +08:00
control.Query.BindValueChanged(q => query.Text = $"Query: {q.NewValue}", true);
2022-06-24 20:25:23 +08:00
control.General.BindCollectionChanged((_, _) => general.Text = $"General: {(control.General.Any() ? string.Join('.', control.General.Select(i => i.ToString().Underscore())) : "")}", true);
2020-04-21 14:13:19 +08:00
control.Ruleset.BindValueChanged(r => ruleset.Text = $"Ruleset: {r.NewValue}", true);
control.Category.BindValueChanged(c => category.Text = $"Category: {c.NewValue}", true);
control.Genre.BindValueChanged(g => genre.Text = $"Genre: {g.NewValue}", true);
control.Language.BindValueChanged(l => language.Text = $"Language: {l.NewValue}", true);
2022-06-24 20:25:23 +08:00
control.Extra.BindCollectionChanged((_, _) => extra.Text = $"Extra: {(control.Extra.Any() ? string.Join('.', control.Extra.Select(i => i.ToString().ToLowerInvariant())) : "")}", true);
control.Ranks.BindCollectionChanged((_, _) => ranks.Text = $"Ranks: {(control.Ranks.Any() ? string.Join('.', control.Ranks.Select(i => i.ToString())) : "")}", true);
2020-10-28 02:30:53 +08:00
control.Played.BindValueChanged(p => played.Text = $"Played: {p.NewValue}", true);
2021-01-17 21:40:24 +08:00
control.ExplicitContent.BindValueChanged(e => explicitMap.Text = $"Explicit Maps: {e.NewValue}", true);
2021-01-12 16:14:05 +08:00
});
2020-02-18 22:47:44 +08:00
[Test]
public void TestCovers()
{
2020-04-21 14:13:19 +08:00
AddStep("Set beatmap", () => control.BeatmapSet = beatmap_set);
AddStep("Set beatmap (no cover)", () => control.BeatmapSet = no_cover_beatmap_set);
AddStep("Set null beatmap", () => control.BeatmapSet = null);
2020-02-18 22:47:44 +08:00
}
2021-01-12 16:14:05 +08:00
[Test]
public void TestExplicitConfig()
{
AddStep("configure explicit content to allowed", () => localConfig.SetValue(OsuSetting.ShowOnlineExplicitContent, true));
2021-01-17 21:40:24 +08:00
AddAssert("explicit control set to show", () => control.ExplicitContent.Value == SearchExplicit.Show);
2021-01-12 16:14:05 +08:00
AddStep("configure explicit content to disallowed", () => localConfig.SetValue(OsuSetting.ShowOnlineExplicitContent, false));
2021-01-17 21:40:24 +08:00
AddAssert("explicit control set to hide", () => control.ExplicitContent.Value == SearchExplicit.Hide);
2021-01-12 16:14:05 +08:00
}
2021-01-13 18:00:14 +08:00
protected override void Dispose(bool isDisposing)
{
localConfig?.Dispose();
base.Dispose(isDisposing);
}
private static readonly APIBeatmapSet beatmap_set = new APIBeatmapSet
2020-02-18 22:47:44 +08:00
{
Covers = new BeatmapSetOnlineCovers
{
Cover = "https://assets.ppy.sh/beatmaps/1094296/covers/cover@2x.jpg?1581416305"
2020-02-18 22:47:44 +08:00
}
};
private static readonly APIBeatmapSet no_cover_beatmap_set = new APIBeatmapSet
2020-02-18 22:47:44 +08:00
{
Covers = new BeatmapSetOnlineCovers
2020-02-18 22:47:44 +08:00
{
Cover = string.Empty
2020-02-18 22:47:44 +08:00
}
};
}
}