2021-01-25 20:41:05 +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.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Testing;
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Online.API;
|
|
|
|
using osu.Game.Online.API.Requests;
|
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
|
|
|
using osu.Game.Overlays;
|
|
|
|
using osu.Game.Overlays.BeatmapListing;
|
|
|
|
using osu.Game.Rulesets;
|
2021-06-20 09:17:07 +00:00
|
|
|
using osu.Game.Users;
|
2021-01-25 20:41:05 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.Online
|
|
|
|
{
|
|
|
|
public class TestSceneBeatmapListingOverlay : OsuTestScene
|
|
|
|
{
|
|
|
|
private readonly List<APIBeatmapSet> setsForResponse = new List<APIBeatmapSet>();
|
|
|
|
|
|
|
|
private BeatmapListingOverlay overlay;
|
|
|
|
|
2021-06-22 05:53:21 +00:00
|
|
|
private BeatmapListingSearchControl searchControl => overlay.ChildrenOfType<BeatmapListingSearchControl>().Single();
|
|
|
|
|
2021-01-25 20:41:05 +00:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
|
|
|
Child = overlay = new BeatmapListingOverlay { State = { Value = Visibility.Visible } };
|
|
|
|
|
|
|
|
((DummyAPIAccess)API).HandleRequest = req =>
|
|
|
|
{
|
2021-03-23 09:08:32 +00:00
|
|
|
if (!(req is SearchBeatmapSetsRequest searchBeatmapSetsRequest)) return false;
|
|
|
|
|
|
|
|
searchBeatmapSetsRequest.TriggerSuccess(new SearchBeatmapSetsResponse
|
2021-01-25 20:41:05 +00:00
|
|
|
{
|
2021-03-23 09:08:32 +00:00
|
|
|
BeatmapSets = setsForResponse,
|
|
|
|
});
|
|
|
|
|
|
|
|
return true;
|
2021-01-25 20:41:05 +00:00
|
|
|
};
|
2021-06-20 10:28:43 +00:00
|
|
|
|
|
|
|
AddStep("initialize dummy", () =>
|
|
|
|
{
|
|
|
|
// non-supporter user
|
|
|
|
((DummyAPIAccess)API).LocalUser.Value = new User
|
|
|
|
{
|
|
|
|
Username = "TestBot",
|
|
|
|
Id = API.LocalUser.Value.Id + 1,
|
|
|
|
};
|
|
|
|
});
|
2021-01-25 20:41:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestNoBeatmapsPlaceholder()
|
|
|
|
{
|
|
|
|
AddStep("fetch for 0 beatmaps", () => fetchFor());
|
|
|
|
AddUntilStep("placeholder shown", () => overlay.ChildrenOfType<BeatmapListingOverlay.NotFoundDrawable>().SingleOrDefault()?.IsPresent == true);
|
|
|
|
|
|
|
|
AddStep("fetch for 1 beatmap", () => fetchFor(CreateBeatmap(Ruleset.Value).BeatmapInfo.BeatmapSet));
|
|
|
|
AddUntilStep("placeholder hidden", () => !overlay.ChildrenOfType<BeatmapListingOverlay.NotFoundDrawable>().Any());
|
|
|
|
|
|
|
|
AddStep("fetch for 0 beatmaps", () => fetchFor());
|
|
|
|
AddUntilStep("placeholder shown", () => overlay.ChildrenOfType<BeatmapListingOverlay.NotFoundDrawable>().SingleOrDefault()?.IsPresent == true);
|
|
|
|
|
|
|
|
// fetch once more to ensure nothing happens in displaying placeholder again when it already is present.
|
|
|
|
AddStep("fetch for 0 beatmaps again", () => fetchFor());
|
|
|
|
AddUntilStep("placeholder shown", () => overlay.ChildrenOfType<BeatmapListingOverlay.NotFoundDrawable>().SingleOrDefault()?.IsPresent == true);
|
|
|
|
}
|
|
|
|
|
2021-06-20 09:17:07 +00:00
|
|
|
[Test]
|
2021-06-26 17:27:34 +00:00
|
|
|
public void TestUserWithoutSupporterUsesSupporterOnlyFiltersWithoutResults()
|
2021-06-20 10:28:43 +00:00
|
|
|
{
|
2021-06-20 13:23:54 +00:00
|
|
|
AddStep("fetch for 0 beatmaps", () => fetchFor());
|
2021-06-20 10:28:43 +00:00
|
|
|
AddStep("set dummy as non-supporter", () => ((DummyAPIAccess)API).LocalUser.Value.IsSupporter = false);
|
2021-06-20 09:17:07 +00:00
|
|
|
|
2021-06-20 10:28:43 +00:00
|
|
|
// test non-supporter on Rank Achieved filter
|
2021-06-22 05:53:21 +00:00
|
|
|
toggleRankFilter(Scoring.ScoreRank.XH);
|
|
|
|
supporterRequiredPlaceholderShown();
|
2021-06-20 09:17:07 +00:00
|
|
|
|
2021-06-22 05:53:21 +00:00
|
|
|
AddStep("Clear Rank Achieved filter", () => searchControl.Ranks.Clear());
|
|
|
|
notFoundPlaceholderShown();
|
2021-06-20 09:17:07 +00:00
|
|
|
|
2021-06-20 10:28:43 +00:00
|
|
|
// test non-supporter on Played filter
|
2021-06-22 05:53:21 +00:00
|
|
|
toggleSupporterOnlyPlayedFilter(SearchPlayed.Played);
|
|
|
|
supporterRequiredPlaceholderShown();
|
2021-06-20 13:23:54 +00:00
|
|
|
|
2021-06-22 05:53:21 +00:00
|
|
|
AddStep("Set Played filter to Any", () => searchControl.Played.Value = SearchPlayed.Any);
|
|
|
|
notFoundPlaceholderShown();
|
2021-06-20 13:23:54 +00:00
|
|
|
|
|
|
|
// test non-supporter on both Rank Achieved and Played filter
|
2021-06-22 05:53:21 +00:00
|
|
|
toggleRankFilter(Scoring.ScoreRank.XH);
|
|
|
|
toggleSupporterOnlyPlayedFilter(SearchPlayed.Played);
|
|
|
|
supporterRequiredPlaceholderShown();
|
2021-06-20 09:17:07 +00:00
|
|
|
|
2021-06-22 05:53:21 +00:00
|
|
|
AddStep("Clear Rank Achieved filter", () => searchControl.Ranks.Clear());
|
|
|
|
AddStep("Set Played filter to Any", () => searchControl.Played.Value = SearchPlayed.Any);
|
|
|
|
notFoundPlaceholderShown();
|
|
|
|
}
|
2021-06-20 09:17:07 +00:00
|
|
|
|
2021-06-22 05:53:21 +00:00
|
|
|
[Test]
|
2021-06-26 17:27:34 +00:00
|
|
|
public void TestUserWithSupporterUsesSupporterOnlyFiltersWithoutResults()
|
2021-06-22 05:53:21 +00:00
|
|
|
{
|
|
|
|
AddStep("fetch for 0 beatmaps", () => fetchFor());
|
2021-06-20 10:28:43 +00:00
|
|
|
AddStep("set dummy as supporter", () => ((DummyAPIAccess)API).LocalUser.Value.IsSupporter = true);
|
2021-06-20 09:17:07 +00:00
|
|
|
|
2021-06-20 10:28:43 +00:00
|
|
|
// test supporter on Rank Achieved filter
|
2021-06-22 05:53:21 +00:00
|
|
|
toggleRankFilter(Scoring.ScoreRank.XH);
|
|
|
|
notFoundPlaceholderShown();
|
2021-06-20 09:17:07 +00:00
|
|
|
|
2021-06-22 05:53:21 +00:00
|
|
|
AddStep("Clear Rank Achieved filter", () => searchControl.Ranks.Clear());
|
|
|
|
notFoundPlaceholderShown();
|
2021-06-20 09:17:07 +00:00
|
|
|
|
2021-06-20 10:28:43 +00:00
|
|
|
// test supporter on Played filter
|
2021-06-22 05:53:21 +00:00
|
|
|
toggleSupporterOnlyPlayedFilter(SearchPlayed.Played);
|
|
|
|
notFoundPlaceholderShown();
|
2021-06-20 09:17:07 +00:00
|
|
|
|
2021-06-22 05:53:21 +00:00
|
|
|
AddStep("Set Played filter to Any", () => searchControl.Played.Value = SearchPlayed.Any);
|
|
|
|
notFoundPlaceholderShown();
|
2021-06-20 13:23:54 +00:00
|
|
|
|
|
|
|
// test supporter on both Rank Achieved and Played filter
|
2021-06-22 05:53:21 +00:00
|
|
|
toggleRankFilter(Scoring.ScoreRank.XH);
|
|
|
|
toggleSupporterOnlyPlayedFilter(SearchPlayed.Played);
|
|
|
|
notFoundPlaceholderShown();
|
2021-06-20 13:23:54 +00:00
|
|
|
|
2021-06-22 05:53:21 +00:00
|
|
|
AddStep("Clear Rank Achieved filter", () => searchControl.Ranks.Clear());
|
|
|
|
AddStep("Set Played filter to Any", () => searchControl.Played.Value = SearchPlayed.Any);
|
|
|
|
notFoundPlaceholderShown();
|
2021-06-20 10:28:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2021-06-26 17:27:34 +00:00
|
|
|
public void TestUserWithoutSupporterUsesSupporterOnlyFiltersWithResults()
|
2021-06-20 10:28:43 +00:00
|
|
|
{
|
|
|
|
AddStep("fetch for 1 beatmap", () => fetchFor(CreateBeatmap(Ruleset.Value).BeatmapInfo.BeatmapSet));
|
|
|
|
AddStep("set dummy as non-supporter", () => ((DummyAPIAccess)API).LocalUser.Value.IsSupporter = false);
|
|
|
|
|
|
|
|
// test non-supporter on Rank Achieved filter
|
2021-06-22 05:53:21 +00:00
|
|
|
toggleRankFilter(Scoring.ScoreRank.XH);
|
|
|
|
supporterRequiredPlaceholderShown();
|
2021-06-20 09:17:07 +00:00
|
|
|
|
2021-06-22 05:53:21 +00:00
|
|
|
AddStep("Clear Rank Achieved filter", () => searchControl.Ranks.Clear());
|
|
|
|
noPlaceholderShown();
|
2021-06-20 09:17:07 +00:00
|
|
|
|
2021-06-20 10:28:43 +00:00
|
|
|
// test non-supporter on Played filter
|
2021-06-22 05:53:21 +00:00
|
|
|
toggleSupporterOnlyPlayedFilter(SearchPlayed.Played);
|
|
|
|
supporterRequiredPlaceholderShown();
|
2021-06-20 13:23:54 +00:00
|
|
|
|
2021-06-22 05:53:21 +00:00
|
|
|
AddStep("Set Played filter to Any", () => searchControl.Played.Value = SearchPlayed.Any);
|
|
|
|
noPlaceholderShown();
|
2021-06-20 10:28:43 +00:00
|
|
|
|
2021-06-20 13:23:54 +00:00
|
|
|
// test non-supporter on both Rank Achieved and Played filter
|
2021-06-22 05:53:21 +00:00
|
|
|
toggleRankFilter(Scoring.ScoreRank.XH);
|
|
|
|
toggleSupporterOnlyPlayedFilter(SearchPlayed.Played);
|
|
|
|
supporterRequiredPlaceholderShown();
|
2021-06-20 13:23:54 +00:00
|
|
|
|
2021-06-22 05:53:21 +00:00
|
|
|
AddStep("Clear Rank Achieved filter", () => searchControl.Ranks.Clear());
|
|
|
|
AddStep("Set Played filter to Any", () => searchControl.Played.Value = SearchPlayed.Any);
|
|
|
|
noPlaceholderShown();
|
|
|
|
}
|
2021-06-20 09:17:07 +00:00
|
|
|
|
2021-06-22 05:53:21 +00:00
|
|
|
[Test]
|
2021-06-26 17:27:34 +00:00
|
|
|
public void TestUserWithSupporterUsesSupporterOnlyFiltersWithResults()
|
2021-06-22 05:53:21 +00:00
|
|
|
{
|
|
|
|
AddStep("fetch for 1 beatmap", () => fetchFor(CreateBeatmap(Ruleset.Value).BeatmapInfo.BeatmapSet));
|
2021-06-20 10:28:43 +00:00
|
|
|
AddStep("set dummy as supporter", () => ((DummyAPIAccess)API).LocalUser.Value.IsSupporter = true);
|
2021-06-20 09:17:07 +00:00
|
|
|
|
2021-06-20 10:28:43 +00:00
|
|
|
// test supporter on Rank Achieved filter
|
2021-06-22 05:53:21 +00:00
|
|
|
toggleRankFilter(Scoring.ScoreRank.XH);
|
|
|
|
noPlaceholderShown();
|
2021-06-20 09:17:07 +00:00
|
|
|
|
2021-06-22 05:53:21 +00:00
|
|
|
AddStep("Clear Rank Achieved filter", () => searchControl.Ranks.Clear());
|
|
|
|
noPlaceholderShown();
|
2021-06-20 10:28:43 +00:00
|
|
|
|
|
|
|
// test supporter on Played filter
|
2021-06-22 05:53:21 +00:00
|
|
|
toggleSupporterOnlyPlayedFilter(SearchPlayed.Played);
|
|
|
|
noPlaceholderShown();
|
2021-06-20 10:28:43 +00:00
|
|
|
|
2021-06-22 05:53:21 +00:00
|
|
|
AddStep("Set Played filter to Any", () => searchControl.Played.Value = SearchPlayed.Any);
|
|
|
|
noPlaceholderShown();
|
2021-06-20 13:23:54 +00:00
|
|
|
|
|
|
|
// test supporter on both Rank Achieved and Played filter
|
2021-06-22 05:53:21 +00:00
|
|
|
toggleRankFilter(Scoring.ScoreRank.XH);
|
|
|
|
toggleSupporterOnlyPlayedFilter(SearchPlayed.Played);
|
|
|
|
noPlaceholderShown();
|
2021-06-20 13:23:54 +00:00
|
|
|
|
2021-06-22 05:53:21 +00:00
|
|
|
AddStep("Set Played filter to Any", () => searchControl.Played.Value = SearchPlayed.Any);
|
|
|
|
AddStep("Clear Rank Achieved filter", () => searchControl.Ranks.Clear());
|
|
|
|
noPlaceholderShown();
|
2021-06-20 09:17:07 +00:00
|
|
|
}
|
|
|
|
|
2021-01-25 20:41:05 +00:00
|
|
|
private void fetchFor(params BeatmapSetInfo[] beatmaps)
|
|
|
|
{
|
|
|
|
setsForResponse.Clear();
|
|
|
|
setsForResponse.AddRange(beatmaps.Select(b => new TestAPIBeatmapSet(b)));
|
|
|
|
|
|
|
|
// trigger arbitrary change for fetching.
|
2021-06-22 05:53:21 +00:00
|
|
|
searchControl.Query.TriggerChange();
|
2021-01-25 20:41:05 +00:00
|
|
|
}
|
|
|
|
|
2021-06-22 05:53:21 +00:00
|
|
|
private void toggleRankFilter(Scoring.ScoreRank rank)
|
2021-06-20 10:28:43 +00:00
|
|
|
{
|
2021-06-22 05:53:21 +00:00
|
|
|
AddStep("toggle Rank Achieved filter", () =>
|
2021-06-20 10:28:43 +00:00
|
|
|
{
|
2021-06-22 05:53:21 +00:00
|
|
|
searchControl.Ranks.Clear();
|
|
|
|
searchControl.Ranks.Add(rank);
|
2021-06-20 10:28:43 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-06-22 05:53:21 +00:00
|
|
|
private void toggleSupporterOnlyPlayedFilter(SearchPlayed played)
|
2021-06-20 10:28:43 +00:00
|
|
|
{
|
2021-06-22 05:53:21 +00:00
|
|
|
AddStep("toggle Played filter", () => searchControl.Played.Value = played);
|
2021-06-20 10:28:43 +00:00
|
|
|
}
|
|
|
|
|
2021-06-22 05:53:21 +00:00
|
|
|
private void supporterRequiredPlaceholderShown()
|
2021-06-20 13:23:54 +00:00
|
|
|
{
|
2021-06-22 05:53:21 +00:00
|
|
|
AddUntilStep("supporter-placeholder shown", () => overlay.ChildrenOfType<BeatmapListingOverlay.SupporterRequiredDrawable>().SingleOrDefault()?.IsPresent == true);
|
|
|
|
}
|
2021-06-20 13:23:54 +00:00
|
|
|
|
2021-06-22 05:53:21 +00:00
|
|
|
private void notFoundPlaceholderShown()
|
|
|
|
{
|
|
|
|
AddUntilStep("not-found-placeholder shown", () => overlay.ChildrenOfType<BeatmapListingOverlay.NotFoundDrawable>().SingleOrDefault()?.IsPresent == true);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void noPlaceholderShown()
|
|
|
|
{
|
|
|
|
AddUntilStep("no placeholder shown", () => !overlay.ChildrenOfType<BeatmapListingOverlay.SupporterRequiredDrawable>().Any() && !overlay.ChildrenOfType<BeatmapListingOverlay.NotFoundDrawable>().Any());
|
2021-06-20 13:23:54 +00:00
|
|
|
}
|
|
|
|
|
2021-01-25 20:41:05 +00:00
|
|
|
private class TestAPIBeatmapSet : APIBeatmapSet
|
|
|
|
{
|
|
|
|
private readonly BeatmapSetInfo beatmapSet;
|
|
|
|
|
|
|
|
public TestAPIBeatmapSet(BeatmapSetInfo beatmapSet)
|
|
|
|
{
|
|
|
|
this.beatmapSet = beatmapSet;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override BeatmapSetInfo ToBeatmapSet(RulesetStore rulesets) => beatmapSet;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|