1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 23:23:04 +08:00
osu-lazer/osu.Game.Tests/Visual/Online/TestSceneBeatmapRulesetSelector.cs

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

105 lines
3.8 KiB
C#
Raw Normal View History

2019-10-04 22:37:09 +08:00
// 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;
2019-10-04 22:37:09 +08:00
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Testing;
using osu.Game.Online.API.Requests.Responses;
2020-02-03 19:16:26 +08:00
using osu.Game.Overlays;
2019-10-04 22:37:09 +08:00
using osu.Game.Overlays.BeatmapSet;
namespace osu.Game.Tests.Visual.Online
{
public partial class TestSceneBeatmapRulesetSelector : OsuTestScene
{
2020-02-03 19:16:26 +08:00
[Cached]
private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Blue);
private BeatmapRulesetSelector selector;
2019-10-04 22:37:09 +08:00
[SetUp]
public void SetUp() => Schedule(() => Child = selector = new BeatmapRulesetSelector
2019-10-04 22:37:09 +08:00
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
BeatmapSet = new APIBeatmapSet(),
});
2019-10-04 22:37:09 +08:00
[Test]
public void TestDisplay()
{
AddSliderStep("osu", 0, 100, 0, v => updateBeatmaps(0, v));
AddSliderStep("taiko", 0, 100, 0, v => updateBeatmaps(1, v));
AddSliderStep("fruits", 0, 100, 0, v => updateBeatmaps(2, v));
AddSliderStep("mania", 0, 100, 0, v => updateBeatmaps(3, v));
void updateBeatmaps(int ruleset, int count)
{
if (selector == null)
return;
selector.BeatmapSet = new APIBeatmapSet
{
Beatmaps = selector.BeatmapSet.Beatmaps
.Where(b => b.Ruleset.OnlineID != ruleset)
.Concat(Enumerable.Range(0, count).Select(_ => new APIBeatmap { RulesetID = ruleset }))
.ToArray(),
};
}
}
2019-10-04 22:37:09 +08:00
[Test]
public void TestMultipleRulesetsBeatmapSet()
{
AddStep("load multiple rulesets beatmapset", () =>
{
selector.BeatmapSet = new APIBeatmapSet
2019-10-04 22:37:09 +08:00
{
Beatmaps = new[]
{
new APIBeatmap { RulesetID = 1 },
new APIBeatmap { RulesetID = 2 },
}
2019-10-04 22:37:09 +08:00
};
});
AddAssert("osu disabled", () => !selector.ChildrenOfType<BeatmapRulesetTabItem>().Single(t => t.Value.OnlineID == 0).Enabled.Value);
AddAssert("mania disabled", () => !selector.ChildrenOfType<BeatmapRulesetTabItem>().Single(t => t.Value.OnlineID == 3).Enabled.Value);
AddAssert("taiko selected", () => selector.ChildrenOfType<BeatmapRulesetTabItem>().Single(t => t.Active.Value).Value.OnlineID == 1);
2019-10-04 22:37:09 +08:00
}
[Test]
public void TestSingleRulesetBeatmapSet()
{
AddStep("load single ruleset beatmapset", () =>
{
selector.BeatmapSet = new APIBeatmapSet
2019-10-04 22:37:09 +08:00
{
Beatmaps = new[] { new APIBeatmap { RulesetID = 3 } }
2019-10-04 22:37:09 +08:00
};
});
AddAssert("single ruleset selected", () => selector.ChildrenOfType<BeatmapRulesetTabItem>().Single(t => t.Active.Value).Value.OnlineID == 3);
2019-10-04 22:37:09 +08:00
}
[Test]
public void TestEmptyBeatmapSet()
{
AddStep("load empty beatmapset", () => selector.BeatmapSet = new APIBeatmapSet());
AddAssert("all rulesets disabled", () => selector.ChildrenOfType<BeatmapRulesetTabItem>().All(t => !t.Active.Value && !t.Enabled.Value));
2019-10-04 22:37:09 +08:00
}
[Test]
public void TestNullBeatmapSet()
{
AddStep("load null beatmapset", () => selector.BeatmapSet = null);
AddAssert("all rulesets disabled", () => selector.ChildrenOfType<BeatmapRulesetTabItem>().All(t => !t.Active.Value && !t.Enabled.Value));
2019-10-04 22:37:09 +08:00
}
}
}