1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-24 00:42:58 +08:00
osu-lazer/osu.Game.Tests/Visual/Beatmaps/TestSceneBeatmapCardDownloadButton.cs

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

97 lines
3.3 KiB
C#
Raw Normal View History

2021-10-23 21:01:53 +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
2021-10-23 21:01:53 +08:00
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Drawables.Cards.Buttons;
using osu.Game.Configuration;
using osu.Game.Online;
2021-10-23 21:01:53 +08:00
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Overlays;
using osu.Game.Resources.Localisation.Web;
2021-10-23 21:01:53 +08:00
using osu.Game.Rulesets.Osu;
using osuTK;
namespace osu.Game.Tests.Visual.Beatmaps
{
public class TestSceneBeatmapCardDownloadButton : OsuTestScene
{
private DownloadButton downloadButton;
2021-10-23 21:01:53 +08:00
[Cached]
private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Blue);
[Resolved]
private OsuConfigManager config { get; set; }
[Test]
public void TestDownloadableBeatmapWithVideo()
{
createButton(true, true);
assertDownloadEnabled(true);
AddStep("prefer no video", () => config.SetValue(OsuSetting.PreferNoVideo, true));
AddAssert("tooltip text correct", () => downloadButton.TooltipText == BeatmapsetsStrings.PanelDownloadNoVideo);
AddStep("prefer video", () => config.SetValue(OsuSetting.PreferNoVideo, false));
AddAssert("tooltip text correct", () => downloadButton.TooltipText == BeatmapsetsStrings.PanelDownloadVideo);
}
2021-10-23 21:01:53 +08:00
[Test]
public void TestUndownloadableBeatmap()
{
createButton(false);
assertDownloadEnabled(false);
AddAssert("tooltip text correct", () => downloadButton.TooltipText == BeatmapsetsStrings.AvailabilityDisabled);
2021-10-23 21:01:53 +08:00
}
private void assertDownloadEnabled(bool enabled) => AddAssert($"download {(enabled ? "enabled" : "disabled")}", () => downloadButton.Enabled.Value == enabled);
2021-10-23 21:01:53 +08:00
private void createButton(bool downloadable, bool hasVideo = false)
2021-10-23 21:01:53 +08:00
{
AddStep("create button", () =>
{
Child = downloadButton = new DownloadButton(downloadable ? getDownloadableBeatmapSet(hasVideo) : getUndownloadableBeatmapSet())
2021-10-23 21:01:53 +08:00
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
State = { Value = DownloadState.NotDownloaded },
Scale = new Vector2(2)
2021-10-23 21:01:53 +08:00
};
});
}
private APIBeatmapSet getDownloadableBeatmapSet(bool hasVideo)
2021-10-23 21:01:53 +08:00
{
var normal = CreateAPIBeatmapSet(new OsuRuleset().RulesetInfo);
normal.HasVideo = hasVideo;
2021-10-23 21:01:53 +08:00
normal.HasStoryboard = true;
return normal;
}
private APIBeatmapSet getUndownloadableBeatmapSet()
{
var beatmap = CreateAPIBeatmapSet(new OsuRuleset().RulesetInfo);
beatmap.Artist = "test";
beatmap.Title = "undownloadable";
beatmap.AuthorString = "test";
beatmap.HasVideo = true;
beatmap.HasStoryboard = true;
beatmap.Availability = new BeatmapSetOnlineAvailability
{
DownloadDisabled = true,
ExternalLink = "https://osu.ppy.sh",
};
return beatmap;
}
}
}