1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-06 07:42:55 +08:00

Rewrite test helpers to also handle clearing filters

This commit is contained in:
Bartłomiej Dach 2021-06-26 20:24:12 +02:00
parent 51888d0d5a
commit b7c4fe2052

View File

@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using NUnit.Framework; using NUnit.Framework;
@ -14,6 +15,7 @@ using osu.Game.Online.API.Requests.Responses;
using osu.Game.Overlays; using osu.Game.Overlays;
using osu.Game.Overlays.BeatmapListing; using osu.Game.Overlays.BeatmapListing;
using osu.Game.Rulesets; using osu.Game.Rulesets;
using osu.Game.Scoring;
using osu.Game.Users; using osu.Game.Users;
namespace osu.Game.Tests.Visual.Online namespace osu.Game.Tests.Visual.Online
@ -77,27 +79,27 @@ namespace osu.Game.Tests.Visual.Online
AddStep("fetch for 0 beatmaps", () => fetchFor()); AddStep("fetch for 0 beatmaps", () => fetchFor());
AddStep("set dummy as non-supporter", () => ((DummyAPIAccess)API).LocalUser.Value.IsSupporter = false); AddStep("set dummy as non-supporter", () => ((DummyAPIAccess)API).LocalUser.Value.IsSupporter = false);
// test non-supporter on Rank Achieved filter // only Rank Achieved filter
toggleRankFilter(Scoring.ScoreRank.XH); setRankAchievedFilter(new[] { ScoreRank.XH });
supporterRequiredPlaceholderShown(); supporterRequiredPlaceholderShown();
AddStep("Clear Rank Achieved filter", () => searchControl.Ranks.Clear()); setRankAchievedFilter(Array.Empty<ScoreRank>());
notFoundPlaceholderShown(); notFoundPlaceholderShown();
// test non-supporter on Played filter // only Played filter
toggleSupporterOnlyPlayedFilter(SearchPlayed.Played); setPlayedFilter(SearchPlayed.Played);
supporterRequiredPlaceholderShown(); supporterRequiredPlaceholderShown();
AddStep("Set Played filter to Any", () => searchControl.Played.Value = SearchPlayed.Any); setPlayedFilter(SearchPlayed.Any);
notFoundPlaceholderShown(); notFoundPlaceholderShown();
// test non-supporter on both Rank Achieved and Played filter // both RankAchieved and Played filters
toggleRankFilter(Scoring.ScoreRank.XH); setRankAchievedFilter(new[] { ScoreRank.XH });
toggleSupporterOnlyPlayedFilter(SearchPlayed.Played); setPlayedFilter(SearchPlayed.Played);
supporterRequiredPlaceholderShown(); supporterRequiredPlaceholderShown();
AddStep("Clear Rank Achieved filter", () => searchControl.Ranks.Clear()); setRankAchievedFilter(Array.Empty<ScoreRank>());
AddStep("Set Played filter to Any", () => searchControl.Played.Value = SearchPlayed.Any); setPlayedFilter(SearchPlayed.Any);
notFoundPlaceholderShown(); notFoundPlaceholderShown();
} }
@ -107,27 +109,27 @@ namespace osu.Game.Tests.Visual.Online
AddStep("fetch for 0 beatmaps", () => fetchFor()); AddStep("fetch for 0 beatmaps", () => fetchFor());
AddStep("set dummy as supporter", () => ((DummyAPIAccess)API).LocalUser.Value.IsSupporter = true); AddStep("set dummy as supporter", () => ((DummyAPIAccess)API).LocalUser.Value.IsSupporter = true);
// test supporter on Rank Achieved filter // only Rank Achieved filter
toggleRankFilter(Scoring.ScoreRank.XH); setRankAchievedFilter(new[] { ScoreRank.XH });
notFoundPlaceholderShown(); notFoundPlaceholderShown();
AddStep("Clear Rank Achieved filter", () => searchControl.Ranks.Clear()); setRankAchievedFilter(Array.Empty<ScoreRank>());
notFoundPlaceholderShown(); notFoundPlaceholderShown();
// test supporter on Played filter // only Played filter
toggleSupporterOnlyPlayedFilter(SearchPlayed.Played); setPlayedFilter(SearchPlayed.Played);
notFoundPlaceholderShown(); notFoundPlaceholderShown();
AddStep("Set Played filter to Any", () => searchControl.Played.Value = SearchPlayed.Any); setPlayedFilter(SearchPlayed.Any);
notFoundPlaceholderShown(); notFoundPlaceholderShown();
// test supporter on both Rank Achieved and Played filter // both Rank Achieved and Played filters
toggleRankFilter(Scoring.ScoreRank.XH); setRankAchievedFilter(new[] { ScoreRank.XH });
toggleSupporterOnlyPlayedFilter(SearchPlayed.Played); setPlayedFilter(SearchPlayed.Played);
notFoundPlaceholderShown(); notFoundPlaceholderShown();
AddStep("Clear Rank Achieved filter", () => searchControl.Ranks.Clear()); setRankAchievedFilter(Array.Empty<ScoreRank>());
AddStep("Set Played filter to Any", () => searchControl.Played.Value = SearchPlayed.Any); setPlayedFilter(SearchPlayed.Any);
notFoundPlaceholderShown(); notFoundPlaceholderShown();
} }
@ -137,27 +139,27 @@ namespace osu.Game.Tests.Visual.Online
AddStep("fetch for 1 beatmap", () => fetchFor(CreateBeatmap(Ruleset.Value).BeatmapInfo.BeatmapSet)); AddStep("fetch for 1 beatmap", () => fetchFor(CreateBeatmap(Ruleset.Value).BeatmapInfo.BeatmapSet));
AddStep("set dummy as non-supporter", () => ((DummyAPIAccess)API).LocalUser.Value.IsSupporter = false); AddStep("set dummy as non-supporter", () => ((DummyAPIAccess)API).LocalUser.Value.IsSupporter = false);
// test non-supporter on Rank Achieved filter // only Rank Achieved filter
toggleRankFilter(Scoring.ScoreRank.XH); setRankAchievedFilter(new[] { ScoreRank.XH });
supporterRequiredPlaceholderShown(); supporterRequiredPlaceholderShown();
AddStep("Clear Rank Achieved filter", () => searchControl.Ranks.Clear()); setRankAchievedFilter(Array.Empty<ScoreRank>());
noPlaceholderShown(); noPlaceholderShown();
// test non-supporter on Played filter // only Played filter
toggleSupporterOnlyPlayedFilter(SearchPlayed.Played); setPlayedFilter(SearchPlayed.Played);
supporterRequiredPlaceholderShown(); supporterRequiredPlaceholderShown();
AddStep("Set Played filter to Any", () => searchControl.Played.Value = SearchPlayed.Any); setPlayedFilter(SearchPlayed.Any);
noPlaceholderShown(); noPlaceholderShown();
// test non-supporter on both Rank Achieved and Played filter // both Rank Achieved and Played filters
toggleRankFilter(Scoring.ScoreRank.XH); setRankAchievedFilter(new[] { ScoreRank.XH });
toggleSupporterOnlyPlayedFilter(SearchPlayed.Played); setPlayedFilter(SearchPlayed.Played);
supporterRequiredPlaceholderShown(); supporterRequiredPlaceholderShown();
AddStep("Clear Rank Achieved filter", () => searchControl.Ranks.Clear()); setRankAchievedFilter(Array.Empty<ScoreRank>());
AddStep("Set Played filter to Any", () => searchControl.Played.Value = SearchPlayed.Any); setPlayedFilter(SearchPlayed.Any);
noPlaceholderShown(); noPlaceholderShown();
} }
@ -167,27 +169,27 @@ namespace osu.Game.Tests.Visual.Online
AddStep("fetch for 1 beatmap", () => fetchFor(CreateBeatmap(Ruleset.Value).BeatmapInfo.BeatmapSet)); AddStep("fetch for 1 beatmap", () => fetchFor(CreateBeatmap(Ruleset.Value).BeatmapInfo.BeatmapSet));
AddStep("set dummy as supporter", () => ((DummyAPIAccess)API).LocalUser.Value.IsSupporter = true); AddStep("set dummy as supporter", () => ((DummyAPIAccess)API).LocalUser.Value.IsSupporter = true);
// test supporter on Rank Achieved filter // only Rank Achieved filter
toggleRankFilter(Scoring.ScoreRank.XH); setRankAchievedFilter(new[] { ScoreRank.XH });
noPlaceholderShown(); noPlaceholderShown();
AddStep("Clear Rank Achieved filter", () => searchControl.Ranks.Clear()); setRankAchievedFilter(Array.Empty<ScoreRank>());
noPlaceholderShown(); noPlaceholderShown();
// test supporter on Played filter // only Played filter
toggleSupporterOnlyPlayedFilter(SearchPlayed.Played); setPlayedFilter(SearchPlayed.Played);
noPlaceholderShown(); noPlaceholderShown();
AddStep("Set Played filter to Any", () => searchControl.Played.Value = SearchPlayed.Any); setPlayedFilter(SearchPlayed.Any);
noPlaceholderShown(); noPlaceholderShown();
// test supporter on both Rank Achieved and Played filter // both Rank Achieved and Played filters
toggleRankFilter(Scoring.ScoreRank.XH); setRankAchievedFilter(new[] { ScoreRank.XH });
toggleSupporterOnlyPlayedFilter(SearchPlayed.Played); setPlayedFilter(SearchPlayed.Played);
noPlaceholderShown(); noPlaceholderShown();
AddStep("Set Played filter to Any", () => searchControl.Played.Value = SearchPlayed.Any); setRankAchievedFilter(Array.Empty<ScoreRank>());
AddStep("Clear Rank Achieved filter", () => searchControl.Ranks.Clear()); setPlayedFilter(SearchPlayed.Any);
noPlaceholderShown(); noPlaceholderShown();
} }
@ -200,18 +202,18 @@ namespace osu.Game.Tests.Visual.Online
searchControl.Query.TriggerChange(); searchControl.Query.TriggerChange();
} }
private void toggleRankFilter(Scoring.ScoreRank rank) private void setRankAchievedFilter(ScoreRank[] ranks)
{ {
AddStep("toggle Rank Achieved filter", () => AddStep($"set Rank Achieved filter to [{string.Join(',', ranks)}]", () =>
{ {
searchControl.Ranks.Clear(); searchControl.Ranks.Clear();
searchControl.Ranks.Add(rank); searchControl.Ranks.AddRange(ranks);
}); });
} }
private void toggleSupporterOnlyPlayedFilter(SearchPlayed played) private void setPlayedFilter(SearchPlayed played)
{ {
AddStep("toggle Played filter", () => searchControl.Played.Value = played); AddStep($"set Played filter to {played}", () => searchControl.Played.Value = played);
} }
private void supporterRequiredPlaceholderShown() private void supporterRequiredPlaceholderShown()