2021-01-26 04:41:05 +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.
2022-06-17 15:37:17 +08:00
#nullable disable
2021-06-27 02:24:12 +08:00
using System ;
2021-01-26 04:41:05 +08:00
using System.Collections.Generic ;
using System.Linq ;
using NUnit.Framework ;
2022-04-02 23:36:32 +08:00
using osu.Framework.Allocation ;
2021-01-26 04:41:05 +08:00
using osu.Framework.Graphics.Containers ;
using osu.Framework.Testing ;
2021-12-22 22:02:59 +08:00
using osu.Game.Beatmaps.Drawables.Cards ;
2022-04-02 23:36:32 +08:00
using osu.Game.Configuration ;
2022-01-20 05:02:01 +08:00
using osu.Game.Graphics.Containers ;
2021-09-10 00:57:33 +08:00
using osu.Game.Graphics.UserInterface ;
2021-01-26 04:41:05 +08:00
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 ;
2021-06-27 02:24:12 +08:00
using osu.Game.Scoring ;
2021-09-10 00:57:33 +08:00
using osuTK.Input ;
2021-11-04 17:02:44 +08:00
using APIUser = osu . Game . Online . API . Requests . Responses . APIUser ;
2021-01-26 04:41:05 +08:00
namespace osu.Game.Tests.Visual.Online
{
2022-11-24 13:32:20 +08:00
public partial class TestSceneBeatmapListingOverlay : OsuManualInputManagerTestScene
2021-01-26 04:41:05 +08:00
{
private readonly List < APIBeatmapSet > setsForResponse = new List < APIBeatmapSet > ( ) ;
private BeatmapListingOverlay overlay ;
2021-06-22 13:53:21 +08:00
private BeatmapListingSearchControl searchControl = > overlay . ChildrenOfType < BeatmapListingSearchControl > ( ) . Single ( ) ;
2022-04-02 23:36:32 +08:00
private OsuConfigManager localConfig ;
2022-09-13 06:37:23 +08:00
private bool returnCursorOnResponse ;
2022-04-02 23:36:32 +08:00
[BackgroundDependencyLoader]
private void load ( )
{
Dependencies . Cache ( localConfig = new OsuConfigManager ( LocalStorage ) ) ;
}
2021-09-10 00:57:33 +08:00
[SetUpSteps]
public void SetUpSteps ( )
2021-01-26 04:41:05 +08:00
{
2021-09-10 00:57:33 +08:00
AddStep ( "setup overlay" , ( ) = >
{
Child = overlay = new BeatmapListingOverlay { State = { Value = Visibility . Visible } } ;
setsForResponse . Clear ( ) ;
} ) ;
2021-01-26 04:41:05 +08:00
2021-09-10 00:57:33 +08:00
AddStep ( "initialize dummy" , ( ) = >
2021-01-26 04:41:05 +08:00
{
2021-09-10 00:57:33 +08:00
var api = ( DummyAPIAccess ) API ;
2021-03-23 17:08:32 +08:00
2021-09-10 00:57:33 +08:00
api . HandleRequest = req = >
2021-01-26 04:41:05 +08:00
{
2021-09-10 00:57:33 +08:00
if ( ! ( req is SearchBeatmapSetsRequest searchBeatmapSetsRequest ) ) return false ;
2021-03-23 17:08:32 +08:00
2021-09-10 00:57:33 +08:00
searchBeatmapSetsRequest . TriggerSuccess ( new SearchBeatmapSetsResponse
{
BeatmapSets = setsForResponse ,
2022-09-13 06:37:23 +08:00
Cursor = returnCursorOnResponse ? new Cursor ( ) : null ,
2021-09-10 00:57:33 +08:00
} ) ;
return true ;
} ;
2021-06-20 18:28:43 +08:00
// non-supporter user
2021-11-04 17:02:44 +08:00
api . LocalUser . Value = new APIUser
2021-06-20 18:28:43 +08:00
{
Username = "TestBot" ,
Id = API . LocalUser . Value . Id + 1 ,
} ;
} ) ;
2022-04-02 23:36:32 +08:00
AddStep ( "reset size" , ( ) = > localConfig . SetValue ( OsuSetting . BeatmapListingCardSize , BeatmapCardSize . Normal ) ) ;
2021-01-26 04:41:05 +08:00
}
2021-09-10 00:57:33 +08:00
[Test]
public void TestHideViaBack ( )
{
AddAssert ( "is visible" , ( ) = > overlay . State . Value = = Visibility . Visible ) ;
AddStep ( "hide" , ( ) = > InputManager . Key ( Key . Escape ) ) ;
AddUntilStep ( "is hidden" , ( ) = > overlay . State . Value = = Visibility . Hidden ) ;
}
[Test]
public void TestHideViaBackWithSearch ( )
{
AddAssert ( "is visible" , ( ) = > overlay . State . Value = = Visibility . Visible ) ;
AddStep ( "search something" , ( ) = > overlay . ChildrenOfType < SearchTextBox > ( ) . First ( ) . Text = "search" ) ;
AddStep ( "kill search" , ( ) = > InputManager . Key ( Key . Escape ) ) ;
AddAssert ( "search textbox empty" , ( ) = > string . IsNullOrEmpty ( overlay . ChildrenOfType < SearchTextBox > ( ) . First ( ) . Text ) ) ;
AddAssert ( "is visible" , ( ) = > overlay . State . Value = = Visibility . Visible ) ;
AddStep ( "hide" , ( ) = > InputManager . Key ( Key . Escape ) ) ;
AddUntilStep ( "is hidden" , ( ) = > overlay . State . Value = = Visibility . Hidden ) ;
}
[Test]
public void TestHideViaBackWithScrolledSearch ( )
{
AddAssert ( "is visible" , ( ) = > overlay . State . Value = = Visibility . Visible ) ;
2022-09-13 06:37:23 +08:00
AddStep ( "show many results" , ( ) = > fetchFor ( getManyBeatmaps ( 100 ) . ToArray ( ) ) ) ;
2021-09-10 00:57:33 +08:00
2021-09-10 03:33:02 +08:00
AddUntilStep ( "placeholder hidden" , ( ) = > ! overlay . ChildrenOfType < BeatmapListingOverlay . NotFoundDrawable > ( ) . Any ( d = > d . IsPresent ) ) ;
2021-09-10 00:57:33 +08:00
AddStep ( "scroll to bottom" , ( ) = > overlay . ChildrenOfType < OverlayScrollContainer > ( ) . First ( ) . ScrollToEnd ( ) ) ;
AddStep ( "kill search" , ( ) = > InputManager . Key ( Key . Escape ) ) ;
AddUntilStep ( "search textbox empty" , ( ) = > string . IsNullOrEmpty ( overlay . ChildrenOfType < SearchTextBox > ( ) . First ( ) . Text ) ) ;
AddUntilStep ( "is scrolled to top" , ( ) = > overlay . ChildrenOfType < OverlayScrollContainer > ( ) . First ( ) . Current = = 0 ) ;
AddAssert ( "is visible" , ( ) = > overlay . State . Value = = Visibility . Visible ) ;
AddStep ( "hide" , ( ) = > InputManager . Key ( Key . Escape ) ) ;
AddUntilStep ( "is hidden" , ( ) = > overlay . State . Value = = Visibility . Hidden ) ;
}
2022-01-04 02:27:46 +08:00
[Test]
public void TestCorrectOldContentExpiration ( )
{
AddAssert ( "is visible" , ( ) = > overlay . State . Value = = Visibility . Visible ) ;
2022-09-13 06:37:23 +08:00
AddStep ( "show many results" , ( ) = > fetchFor ( getManyBeatmaps ( 100 ) . ToArray ( ) ) ) ;
2022-01-04 02:27:46 +08:00
assertAllCardsOfType < BeatmapCardNormal > ( 100 ) ;
2022-09-13 06:37:23 +08:00
AddStep ( "show more results" , ( ) = > fetchFor ( getManyBeatmaps ( 30 ) . ToArray ( ) ) ) ;
2022-01-04 02:27:46 +08:00
assertAllCardsOfType < BeatmapCardNormal > ( 30 ) ;
}
2022-04-03 00:24:16 +08:00
[Test]
public void TestCardSizeSwitching ( [ Values ] bool viaConfig )
2021-12-22 21:27:11 +08:00
{
AddAssert ( "is visible" , ( ) = > overlay . State . Value = = Visibility . Visible ) ;
2022-09-13 06:37:23 +08:00
AddStep ( "show many results" , ( ) = > fetchFor ( getManyBeatmaps ( 100 ) . ToArray ( ) ) ) ;
2022-01-04 02:27:46 +08:00
assertAllCardsOfType < BeatmapCardNormal > ( 100 ) ;
2021-12-22 21:27:11 +08:00
2022-04-02 23:36:32 +08:00
setCardSize ( BeatmapCardSize . Extra , viaConfig ) ;
2022-01-04 02:27:46 +08:00
assertAllCardsOfType < BeatmapCardExtra > ( 100 ) ;
2021-12-22 21:27:11 +08:00
2022-04-02 23:36:32 +08:00
setCardSize ( BeatmapCardSize . Normal , viaConfig ) ;
2022-01-04 02:27:46 +08:00
assertAllCardsOfType < BeatmapCardNormal > ( 100 ) ;
2021-12-22 21:27:11 +08:00
AddStep ( "fetch for 0 beatmaps" , ( ) = > fetchFor ( ) ) ;
AddUntilStep ( "placeholder shown" , ( ) = > overlay . ChildrenOfType < BeatmapListingOverlay . NotFoundDrawable > ( ) . SingleOrDefault ( ) ? . IsPresent = = true ) ;
2022-04-02 23:36:32 +08:00
setCardSize ( BeatmapCardSize . Extra , viaConfig ) ;
2021-12-22 21:27:11 +08:00
AddAssert ( "placeholder shown" , ( ) = > overlay . ChildrenOfType < BeatmapListingOverlay . NotFoundDrawable > ( ) . SingleOrDefault ( ) ? . IsPresent = = true ) ;
}
2021-01-26 04:41:05 +08:00
[Test]
public void TestNoBeatmapsPlaceholder ( )
{
AddStep ( "fetch for 0 beatmaps" , ( ) = > fetchFor ( ) ) ;
2021-12-22 22:02:59 +08:00
placeholderShown ( ) ;
2021-01-26 04:41:05 +08:00
2022-09-13 06:37:23 +08:00
AddStep ( "show many results" , ( ) = > fetchFor ( getManyBeatmaps ( 100 ) . ToArray ( ) ) ) ;
2021-12-22 22:02:59 +08:00
AddUntilStep ( "wait for loaded" , ( ) = > this . ChildrenOfType < BeatmapCard > ( ) . Count ( ) = = 100 ) ;
2021-09-10 03:33:02 +08:00
AddUntilStep ( "placeholder hidden" , ( ) = > ! overlay . ChildrenOfType < BeatmapListingOverlay . NotFoundDrawable > ( ) . Any ( d = > d . IsPresent ) ) ;
2021-01-26 04:41:05 +08:00
AddStep ( "fetch for 0 beatmaps" , ( ) = > fetchFor ( ) ) ;
2021-12-22 22:02:59 +08:00
placeholderShown ( ) ;
2021-01-26 04:41:05 +08:00
// fetch once more to ensure nothing happens in displaying placeholder again when it already is present.
AddStep ( "fetch for 0 beatmaps again" , ( ) = > fetchFor ( ) ) ;
2021-12-22 22:02:59 +08:00
placeholderShown ( ) ;
void placeholderShown ( ) = >
AddUntilStep ( "placeholder shown" , ( ) = >
{
var notFoundDrawable = overlay . ChildrenOfType < BeatmapListingOverlay . NotFoundDrawable > ( ) . SingleOrDefault ( ) ;
return notFoundDrawable ! = null & & notFoundDrawable . IsPresent & & notFoundDrawable . Parent . DrawHeight > 0 ;
} ) ;
2021-01-26 04:41:05 +08:00
}
2022-09-13 06:37:23 +08:00
/// <summary>
/// During pagination, the first beatmap of the second page may be a duplicate of the last beatmap from the previous page.
/// This is currently the case with osu!web API due to ES relevance score's presence in the response cursor.
/// See: https://github.com/ppy/osu-web/issues/9270
/// </summary>
[Test]
public void TestDuplicatedBeatmapOnlyShowsOnce ( )
{
APIBeatmapSet beatmapSet = null ;
AddStep ( "show many results" , ( ) = >
{
beatmapSet = CreateAPIBeatmapSet ( Ruleset . Value ) ;
beatmapSet . Title = "last beatmap of first page" ;
2022-11-04 08:20:24 +08:00
fetchFor ( getManyBeatmaps ( 49 ) . Append ( new APIBeatmapSet { Title = "last beatmap of first page" , OnlineID = beatmapSet . OnlineID } ) . ToArray ( ) , true ) ;
2022-09-13 06:37:23 +08:00
} ) ;
AddUntilStep ( "wait for loaded" , ( ) = > this . ChildrenOfType < BeatmapCard > ( ) . Count ( ) = = 50 ) ;
2022-11-04 08:20:24 +08:00
AddStep ( "set next page" , ( ) = > setSearchResponse ( getManyBeatmaps ( 49 ) . Prepend ( new APIBeatmapSet { Title = "this shouldn't show up" , OnlineID = beatmapSet . OnlineID } ) . ToArray ( ) , false ) ) ;
2022-09-13 06:37:23 +08:00
AddStep ( "scroll to end" , ( ) = > overlay . ChildrenOfType < OverlayScrollContainer > ( ) . Single ( ) . ScrollToEnd ( ) ) ;
2022-11-04 08:20:24 +08:00
AddUntilStep ( "wait for loaded" , ( ) = > this . ChildrenOfType < BeatmapCard > ( ) . Count ( ) > = 99 ) ;
2022-09-13 06:37:23 +08:00
AddAssert ( "beatmap not duplicated" , ( ) = > overlay . ChildrenOfType < BeatmapCard > ( ) . Count ( c = > c . BeatmapSet . Equals ( beatmapSet ) ) = = 1 ) ;
}
2021-06-20 17:17:07 +08:00
[Test]
2021-06-27 01:27:34 +08:00
public void TestUserWithoutSupporterUsesSupporterOnlyFiltersWithoutResults ( )
2021-06-20 18:28:43 +08:00
{
2021-06-20 21:23:54 +08:00
AddStep ( "fetch for 0 beatmaps" , ( ) = > fetchFor ( ) ) ;
2021-12-21 13:10:38 +08:00
2021-06-20 18:28:43 +08:00
AddStep ( "set dummy as non-supporter" , ( ) = > ( ( DummyAPIAccess ) API ) . LocalUser . Value . IsSupporter = false ) ;
2021-06-20 17:17:07 +08:00
2021-06-27 02:24:12 +08:00
// only Rank Achieved filter
setRankAchievedFilter ( new [ ] { ScoreRank . XH } ) ;
2021-06-22 13:53:21 +08:00
supporterRequiredPlaceholderShown ( ) ;
2021-06-20 17:17:07 +08:00
2021-06-27 02:24:12 +08:00
setRankAchievedFilter ( Array . Empty < ScoreRank > ( ) ) ;
2021-06-22 13:53:21 +08:00
notFoundPlaceholderShown ( ) ;
2021-06-20 17:17:07 +08:00
2021-06-27 02:24:12 +08:00
// only Played filter
setPlayedFilter ( SearchPlayed . Played ) ;
2021-06-22 13:53:21 +08:00
supporterRequiredPlaceholderShown ( ) ;
2021-06-20 21:23:54 +08:00
2021-06-27 02:24:12 +08:00
setPlayedFilter ( SearchPlayed . Any ) ;
2021-06-22 13:53:21 +08:00
notFoundPlaceholderShown ( ) ;
2021-06-20 21:23:54 +08:00
2021-06-27 02:24:12 +08:00
// both RankAchieved and Played filters
setRankAchievedFilter ( new [ ] { ScoreRank . XH } ) ;
setPlayedFilter ( SearchPlayed . Played ) ;
2021-06-22 13:53:21 +08:00
supporterRequiredPlaceholderShown ( ) ;
2021-06-20 17:17:07 +08:00
2021-06-27 02:24:12 +08:00
setRankAchievedFilter ( Array . Empty < ScoreRank > ( ) ) ;
setPlayedFilter ( SearchPlayed . Any ) ;
2021-06-22 13:53:21 +08:00
notFoundPlaceholderShown ( ) ;
}
2021-06-20 17:17:07 +08:00
2021-06-22 13:53:21 +08:00
[Test]
2021-06-27 01:27:34 +08:00
public void TestUserWithSupporterUsesSupporterOnlyFiltersWithoutResults ( )
2021-06-22 13:53:21 +08:00
{
AddStep ( "fetch for 0 beatmaps" , ( ) = > fetchFor ( ) ) ;
2021-06-20 18:28:43 +08:00
AddStep ( "set dummy as supporter" , ( ) = > ( ( DummyAPIAccess ) API ) . LocalUser . Value . IsSupporter = true ) ;
2021-06-20 17:17:07 +08:00
2021-06-27 02:24:12 +08:00
// only Rank Achieved filter
setRankAchievedFilter ( new [ ] { ScoreRank . XH } ) ;
2021-06-22 13:53:21 +08:00
notFoundPlaceholderShown ( ) ;
2021-06-20 17:17:07 +08:00
2021-06-27 02:24:12 +08:00
setRankAchievedFilter ( Array . Empty < ScoreRank > ( ) ) ;
2021-06-22 13:53:21 +08:00
notFoundPlaceholderShown ( ) ;
2021-06-20 17:17:07 +08:00
2021-06-27 02:24:12 +08:00
// only Played filter
setPlayedFilter ( SearchPlayed . Played ) ;
2021-06-22 13:53:21 +08:00
notFoundPlaceholderShown ( ) ;
2021-06-20 17:17:07 +08:00
2021-06-27 02:24:12 +08:00
setPlayedFilter ( SearchPlayed . Any ) ;
2021-06-22 13:53:21 +08:00
notFoundPlaceholderShown ( ) ;
2021-06-20 21:23:54 +08:00
2021-06-27 02:24:12 +08:00
// both Rank Achieved and Played filters
setRankAchievedFilter ( new [ ] { ScoreRank . XH } ) ;
setPlayedFilter ( SearchPlayed . Played ) ;
2021-06-22 13:53:21 +08:00
notFoundPlaceholderShown ( ) ;
2021-06-20 21:23:54 +08:00
2021-06-27 02:24:12 +08:00
setRankAchievedFilter ( Array . Empty < ScoreRank > ( ) ) ;
setPlayedFilter ( SearchPlayed . Any ) ;
2021-06-22 13:53:21 +08:00
notFoundPlaceholderShown ( ) ;
2021-06-20 18:28:43 +08:00
}
[Test]
2021-06-27 01:27:34 +08:00
public void TestUserWithoutSupporterUsesSupporterOnlyFiltersWithResults ( )
2021-06-20 18:28:43 +08:00
{
2021-10-25 12:47:12 +08:00
AddStep ( "fetch for 1 beatmap" , ( ) = > fetchFor ( CreateAPIBeatmapSet ( Ruleset . Value ) ) ) ;
2021-12-21 13:10:38 +08:00
noPlaceholderShown ( ) ;
2021-06-20 18:28:43 +08:00
AddStep ( "set dummy as non-supporter" , ( ) = > ( ( DummyAPIAccess ) API ) . LocalUser . Value . IsSupporter = false ) ;
2021-06-27 02:24:12 +08:00
// only Rank Achieved filter
setRankAchievedFilter ( new [ ] { ScoreRank . XH } ) ;
2021-06-22 13:53:21 +08:00
supporterRequiredPlaceholderShown ( ) ;
2021-06-20 17:17:07 +08:00
2021-06-27 02:24:12 +08:00
setRankAchievedFilter ( Array . Empty < ScoreRank > ( ) ) ;
2021-06-22 13:53:21 +08:00
noPlaceholderShown ( ) ;
2021-06-20 17:17:07 +08:00
2021-06-27 02:24:12 +08:00
// only Played filter
setPlayedFilter ( SearchPlayed . Played ) ;
2021-06-22 13:53:21 +08:00
supporterRequiredPlaceholderShown ( ) ;
2021-06-20 21:23:54 +08:00
2021-06-27 02:24:12 +08:00
setPlayedFilter ( SearchPlayed . Any ) ;
2021-06-22 13:53:21 +08:00
noPlaceholderShown ( ) ;
2021-06-20 18:28:43 +08:00
2021-06-27 02:24:12 +08:00
// both Rank Achieved and Played filters
setRankAchievedFilter ( new [ ] { ScoreRank . XH } ) ;
setPlayedFilter ( SearchPlayed . Played ) ;
2021-06-22 13:53:21 +08:00
supporterRequiredPlaceholderShown ( ) ;
2021-06-20 21:23:54 +08:00
2021-06-27 02:24:12 +08:00
setRankAchievedFilter ( Array . Empty < ScoreRank > ( ) ) ;
setPlayedFilter ( SearchPlayed . Any ) ;
2021-06-22 13:53:21 +08:00
noPlaceholderShown ( ) ;
}
2021-06-20 17:17:07 +08:00
2021-06-22 13:53:21 +08:00
[Test]
2021-06-27 01:27:34 +08:00
public void TestUserWithSupporterUsesSupporterOnlyFiltersWithResults ( )
2021-06-22 13:53:21 +08:00
{
2021-10-25 12:47:12 +08:00
AddStep ( "fetch for 1 beatmap" , ( ) = > fetchFor ( CreateAPIBeatmapSet ( Ruleset . Value ) ) ) ;
2021-12-21 13:10:38 +08:00
noPlaceholderShown ( ) ;
2021-06-20 18:28:43 +08:00
AddStep ( "set dummy as supporter" , ( ) = > ( ( DummyAPIAccess ) API ) . LocalUser . Value . IsSupporter = true ) ;
2021-06-20 17:17:07 +08:00
2021-06-27 02:24:12 +08:00
// only Rank Achieved filter
setRankAchievedFilter ( new [ ] { ScoreRank . XH } ) ;
2021-06-22 13:53:21 +08:00
noPlaceholderShown ( ) ;
2021-06-20 17:17:07 +08:00
2021-06-27 02:24:12 +08:00
setRankAchievedFilter ( Array . Empty < ScoreRank > ( ) ) ;
2021-06-22 13:53:21 +08:00
noPlaceholderShown ( ) ;
2021-06-20 18:28:43 +08:00
2021-06-27 02:24:12 +08:00
// only Played filter
setPlayedFilter ( SearchPlayed . Played ) ;
2021-06-22 13:53:21 +08:00
noPlaceholderShown ( ) ;
2021-06-20 18:28:43 +08:00
2021-06-27 02:24:12 +08:00
setPlayedFilter ( SearchPlayed . Any ) ;
2021-06-22 13:53:21 +08:00
noPlaceholderShown ( ) ;
2021-06-20 21:23:54 +08:00
2021-06-27 02:24:12 +08:00
// both Rank Achieved and Played filters
setRankAchievedFilter ( new [ ] { ScoreRank . XH } ) ;
setPlayedFilter ( SearchPlayed . Played ) ;
2021-06-22 13:53:21 +08:00
noPlaceholderShown ( ) ;
2021-06-20 21:23:54 +08:00
2021-06-27 02:24:12 +08:00
setRankAchievedFilter ( Array . Empty < ScoreRank > ( ) ) ;
setPlayedFilter ( SearchPlayed . Any ) ;
2021-06-22 13:53:21 +08:00
noPlaceholderShown ( ) ;
2021-06-20 17:17:07 +08:00
}
2022-01-20 05:02:01 +08:00
[Test]
public void TestExpandedCardContentNotClipped ( )
{
AddAssert ( "is visible" , ( ) = > overlay . State . Value = = Visibility . Visible ) ;
AddStep ( "show result with many difficulties" , ( ) = >
{
var beatmapSet = CreateAPIBeatmapSet ( Ruleset . Value ) ;
beatmapSet . Beatmaps = Enumerable . Repeat ( beatmapSet . Beatmaps . First ( ) , 100 ) . ToArray ( ) ;
fetchFor ( beatmapSet ) ;
} ) ;
assertAllCardsOfType < BeatmapCardNormal > ( 1 ) ;
AddStep ( "hover extra info row" , ( ) = >
{
var difficultyArea = this . ChildrenOfType < BeatmapCardExtraInfoRow > ( ) . Single ( ) ;
InputManager . MoveMouseTo ( difficultyArea ) ;
} ) ;
AddUntilStep ( "wait for expanded" , ( ) = > this . ChildrenOfType < BeatmapCardNormal > ( ) . Single ( ) . Expanded . Value ) ;
AddAssert ( "expanded content not clipped" , ( ) = >
{
var cardContainer = this . ChildrenOfType < ReverseChildIDFillFlowContainer < BeatmapCard > > ( ) . Single ( ) . Parent ;
var expandedContent = this . ChildrenOfType < ExpandedContentScrollContainer > ( ) . Single ( ) ;
return expandedContent . ScreenSpaceDrawQuad . GetVertices ( ) . ToArray ( ) . All ( v = > cardContainer . ScreenSpaceDrawQuad . Contains ( v ) ) ;
} ) ;
}
2021-09-10 00:57:33 +08:00
private static int searchCount ;
2022-09-13 06:37:23 +08:00
private APIBeatmapSet [ ] getManyBeatmaps ( int count ) = > Enumerable . Range ( 0 , count ) . Select ( _ = > CreateAPIBeatmapSet ( Ruleset . Value ) ) . ToArray ( ) ;
private void fetchFor ( params APIBeatmapSet [ ] beatmaps ) = > fetchFor ( beatmaps , false ) ;
private void fetchFor ( APIBeatmapSet [ ] beatmaps , bool hasNextPage )
2021-01-26 04:41:05 +08:00
{
2022-09-13 06:37:23 +08:00
setSearchResponse ( beatmaps , hasNextPage ) ;
2021-01-26 04:41:05 +08:00
// trigger arbitrary change for fetching.
2021-09-10 00:57:33 +08:00
searchControl . Query . Value = $"search {searchCount++}" ;
2021-01-26 04:41:05 +08:00
}
2022-09-13 06:37:23 +08:00
private void setSearchResponse ( APIBeatmapSet [ ] beatmaps , bool hasNextPage )
{
setsForResponse . Clear ( ) ;
setsForResponse . AddRange ( beatmaps ) ;
returnCursorOnResponse = hasNextPage ;
}
2021-06-27 02:24:12 +08:00
private void setRankAchievedFilter ( ScoreRank [ ] ranks )
2021-06-20 18:28:43 +08:00
{
2021-06-27 02:24:12 +08:00
AddStep ( $"set Rank Achieved filter to [{string.Join(',', ranks)}]" , ( ) = >
2021-06-20 18:28:43 +08:00
{
2021-06-22 13:53:21 +08:00
searchControl . Ranks . Clear ( ) ;
2021-06-27 02:24:12 +08:00
searchControl . Ranks . AddRange ( ranks ) ;
2021-06-20 18:28:43 +08:00
} ) ;
}
2021-06-27 02:24:12 +08:00
private void setPlayedFilter ( SearchPlayed played )
2021-06-20 18:28:43 +08:00
{
2021-06-27 02:24:12 +08:00
AddStep ( $"set Played filter to {played}" , ( ) = > searchControl . Played . Value = played ) ;
2021-06-20 18:28:43 +08:00
}
2021-06-22 13:53:21 +08:00
private void supporterRequiredPlaceholderShown ( )
2021-06-20 21:23:54 +08:00
{
2021-06-27 02:27:15 +08:00
AddUntilStep ( "\"supporter required\" placeholder shown" , ( ) = > overlay . ChildrenOfType < BeatmapListingOverlay . SupporterRequiredDrawable > ( ) . SingleOrDefault ( ) ? . IsPresent = = true ) ;
2021-06-22 13:53:21 +08:00
}
2021-06-20 21:23:54 +08:00
2021-06-22 13:53:21 +08:00
private void notFoundPlaceholderShown ( )
{
2021-06-27 02:27:15 +08:00
AddUntilStep ( "\"no maps found\" placeholder shown" , ( ) = > overlay . ChildrenOfType < BeatmapListingOverlay . NotFoundDrawable > ( ) . SingleOrDefault ( ) ? . IsPresent = = true ) ;
2021-06-22 13:53:21 +08:00
}
private void noPlaceholderShown ( )
{
2021-12-21 13:10:38 +08:00
AddUntilStep ( "\"supporter required\" placeholder not shown" , ( ) = > ! overlay . ChildrenOfType < BeatmapListingOverlay . SupporterRequiredDrawable > ( ) . Any ( d = > d . IsPresent ) ) ;
AddUntilStep ( "\"no maps found\" placeholder not shown" , ( ) = > ! overlay . ChildrenOfType < BeatmapListingOverlay . NotFoundDrawable > ( ) . Any ( d = > d . IsPresent ) ) ;
2021-06-20 21:23:54 +08:00
}
2021-12-22 21:27:11 +08:00
2022-04-02 23:36:32 +08:00
private void setCardSize ( BeatmapCardSize cardSize , bool viaConfig ) = > AddStep ( $"set card size to {cardSize}" , ( ) = >
{
2022-04-03 00:28:33 +08:00
if ( viaConfig )
2022-04-02 23:36:32 +08:00
localConfig . SetValue ( OsuSetting . BeatmapListingCardSize , cardSize ) ;
2022-04-03 00:28:33 +08:00
else
overlay . ChildrenOfType < BeatmapListingCardSizeTabControl > ( ) . Single ( ) . Current . Value = cardSize ;
2022-04-02 23:36:32 +08:00
} ) ;
2021-12-22 21:27:11 +08:00
2022-01-04 02:27:46 +08:00
private void assertAllCardsOfType < T > ( int expectedCount )
2021-12-22 21:27:11 +08:00
where T : BeatmapCard = >
AddUntilStep ( $"all loaded beatmap cards are {typeof(T)}" , ( ) = >
{
int loadedCorrectCount = this . ChildrenOfType < BeatmapCard > ( ) . Count ( card = > card . IsLoaded & & card . GetType ( ) = = typeof ( T ) ) ;
2022-01-04 02:27:46 +08:00
return loadedCorrectCount > 0 & & loadedCorrectCount = = expectedCount ;
2021-12-22 21:27:11 +08:00
} ) ;
2022-04-02 23:36:32 +08:00
protected override void Dispose ( bool isDisposing )
{
localConfig ? . Dispose ( ) ;
base . Dispose ( isDisposing ) ;
}
2021-01-26 04:41:05 +08:00
}
}