2021-10-17 15:00:54 +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.
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
2021-10-17 16:24:17 +00:00
|
|
|
using NUnit.Framework;
|
2021-10-17 15:00:54 +00:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2021-11-07 16:42:32 +00:00
|
|
|
using osu.Framework.Testing;
|
2021-10-17 15:00:54 +00:00
|
|
|
using osu.Game.Beatmaps;
|
2021-12-15 07:13:12 +00:00
|
|
|
using osu.Game.Beatmaps.Drawables;
|
2021-10-17 16:24:17 +00:00
|
|
|
using osu.Game.Beatmaps.Drawables.Cards;
|
2021-12-05 14:04:44 +00:00
|
|
|
using osu.Game.Graphics.Containers;
|
2021-11-07 16:42:32 +00:00
|
|
|
using osu.Game.Online.API;
|
|
|
|
using osu.Game.Online.API.Requests;
|
2021-10-17 15:00:54 +00:00
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
|
|
|
using osu.Game.Overlays;
|
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.Beatmaps
|
|
|
|
{
|
2021-12-15 07:13:12 +00:00
|
|
|
public class TestSceneBeatmapCard : OsuManualInputManagerTestScene
|
2021-10-17 15:00:54 +00:00
|
|
|
{
|
2021-11-24 19:34:33 +00:00
|
|
|
/// <summary>
|
|
|
|
/// All cards on this scene use a common online ID to ensure that map download, preview tracks, etc. can be tested manually with online sources.
|
|
|
|
/// </summary>
|
|
|
|
private const int online_id = 163112;
|
|
|
|
|
2021-11-07 16:42:32 +00:00
|
|
|
private DummyAPIAccess dummyAPI => (DummyAPIAccess)API;
|
|
|
|
|
2021-10-17 16:24:17 +00:00
|
|
|
private APIBeatmapSet[] testCases;
|
2021-10-17 15:00:54 +00:00
|
|
|
|
2021-11-10 15:03:48 +00:00
|
|
|
[Resolved]
|
|
|
|
private BeatmapManager beatmaps { get; set; }
|
|
|
|
|
2021-10-17 15:00:54 +00:00
|
|
|
#region Test case generation
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
|
|
|
var normal = CreateAPIBeatmapSet(Ruleset.Value);
|
|
|
|
normal.HasVideo = true;
|
|
|
|
normal.HasStoryboard = true;
|
|
|
|
|
2021-10-17 18:50:44 +00:00
|
|
|
var withStatistics = CreateAPIBeatmapSet(Ruleset.Value);
|
2021-11-08 04:27:04 +00:00
|
|
|
withStatistics.Title = withStatistics.TitleUnicode = "play favourite stats";
|
2021-11-24 09:42:47 +00:00
|
|
|
withStatistics.Status = BeatmapOnlineStatus.Approved;
|
2021-10-17 18:50:44 +00:00
|
|
|
withStatistics.FavouriteCount = 284_239;
|
|
|
|
withStatistics.PlayCount = 999_001;
|
|
|
|
withStatistics.Ranked = DateTimeOffset.Now.AddDays(-45);
|
2021-10-17 19:05:26 +00:00
|
|
|
withStatistics.HypeStatus = new BeatmapSetHypeStatus
|
|
|
|
{
|
|
|
|
Current = 34,
|
|
|
|
Required = 5
|
|
|
|
};
|
|
|
|
withStatistics.NominationStatus = new BeatmapSetNominationStatus
|
|
|
|
{
|
|
|
|
Current = 1,
|
|
|
|
Required = 2
|
|
|
|
};
|
2021-10-17 18:50:44 +00:00
|
|
|
|
2021-10-17 15:00:54 +00:00
|
|
|
var undownloadable = getUndownloadableBeatmapSet();
|
2021-10-17 18:50:44 +00:00
|
|
|
undownloadable.LastUpdated = DateTimeOffset.Now.AddYears(-1);
|
2021-10-17 16:24:17 +00:00
|
|
|
|
|
|
|
var someDifficulties = getManyDifficultiesBeatmapSet(11);
|
2021-11-08 04:27:04 +00:00
|
|
|
someDifficulties.Title = someDifficulties.TitleUnicode = "favourited";
|
2021-10-17 16:24:17 +00:00
|
|
|
someDifficulties.Title = someDifficulties.TitleUnicode = "some difficulties";
|
2021-11-24 09:42:47 +00:00
|
|
|
someDifficulties.Status = BeatmapOnlineStatus.Qualified;
|
2021-10-17 18:50:44 +00:00
|
|
|
someDifficulties.HasFavourited = true;
|
|
|
|
someDifficulties.FavouriteCount = 1;
|
2021-11-07 20:20:21 +00:00
|
|
|
someDifficulties.NominationStatus = new BeatmapSetNominationStatus
|
|
|
|
{
|
|
|
|
Current = 2,
|
|
|
|
Required = 2
|
|
|
|
};
|
2021-10-17 16:24:17 +00:00
|
|
|
|
|
|
|
var manyDifficulties = getManyDifficultiesBeatmapSet(100);
|
2021-11-24 09:42:47 +00:00
|
|
|
manyDifficulties.Status = BeatmapOnlineStatus.Pending;
|
2021-10-17 15:00:54 +00:00
|
|
|
|
|
|
|
var explicitMap = CreateAPIBeatmapSet(Ruleset.Value);
|
2021-11-08 04:27:04 +00:00
|
|
|
explicitMap.Title = someDifficulties.TitleUnicode = "explicit beatmap";
|
2021-10-17 15:00:54 +00:00
|
|
|
explicitMap.HasExplicitContent = true;
|
|
|
|
|
|
|
|
var featuredMap = CreateAPIBeatmapSet(Ruleset.Value);
|
2021-11-08 04:27:04 +00:00
|
|
|
featuredMap.Title = someDifficulties.TitleUnicode = "featured artist beatmap";
|
2021-10-17 15:00:54 +00:00
|
|
|
featuredMap.TrackId = 1;
|
|
|
|
|
|
|
|
var explicitFeaturedMap = CreateAPIBeatmapSet(Ruleset.Value);
|
2021-11-08 04:27:04 +00:00
|
|
|
explicitFeaturedMap.Title = someDifficulties.TitleUnicode = "explicit featured artist";
|
2021-10-17 15:00:54 +00:00
|
|
|
explicitFeaturedMap.HasExplicitContent = true;
|
|
|
|
explicitFeaturedMap.TrackId = 2;
|
|
|
|
|
2021-10-17 16:24:17 +00:00
|
|
|
var longName = CreateAPIBeatmapSet(Ruleset.Value);
|
|
|
|
longName.Title = longName.TitleUnicode = "this track has an incredibly and implausibly long title";
|
|
|
|
longName.Artist = longName.ArtistUnicode = "and this artist! who would have thunk it. it's really such a long name.";
|
2021-11-27 14:47:52 +00:00
|
|
|
longName.Source = "wow. even the source field has an impossibly long string in it. this really takes the cake, doesn't it?";
|
2021-10-17 16:24:17 +00:00
|
|
|
longName.HasExplicitContent = true;
|
|
|
|
longName.TrackId = 444;
|
|
|
|
|
|
|
|
testCases = new[]
|
2021-10-17 15:00:54 +00:00
|
|
|
{
|
|
|
|
normal,
|
2021-10-17 18:50:44 +00:00
|
|
|
withStatistics,
|
2021-10-17 15:00:54 +00:00
|
|
|
undownloadable,
|
2021-10-17 16:24:17 +00:00
|
|
|
someDifficulties,
|
2021-10-17 15:00:54 +00:00
|
|
|
manyDifficulties,
|
|
|
|
explicitMap,
|
|
|
|
featuredMap,
|
2021-10-17 16:24:17 +00:00
|
|
|
explicitFeaturedMap,
|
|
|
|
longName
|
2021-10-17 15:00:54 +00:00
|
|
|
};
|
2021-11-24 19:34:33 +00:00
|
|
|
|
|
|
|
foreach (var testCase in testCases)
|
|
|
|
testCase.OnlineID = online_id;
|
2021-10-17 15:00:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private APIBeatmapSet getUndownloadableBeatmapSet() => new APIBeatmapSet
|
|
|
|
{
|
|
|
|
OnlineID = 123,
|
|
|
|
Title = "undownloadable beatmap",
|
|
|
|
Artist = "test",
|
|
|
|
Source = "more tests",
|
2021-11-04 09:02:44 +00:00
|
|
|
Author = new APIUser
|
2021-10-17 15:00:54 +00:00
|
|
|
{
|
|
|
|
Username = "BanchoBot",
|
|
|
|
Id = 3,
|
|
|
|
},
|
|
|
|
Availability = new BeatmapSetOnlineAvailability
|
|
|
|
{
|
|
|
|
DownloadDisabled = true,
|
|
|
|
},
|
|
|
|
Preview = @"https://b.ppy.sh/preview/12345.mp3",
|
|
|
|
PlayCount = 123,
|
|
|
|
FavouriteCount = 456,
|
|
|
|
BPM = 111,
|
|
|
|
HasVideo = true,
|
|
|
|
HasStoryboard = true,
|
|
|
|
Covers = new BeatmapSetOnlineCovers(),
|
2021-11-04 07:44:05 +00:00
|
|
|
Beatmaps = new[]
|
2021-10-17 15:00:54 +00:00
|
|
|
{
|
|
|
|
new APIBeatmap
|
|
|
|
{
|
|
|
|
RulesetID = Ruleset.Value.OnlineID,
|
|
|
|
DifficultyName = "Test",
|
|
|
|
StarRating = 6.42,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-10-17 16:24:17 +00:00
|
|
|
private static APIBeatmapSet getManyDifficultiesBeatmapSet(int count)
|
2021-10-17 15:00:54 +00:00
|
|
|
{
|
|
|
|
var beatmaps = new List<APIBeatmap>();
|
|
|
|
|
2021-10-17 16:24:17 +00:00
|
|
|
for (int i = 0; i < count; i++)
|
2021-10-17 15:00:54 +00:00
|
|
|
{
|
|
|
|
beatmaps.Add(new APIBeatmap
|
|
|
|
{
|
|
|
|
RulesetID = i % 4,
|
|
|
|
StarRating = 2 + i % 4 * 2,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return new APIBeatmapSet
|
|
|
|
{
|
|
|
|
OnlineID = 1,
|
|
|
|
Title = "many difficulties beatmap",
|
|
|
|
Artist = "test",
|
2021-11-04 09:02:44 +00:00
|
|
|
Author = new APIUser
|
2021-10-17 15:00:54 +00:00
|
|
|
{
|
|
|
|
Username = "BanchoBot",
|
|
|
|
Id = 3,
|
|
|
|
},
|
|
|
|
HasVideo = true,
|
|
|
|
HasStoryboard = true,
|
|
|
|
Covers = new BeatmapSetOnlineCovers(),
|
2021-11-04 07:44:05 +00:00
|
|
|
Beatmaps = beatmaps.ToArray(),
|
2021-10-17 15:00:54 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2021-11-07 16:42:32 +00:00
|
|
|
[SetUpSteps]
|
|
|
|
public void SetUpSteps()
|
|
|
|
{
|
|
|
|
AddStep("register request handling", () => dummyAPI.HandleRequest = request =>
|
|
|
|
{
|
|
|
|
if (!(request is PostBeatmapFavouriteRequest))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
request.TriggerSuccess();
|
|
|
|
return true;
|
|
|
|
});
|
2021-11-10 15:03:48 +00:00
|
|
|
|
|
|
|
ensureSoleilyRemoved();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void ensureSoleilyRemoved()
|
|
|
|
{
|
|
|
|
AddUntilStep("ensure manager loaded", () => beatmaps != null);
|
2021-11-24 19:34:33 +00:00
|
|
|
AddStep("remove map", () =>
|
2021-11-10 15:03:48 +00:00
|
|
|
{
|
2021-11-24 19:34:33 +00:00
|
|
|
var beatmap = beatmaps.QueryBeatmapSet(b => b.OnlineID == online_id);
|
2021-11-10 15:03:48 +00:00
|
|
|
|
2021-12-17 09:26:12 +00:00
|
|
|
if (beatmap != null) beatmaps.Delete(beatmap.Value);
|
2021-11-10 15:03:48 +00:00
|
|
|
});
|
2021-11-07 16:42:32 +00:00
|
|
|
}
|
|
|
|
|
2021-10-17 16:24:17 +00:00
|
|
|
private Drawable createContent(OverlayColourScheme colourScheme, Func<APIBeatmapSet, Drawable> creationFunc)
|
2021-10-17 15:00:54 +00:00
|
|
|
{
|
|
|
|
var colourProvider = new OverlayColourProvider(colourScheme);
|
|
|
|
|
|
|
|
return new DependencyProvidingContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
CachedDependencies = new (Type, object)[]
|
|
|
|
{
|
|
|
|
(typeof(OverlayColourProvider), colourProvider)
|
|
|
|
},
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Colour = colourProvider.Background5
|
|
|
|
},
|
|
|
|
new BasicScrollContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2021-12-05 14:04:44 +00:00
|
|
|
Child = new ReverseChildIDFillFlowContainer<Drawable>
|
2021-10-17 15:00:54 +00:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
Direction = FillDirection.Full,
|
|
|
|
Padding = new MarginPadding(10),
|
|
|
|
Spacing = new Vector2(10),
|
|
|
|
ChildrenEnumerable = testCases.Select(creationFunc)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-10-17 16:24:17 +00:00
|
|
|
private void createTestCase(Func<APIBeatmapSet, Drawable> creationFunc)
|
2021-10-17 15:00:54 +00:00
|
|
|
{
|
|
|
|
foreach (var scheme in Enum.GetValues(typeof(OverlayColourScheme)).Cast<OverlayColourScheme>())
|
|
|
|
AddStep($"set {scheme} scheme", () => Child = createContent(scheme, creationFunc));
|
|
|
|
}
|
2021-10-17 16:24:17 +00:00
|
|
|
|
|
|
|
[Test]
|
2021-12-05 14:04:44 +00:00
|
|
|
public void TestNormal()
|
|
|
|
{
|
2021-12-21 07:25:52 +00:00
|
|
|
createTestCase(beatmapSetInfo => new BeatmapCardNormal(beatmapSetInfo));
|
2021-12-15 07:13:12 +00:00
|
|
|
}
|
2021-12-05 14:04:44 +00:00
|
|
|
|
2021-12-17 10:44:36 +00:00
|
|
|
[Test]
|
|
|
|
public void TestExtra()
|
|
|
|
{
|
|
|
|
createTestCase(beatmapSetInfo => new BeatmapCardExtra(beatmapSetInfo));
|
|
|
|
}
|
|
|
|
|
2021-12-15 07:13:12 +00:00
|
|
|
[Test]
|
|
|
|
public void TestHoverState()
|
|
|
|
{
|
2021-12-21 07:25:52 +00:00
|
|
|
AddStep("create cards", () => Child = createContent(OverlayColourScheme.Blue, s => new BeatmapCardNormal(s)));
|
2021-12-15 07:13:12 +00:00
|
|
|
|
|
|
|
AddStep("Hover card", () => InputManager.MoveMouseTo(firstCard()));
|
|
|
|
AddWaitStep("wait for potential state change", 5);
|
|
|
|
AddAssert("card is not expanded", () => !firstCard().Expanded.Value);
|
|
|
|
|
|
|
|
AddStep("Hover spectrum display", () => InputManager.MoveMouseTo(firstCard().ChildrenOfType<DifficultySpectrumDisplay>().Single()));
|
|
|
|
AddUntilStep("card is expanded", () => firstCard().Expanded.Value);
|
|
|
|
|
|
|
|
AddStep("Hover difficulty content", () => InputManager.MoveMouseTo(firstCard().ChildrenOfType<BeatmapCardDifficultyList>().Single()));
|
|
|
|
AddWaitStep("wait for potential state change", 5);
|
|
|
|
AddAssert("card is still expanded", () => firstCard().Expanded.Value);
|
|
|
|
|
|
|
|
AddStep("Hover main content again", () => InputManager.MoveMouseTo(firstCard()));
|
|
|
|
AddWaitStep("wait for potential state change", 5);
|
|
|
|
AddAssert("card is still expanded", () => firstCard().Expanded.Value);
|
|
|
|
|
2021-12-21 07:25:52 +00:00
|
|
|
AddStep("Hover away", () => InputManager.MoveMouseTo(this.ChildrenOfType<BeatmapCardNormal>().Last()));
|
2021-12-15 07:13:12 +00:00
|
|
|
AddUntilStep("card is not expanded", () => !firstCard().Expanded.Value);
|
|
|
|
|
2021-12-21 07:25:52 +00:00
|
|
|
BeatmapCardNormal firstCard() => this.ChildrenOfType<BeatmapCardNormal>().First();
|
2021-12-05 14:04:44 +00:00
|
|
|
}
|
2021-10-17 15:00:54 +00:00
|
|
|
}
|
|
|
|
}
|