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