1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 22:03:01 +08:00
osu-lazer/osu.Game.Tests/Visual/Online/TestSceneBeatmapSetOverlay.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

292 lines
10 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
2022-06-17 15:37:17 +08:00
#nullable disable
2018-03-02 14:34:31 +08:00
using NUnit.Framework;
2017-09-13 10:41:10 +08:00
using osu.Framework.Allocation;
using osu.Game.Beatmaps;
using osu.Game.Overlays;
using osu.Game.Overlays.BeatmapSet;
2017-09-13 10:41:10 +08:00
using osu.Game.Rulesets;
2019-02-06 00:32:33 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
2022-05-27 08:39:29 +08:00
using osu.Framework.Testing;
using osu.Game.Beatmaps.Drawables;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Overlays.BeatmapSet.Scores;
2022-07-23 15:01:06 +08:00
using osu.Game.Resources.Localisation.Web;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Osu.Mods;
using osu.Game.Screens.Select.Details;
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
2017-09-13 10:41:10 +08:00
{
public partial class TestSceneBeatmapSetOverlay : OsuTestScene
2017-09-13 10:41:10 +08:00
{
private readonly TestBeatmapSetOverlay overlay;
2018-04-13 17:19:50 +08:00
2021-09-09 18:36:47 +08:00
private int nextBeatmapSetId = 1;
public TestSceneBeatmapSetOverlay()
2017-09-13 10:41:10 +08:00
{
Add(overlay = new TestBeatmapSetOverlay());
2017-09-13 10:41:10 +08:00
}
2018-04-13 17:19:50 +08:00
[Resolved]
private IRulesetStore rulesets { get; set; }
2018-04-13 17:19:50 +08:00
2022-07-23 15:01:06 +08:00
[SetUp]
public void SetUp() => Schedule(() => SelectedMods.Value = Array.Empty<Mod>());
[Test]
public void TestLoading()
{
AddStep(@"show loading", () => overlay.ShowBeatmapSet(null));
}
[Test]
public void TestLocalBeatmaps()
{
2017-09-13 10:41:10 +08:00
AddStep(@"show first", () =>
{
overlay.ShowBeatmapSet(new APIBeatmapSet
2017-09-13 10:41:10 +08:00
{
OnlineID = 1235,
Title = @"an awesome beatmap",
Artist = @"naru narusegawa",
Source = @"hinata sou",
Tags = @"test tag tag more tag",
Author = new APIUser
2017-09-13 10:41:10 +08:00
{
Username = @"BanchoBot",
Id = 3,
2017-09-13 10:41:10 +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[]
2017-09-13 10:41:10 +08:00
{
new APIBeatmap
2017-09-13 10:41:10 +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
2017-09-13 10:41:10 +08:00
{
Fails = Enumerable.Range(1, 100).Select(i => i % 12 - 6).ToArray(),
Retries = Enumerable.Range(-2, 100).Select(i => i % 12 - 6).ToArray(),
2017-09-13 10:41:10 +08:00
},
},
},
});
2017-09-13 10:41:10 +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);
2022-05-27 08:39:29 +08:00
AddAssert("status is loved", () => overlay.ChildrenOfType<BeatmapSetOnlineStatusPill>().Single().Status == BeatmapOnlineStatus.Loved);
AddAssert("scores container is visible", () => overlay.ChildrenOfType<ScoresContainer>().Single().Alpha == 1);
AddAssert("mod selector is visible", () => overlay.ChildrenOfType<LeaderboardModSelector>().Single().Alpha == 1);
2022-05-27 08:39:29 +08:00
AddStep("go to second beatmap", () => overlay.ChildrenOfType<BeatmapPicker.DifficultySelectorButton>().ElementAt(1).TriggerClick());
AddAssert("status is graveyard", () => overlay.ChildrenOfType<BeatmapSetOnlineStatusPill>().Single().Status == BeatmapOnlineStatus.Graveyard);
AddAssert("scores container is hidden", () => overlay.ChildrenOfType<ScoresContainer>().Single().Alpha == 0);
}
2019-06-19 08:37:08 +08:00
[Test]
2019-06-27 12:48:57 +08:00
public void TestAvailability()
{
AddStep(@"show undownloadable", () =>
2017-09-13 10:41:10 +08:00
{
var set = getBeatmapSet();
set.Availability = new BeatmapSetOnlineAvailability
2017-09-13 10:41:10 +08:00
{
DownloadDisabled = true,
ExternalLink = "https://osu.ppy.sh",
};
overlay.ShowBeatmapSet(set);
2017-09-13 10:41:10 +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 TestSpotlightBeatmap()
{
AddStep("show spotlight map", () =>
{
var beatmapSet = getBeatmapSet();
beatmapSet.FeaturedInSpotlight = true;
overlay.ShowBeatmapSet(beatmapSet);
});
}
[Test]
public void TestFeaturedBeatmap()
{
AddStep("show featured map", () =>
{
var beatmapSet = getBeatmapSet();
beatmapSet.TrackId = 1;
overlay.ShowBeatmapSet(beatmapSet);
});
}
[Test]
public void TestAllBadgesBeatmap()
{
AddStep("show map with all badges", () =>
{
var beatmapSet = getBeatmapSet();
beatmapSet.HasExplicitContent = true;
beatmapSet.FeaturedInSpotlight = true;
beatmapSet.TrackId = 1;
overlay.ShowBeatmapSet(beatmapSet);
});
}
2022-07-23 15:01:06 +08:00
[Test]
public void TestSelectedModsDontAffectStatistics()
{
AddStep("show map", () => overlay.ShowBeatmapSet(getBeatmapSet()));
AddAssert("AR displayed as 0", () => overlay.ChildrenOfType<AdvancedStats.StatisticRow>().Single(s => s.Title == BeatmapsetsStrings.ShowStatsAr).Value == (0, null));
AddStep("set AR10 diff adjust", () => SelectedMods.Value = new[]
{
new OsuModDifficultyAdjust
{
ApproachRate = { Value = 10 }
}
});
AddAssert("AR still displayed as 0", () => overlay.ChildrenOfType<AdvancedStats.StatisticRow>().Single(s => s.Title == BeatmapsetsStrings.ShowStatsAr).Value == (0, null));
}
[Test]
public void TestHide()
{
2017-09-13 10:41:10 +08:00
AddStep(@"hide", overlay.Hide);
}
[Test]
public void TestShowWithNoReload()
{
2017-09-13 10:41:10 +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(),
},
2022-05-27 08:39:29 +08:00
Status = i % 2 == 0 ? BeatmapOnlineStatus.Graveyard : BeatmapOnlineStatus.Loved,
});
}
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 partial class TestBeatmapSetOverlay : BeatmapSetOverlay
{
public new BeatmapSetHeader Header => base.Header;
}
2017-09-13 10:41:10 +08:00
}
}