1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-14 21:57:55 +08:00
osu-lazer/osu.Game.Tests/Visual/Online/TestSceneBeatmapSetOverlay.cs

240 lines
7.7 KiB
C#
Raw Normal View History

2019-06-27 10:40:22 +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.
2018-04-13 17:19:50 +08:00
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Game.Beatmaps;
using osu.Game.Overlays;
using osu.Game.Overlays.BeatmapSet;
2018-04-13 17:19:50 +08:00
using osu.Game.Rulesets;
2019-02-06 00:32:33 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
using osu.Game.Online.API.Requests.Responses;
using APIUser = osu.Game.Online.API.Requests.Responses.APIUser;
2018-04-13 17:19:50 +08:00
2019-03-25 00:02:36 +08:00
namespace osu.Game.Tests.Visual.Online
2018-04-13 17:19:50 +08:00
{
[TestFixture]
public class TestSceneBeatmapSetOverlay : OsuTestScene
2018-04-13 17:19:50 +08:00
{
private readonly TestBeatmapSetOverlay overlay;
2018-04-13 17:19:50 +08:00
protected override bool UseOnlineAPI => true;
2019-08-01 03:44:44 +08:00
2021-09-09 18:36:47 +08:00
private int nextBeatmapSetId = 1;
public TestSceneBeatmapSetOverlay()
2018-04-13 17:19:50 +08:00
{
Add(overlay = new TestBeatmapSetOverlay());
2018-04-13 17:19:50 +08:00
}
[Resolved]
private RulesetStore rulesets { get; set; }
2018-04-13 17:19:50 +08:00
[Test]
public void TestLoading()
{
AddStep(@"show loading", () => overlay.ShowBeatmapSet(null));
}
[Test]
public void TestOnline()
{
AddStep(@"show online", () => overlay.FetchAndShowBeatmapSet(55));
}
[Test]
public void TestLocalBeatmaps()
{
2018-04-13 17:19:50 +08:00
AddStep(@"show first", () =>
{
overlay.ShowBeatmapSet(new APIBeatmapSet
2018-04-13 17:19:50 +08:00
{
OnlineID = 1235,
Title = @"an awesome beatmap",
Artist = @"naru narusegawa",
Source = @"hinata sou",
Tags = @"test tag tag more tag",
Author = new APIUser
2018-04-13 17:19:50 +08:00
{
Username = @"BanchoBot",
Id = 3,
2018-04-13 17:19:50 +08:00
},
Preview = @"https://b.ppy.sh/preview/12345.mp3",
PlayCount = 123,
FavouriteCount = 456,
Submitted = DateTime.Now,
Ranked = DateTime.Now,
BPM = 111,
HasVideo = true,
Ratings = Enumerable.Range(0, 11).ToArray(),
HasStoryboard = true,
Covers = new BeatmapSetOnlineCovers(),
Beatmaps = new[]
2018-04-13 17:19:50 +08:00
{
new APIBeatmap
2018-04-13 17:19:50 +08:00
{
StarRating = 9.99,
DifficultyName = @"TEST",
2019-07-08 01:25:36 +08:00
Length = 456000,
RulesetID = 3,
CircleSize = 1,
DrainRate = 2.3f,
OverallDifficulty = 4.5f,
ApproachRate = 6,
CircleCount = 111,
SliderCount = 12,
PlayCount = 222,
PassCount = 21,
FailTimes = new APIFailTimes
2018-04-13 17:19:50 +08:00
{
Fails = Enumerable.Range(1, 100).Select(i => i % 12 - 6).ToArray(),
Retries = Enumerable.Range(-2, 100).Select(i => i % 12 - 6).ToArray(),
2018-04-13 17:19:50 +08:00
},
},
},
});
2018-04-13 17:19:50 +08:00
});
2019-06-26 10:17:28 +08:00
2019-06-19 08:37:08 +08:00
downloadAssert(true);
AddStep("show many difficulties", () => overlay.ShowBeatmapSet(createManyDifficultiesBeatmapSet()));
downloadAssert(true);
}
2019-06-19 08:37:08 +08:00
[Test]
2019-06-27 12:48:57 +08:00
public void TestAvailability()
{
AddStep(@"show undownloadable", () =>
2018-04-13 17:19:50 +08:00
{
var set = getBeatmapSet();
set.Availability = new BeatmapSetOnlineAvailability
2018-04-13 17:19:50 +08:00
{
DownloadDisabled = true,
ExternalLink = "https://osu.ppy.sh",
};
overlay.ShowBeatmapSet(set);
2018-04-13 17:19:50 +08:00
});
2019-06-26 10:17:28 +08:00
downloadAssert(false);
}
[Test]
public void TestMultipleRulesets()
{
AddStep("show multiple rulesets beatmap", () =>
{
var beatmaps = new List<APIBeatmap>();
foreach (var ruleset in rulesets.AvailableRulesets.Skip(1))
{
beatmaps.Add(new APIBeatmap
{
DifficultyName = ruleset.Name,
RulesetID = ruleset.OnlineID,
FailTimes = new APIFailTimes
{
Fails = Enumerable.Range(1, 100).Select(i => i % 12 - 6).ToArray(),
Retries = Enumerable.Range(-2, 100).Select(i => i % 12 - 6).ToArray(),
},
});
}
var set = getBeatmapSet();
set.Beatmaps = beatmaps.ToArray();
overlay.ShowBeatmapSet(set);
});
AddAssert("shown beatmaps of current ruleset", () => overlay.Header.HeaderContent.Picker.Difficulties.All(b => b.Beatmap.Ruleset.OnlineID == overlay.Header.RulesetSelector.Current.Value.OnlineID));
AddAssert("left-most beatmap selected", () => overlay.Header.HeaderContent.Picker.Difficulties.First().State == BeatmapPicker.DifficultySelectorState.Selected);
}
[Test]
public void TestExplicitBeatmap()
{
AddStep("show explicit map", () =>
{
var beatmapSet = getBeatmapSet();
beatmapSet.HasExplicitContent = true;
overlay.ShowBeatmapSet(beatmapSet);
});
}
[Test]
public void TestFeaturedBeatmap()
{
AddStep("show featured map", () =>
{
var beatmapSet = getBeatmapSet();
beatmapSet.TrackId = 1;
overlay.ShowBeatmapSet(beatmapSet);
});
}
[Test]
public void TestHide()
{
2018-04-13 17:19:50 +08:00
AddStep(@"hide", overlay.Hide);
}
[Test]
public void TestShowWithNoReload()
{
2018-04-13 17:19:50 +08:00
AddStep(@"show without reload", overlay.Show);
}
private APIBeatmapSet createManyDifficultiesBeatmapSet()
{
var set = getBeatmapSet();
var beatmaps = new List<APIBeatmap>();
for (int i = 1; i < 41; i++)
{
beatmaps.Add(new APIBeatmap
{
OnlineID = i * 10,
DifficultyName = $"Test #{i}",
RulesetID = Ruleset.Value.OnlineID,
StarRating = 2 + i * 0.1,
OverallDifficulty = 3.5f,
FailTimes = new APIFailTimes
{
Fails = Enumerable.Range(1, 100).Select(j => j % 12 - 6).ToArray(),
Retries = Enumerable.Range(-2, 100).Select(j => j % 12 - 6).ToArray(),
},
});
}
set.Beatmaps = beatmaps.ToArray();
return set;
}
private APIBeatmapSet getBeatmapSet()
{
var beatmapSet = CreateAPIBeatmapSet(Ruleset.Value);
2021-09-09 18:36:47 +08:00
// Make sure the overlay is reloaded (see `BeatmapSetInfo.Equals`).
beatmapSet.OnlineID = nextBeatmapSetId++;
return beatmapSet;
}
private void downloadAssert(bool shown)
{
AddAssert($"is download button {(shown ? "shown" : "hidden")}", () => overlay.Header.HeaderContent.DownloadButtonsVisible == shown);
}
private class TestBeatmapSetOverlay : BeatmapSetOverlay
{
public new BeatmapSetHeader Header => base.Header;
}
2018-04-13 17:19:50 +08:00
}
}