1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-31 01:42:55 +08:00
osu-lazer/osu.Game.Tests/Visual/Online/TestSceneBeatmapDownloadButton.cs

153 lines
4.9 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.
2019-06-27 20:01:21 +08:00
using System.Linq;
using NUnit.Framework;
2019-06-27 20:01:21 +08:00
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Drawables;
2019-06-27 20:01:21 +08:00
using osu.Game.Online;
using osu.Game.Online.API.Requests.Responses;
2019-06-27 20:01:21 +08:00
using osu.Game.Tests.Resources;
using osuTK;
namespace osu.Game.Tests.Visual.Online
{
public class TestSceneBeatmapDownloadButton : OsuTestScene
{
private TestDownloadButton downloadButton;
2019-06-27 20:01:21 +08:00
[Resolved]
private BeatmapManager beatmaps { get; set; }
[Test]
public void TestDownloadableBeatmap()
{
createButton(true);
assertEnabled(true);
}
[Test]
public void TestUndownloadableBeatmap()
{
createButton(false);
assertEnabled(false);
}
2019-06-27 20:01:21 +08:00
[Test]
public void TestDownloadState()
{
AddUntilStep("ensure manager loaded", () => beatmaps != null);
ensureSoleilyRemoved();
createButtonWithBeatmap(createSoleily());
AddUntilStep("button state not downloaded", () => downloadButton.DownloadState == DownloadState.NotDownloaded);
AddStep("import soleily", () => beatmaps.Import(TestResources.GetQuickTestBeatmapForImport()));
AddUntilStep("wait for beatmap import", () => beatmaps.GetAllUsableBeatmapSets().Any(b => b.OnlineID == 241526));
AddUntilStep("button state downloaded", () => downloadButton.DownloadState == DownloadState.LocallyAvailable);
createButtonWithBeatmap(createSoleily());
AddUntilStep("button state downloaded", () => downloadButton.DownloadState == DownloadState.LocallyAvailable);
2019-06-27 20:01:21 +08:00
ensureSoleilyRemoved();
AddUntilStep("button state not downloaded", () => downloadButton.DownloadState == DownloadState.NotDownloaded);
2019-06-27 20:01:21 +08:00
}
private void ensureSoleilyRemoved()
{
AddStep("remove soleily", () =>
{
var beatmap = beatmaps.QueryBeatmapSet(b => b.OnlineID == 241526);
2019-06-27 20:01:21 +08:00
2021-12-17 17:26:12 +08:00
if (beatmap != null) beatmaps.Delete(beatmap.Value);
2019-06-27 20:01:21 +08:00
});
}
private void assertEnabled(bool enabled)
{
2019-06-27 12:38:21 +08:00
AddAssert($"button {(enabled ? "enabled" : "disabled")}", () => downloadButton.DownloadEnabled == enabled);
}
private void createButtonWithBeatmap(IBeatmapSetInfo beatmap)
2019-06-27 20:01:21 +08:00
{
AddStep("create button", () =>
{
Child = downloadButton = new TestDownloadButton(beatmap)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(75, 50),
};
});
}
private void createButton(bool downloadable)
{
AddStep("create button", () =>
{
Child = downloadButton = new TestDownloadButton(downloadable ? getDownloadableBeatmapSet() : getUndownloadableBeatmapSet())
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(75, 50),
};
});
}
private IBeatmapSetInfo createSoleily()
{
return new APIBeatmapSet
{
OnlineID = 241526,
Availability = new BeatmapSetOnlineAvailability
{
DownloadDisabled = false,
ExternalLink = string.Empty,
},
};
}
private IBeatmapSetInfo getDownloadableBeatmapSet()
{
var apiBeatmapSet = CreateAPIBeatmapSet();
apiBeatmapSet.HasVideo = true;
apiBeatmapSet.HasStoryboard = true;
return apiBeatmapSet;
}
private IBeatmapSetInfo getUndownloadableBeatmapSet()
{
var apiBeatmapSet = CreateAPIBeatmapSet();
apiBeatmapSet.Artist = "test";
apiBeatmapSet.Title = "undownloadable";
apiBeatmapSet.AuthorString = "test";
apiBeatmapSet.HasVideo = true;
apiBeatmapSet.HasStoryboard = true;
apiBeatmapSet.Availability = new BeatmapSetOnlineAvailability
{
DownloadDisabled = true,
ExternalLink = "http://osu.ppy.sh",
};
return apiBeatmapSet;
}
private class TestDownloadButton : BeatmapDownloadButton
{
2019-06-27 12:38:21 +08:00
public new bool DownloadEnabled => base.DownloadEnabled;
2019-06-27 20:01:21 +08:00
public DownloadState DownloadState => State.Value;
public TestDownloadButton(IBeatmapSetInfo beatmapSet)
2020-04-13 02:57:35 +08:00
: base(beatmapSet)
{
}
}
}
}