1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 11:27:24 +08:00

Add test for download button states

This commit is contained in:
naoey 2019-06-27 17:31:21 +05:30
parent 61260cf599
commit 3cfa5a767f
No known key found for this signature in database
GPG Key ID: 670DA9BE3DF7EE60

View File

@ -3,11 +3,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Game.Beatmaps;
using osu.Game.Online;
using osu.Game.Overlays.Direct;
using osu.Game.Rulesets.Osu;
using osu.Game.Tests.Resources;
using osuTK;
namespace osu.Game.Tests.Visual.Online
@ -21,6 +25,9 @@ namespace osu.Game.Tests.Visual.Online
private TestDownloadButton downloadButton;
[Resolved]
private BeatmapManager beatmaps { get; set; }
[Test]
public void TestDownloadableBeatmap()
{
@ -35,11 +42,66 @@ namespace osu.Game.Tests.Visual.Online
assertEnabled(false);
}
[Test]
public void TestDownloadState()
{
AddUntilStep("ensure manager loaded", () => beatmaps != null);
ensureSoleilyRemoved();
createButtonWithBeatmap(createSoleily());
AddAssert("button state not downloaded", () => downloadButton.DownloadState == DownloadState.NotDownloaded);
AddStep("import soleily", () => beatmaps.Import(new[] { TestResources.GetTestBeatmapForImport() }));
AddUntilStep("wait for beatmap import", () => beatmaps.GetAllUsableBeatmapSets().Any(b => b.OnlineBeatmapSetID == 241526));
createButtonWithBeatmap(createSoleily());
AddAssert("button state downloaded", () => downloadButton.DownloadState == DownloadState.LocallyAvailable);
ensureSoleilyRemoved();
AddAssert("button state not downloaded", () => downloadButton.DownloadState == DownloadState.NotDownloaded);
}
private void ensureSoleilyRemoved()
{
AddStep("remove soleily", () =>
{
var beatmap = beatmaps.QueryBeatmapSet(b => b.OnlineBeatmapSetID == 241526);
if (beatmap != null) beatmaps.Delete(beatmap);
});
}
private void assertEnabled(bool enabled)
{
AddAssert($"button {(enabled ? "enabled" : "disabled")}", () => downloadButton.DownloadEnabled == enabled);
}
private BeatmapSetInfo createSoleily()
{
return new BeatmapSetInfo
{
ID = 1,
OnlineBeatmapSetID = 241526,
OnlineInfo = new BeatmapSetOnlineInfo
{
Availability = new BeatmapSetOnlineAvailability
{
DownloadDisabled = false,
ExternalLink = string.Empty,
},
},
};
}
private void createButtonWithBeatmap(BeatmapSetInfo beatmap)
{
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", () =>
@ -85,6 +147,8 @@ namespace osu.Game.Tests.Visual.Online
{
public new bool DownloadEnabled => base.DownloadEnabled;
public DownloadState DownloadState => State.Value;
public TestDownloadButton(BeatmapSetInfo beatmapSet, bool noVideo = false)
: base(beatmapSet, noVideo)
{