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.
|
|
|
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Beatmaps.Drawables.Cards.Buttons;
|
2021-10-23 21:51:36 +08:00
|
|
|
using osu.Game.Configuration;
|
2021-10-23 21:01:53 +08:00
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
|
|
|
using osu.Game.Overlays;
|
2021-10-23 21:51:36 +08:00
|
|
|
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
|
|
|
|
{
|
2021-11-19 05:28:17 +08:00
|
|
|
private DownloadButton downloadButton;
|
2021-10-23 21:01:53 +08:00
|
|
|
|
|
|
|
[Cached]
|
|
|
|
private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Blue);
|
|
|
|
|
2021-10-23 21:51:36 +08:00
|
|
|
[Resolved]
|
|
|
|
private OsuConfigManager config { get; set; }
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestDownloadableBeatmapWithVideo()
|
|
|
|
{
|
|
|
|
createButton(true, true);
|
|
|
|
assertDownloadEnabled(true);
|
|
|
|
|
|
|
|
AddStep("prefer no video", () => config.SetValue(OsuSetting.PreferNoVideo, true));
|
2021-11-19 05:28:17 +08:00
|
|
|
AddAssert("tooltip text correct", () => downloadButton.TooltipText == BeatmapsetsStrings.PanelDownloadNoVideo);
|
2021-10-23 21:51:36 +08:00
|
|
|
|
|
|
|
AddStep("prefer video", () => config.SetValue(OsuSetting.PreferNoVideo, false));
|
2021-11-19 05:28:17 +08:00
|
|
|
AddAssert("tooltip text correct", () => downloadButton.TooltipText == BeatmapsetsStrings.PanelDownloadVideo);
|
2021-10-23 21:51:36 +08:00
|
|
|
}
|
|
|
|
|
2021-10-23 21:01:53 +08:00
|
|
|
[Test]
|
|
|
|
public void TestUndownloadableBeatmap()
|
|
|
|
{
|
|
|
|
createButton(false);
|
|
|
|
assertDownloadEnabled(false);
|
2021-11-19 05:28:17 +08:00
|
|
|
AddAssert("tooltip text correct", () => downloadButton.TooltipText == BeatmapsetsStrings.AvailabilityDisabled);
|
2021-10-23 21:01:53 +08:00
|
|
|
}
|
|
|
|
|
2021-11-19 05:28:17 +08:00
|
|
|
private void assertDownloadEnabled(bool enabled) => AddAssert($"download {(enabled ? "enabled" : "disabled")}", () => downloadButton.Enabled.Value == enabled);
|
2021-10-23 21:01:53 +08:00
|
|
|
|
2021-10-23 21:51:36 +08:00
|
|
|
private void createButton(bool downloadable, bool hasVideo = false)
|
2021-10-23 21:01:53 +08:00
|
|
|
{
|
|
|
|
AddStep("create button", () =>
|
|
|
|
{
|
2021-11-21 01:45:24 +08:00
|
|
|
Child = downloadButton = new DownloadButton(downloadable ? getDownloadableBeatmapSet(hasVideo) : getUndownloadableBeatmapSet())
|
2021-10-23 21:01:53 +08:00
|
|
|
{
|
2021-11-21 01:45:24 +08:00
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Scale = new Vector2(2)
|
2021-10-23 21:01:53 +08:00
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-10-23 21:51:36 +08:00
|
|
|
private APIBeatmapSet getDownloadableBeatmapSet(bool hasVideo)
|
2021-10-23 21:01:53 +08:00
|
|
|
{
|
|
|
|
var normal = CreateAPIBeatmapSet(new OsuRuleset().RulesetInfo);
|
2021-10-23 21:51:36 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|