2019-06-27 10:40:22 +08:00
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
2019-01-24 16:43:03 +08:00
// 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 ;
2018-04-18 15:04:02 +08:00
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 ;
2023-01-12 11:04:55 +08:00
using osu.Game.Online.API ;
using osu.Game.Online.API.Requests ;
2021-10-20 17:43:48 +08:00
using osu.Game.Online.API.Requests.Responses ;
2022-05-27 10:46:42 +08:00
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 ;
2021-11-04 17:02:44 +08:00
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
{
2019-05-15 03:37:25 +08:00
public partial class TestSceneBeatmapSetOverlay : OsuTestScene
2017-09-13 10:41:10 +08:00
{
2019-06-27 03:42:34 +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 ;
2019-05-15 03:37:25 +08:00
public TestSceneBeatmapSetOverlay ( )
2017-09-13 10:41:10 +08:00
{
2019-06-27 03:42:34 +08:00
Add ( overlay = new TestBeatmapSetOverlay ( ) ) ;
2017-09-13 10:41:10 +08:00
}
2018-04-13 17:19:50 +08:00
2019-10-04 22:57:39 +08:00
[Resolved]
2021-12-03 17:14:44 +08:00
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 > ( ) ) ;
2019-06-13 17:14:57 +08:00
[Test]
public void TestLoading ( )
{
2018-04-18 15:04:02 +08:00
AddStep ( @"show loading" , ( ) = > overlay . ShowBeatmapSet ( null ) ) ;
2019-06-13 17:14:57 +08:00
}
2018-04-18 15:04:02 +08:00
2019-06-13 17:14:57 +08:00
[Test]
public void TestLocalBeatmaps ( )
{
2017-09-13 10:41:10 +08:00
AddStep ( @"show first" , ( ) = >
{
2021-10-29 16:58:46 +08:00
overlay . ShowBeatmapSet ( new APIBeatmapSet
2017-09-13 10:41:10 +08:00
{
2022-12-22 03:02:04 +08:00
Genre = new BeatmapSetOnlineGenre { Id = 15 , Name = "Future genre" } ,
Language = new BeatmapSetOnlineLanguage { Id = 15 , Name = "Future language" } ,
2021-10-29 16:58:46 +08:00
OnlineID = 1235 ,
Title = @"an awesome beatmap" ,
Artist = @"naru narusegawa" ,
Source = @"hinata sou" ,
Tags = @"test tag tag more tag" ,
2021-11-04 17:02:44 +08:00
Author = new APIUser
2017-09-13 10:41:10 +08:00
{
2021-10-29 16:58:46 +08:00
Username = @"BanchoBot" ,
Id = 3 ,
2017-09-13 10:41:10 +08:00
} ,
2021-10-29 16:58:46 +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 ( ) ,
2021-11-04 15:44:05 +08:00
Beatmaps = new [ ]
2017-09-13 10:41:10 +08:00
{
2021-10-29 16:58:46 +08:00
new APIBeatmap
2017-09-13 10:41:10 +08:00
{
2021-10-29 16:58:46 +08:00
StarRating = 9.99 ,
DifficultyName = @"TEST" ,
2019-07-08 01:25:36 +08:00
Length = 456000 ,
2021-10-29 16:58:46 +08:00
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
{
2021-10-29 16:58:46 +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
} ,
} ,
} ,
2019-06-27 11:00:31 +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 ) ;
2019-08-23 23:31:53 +08:00
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 ) ;
2022-05-27 10:46:42 +08:00
AddAssert ( "scores container is visible" , ( ) = > overlay . ChildrenOfType < ScoresContainer > ( ) . Single ( ) . Alpha = = 1 ) ;
2022-06-09 03:10:02 +08:00
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 ) ;
2022-05-27 10:46:42 +08:00
AddAssert ( "scores container is hidden" , ( ) = > overlay . ChildrenOfType < ScoresContainer > ( ) . Single ( ) . Alpha = = 0 ) ;
2019-06-26 10:01:29 +08:00
}
2019-06-19 08:37:08 +08:00
2019-06-26 10:01:29 +08:00
[Test]
2019-06-27 12:48:57 +08:00
public void TestAvailability ( )
2019-06-26 10:01:29 +08:00
{
AddStep ( @"show undownloadable" , ( ) = >
2017-09-13 10:41:10 +08:00
{
2021-10-29 16:58:46 +08:00
var set = getBeatmapSet ( ) ;
set . Availability = new BeatmapSetOnlineAvailability
2017-09-13 10:41:10 +08:00
{
2021-10-29 16:58:46 +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
2019-06-25 08:21:55 +08:00
downloadAssert ( false ) ;
2019-06-13 17:14:57 +08:00
}
2019-06-13 01:42:52 +08:00
2019-10-04 22:57:39 +08:00
[Test]
public void TestMultipleRulesets ( )
{
AddStep ( "show multiple rulesets beatmap" , ( ) = >
{
2021-10-29 16:58:46 +08:00
var beatmaps = new List < APIBeatmap > ( ) ;
2019-10-04 22:57:39 +08:00
foreach ( var ruleset in rulesets . AvailableRulesets . Skip ( 1 ) )
{
2021-10-29 16:58:46 +08:00
beatmaps . Add ( new APIBeatmap
2019-10-04 22:57:39 +08:00
{
2021-10-29 16:58:46 +08:00
DifficultyName = ruleset . Name ,
RulesetID = ruleset . OnlineID ,
FailTimes = new APIFailTimes
2019-10-04 22:57:39 +08:00
{
2021-10-29 16:58:46 +08:00
Fails = Enumerable . Range ( 1 , 100 ) . Select ( i = > i % 12 - 6 ) . ToArray ( ) ,
Retries = Enumerable . Range ( - 2 , 100 ) . Select ( i = > i % 12 - 6 ) . ToArray ( ) ,
} ,
2019-10-04 22:57:39 +08:00
} ) ;
}
2021-10-29 16:58:46 +08:00
var set = getBeatmapSet ( ) ;
2021-11-04 15:44:05 +08:00
set . Beatmaps = beatmaps . ToArray ( ) ;
2021-10-29 16:58:46 +08:00
overlay . ShowBeatmapSet ( set ) ;
2019-10-04 22:57:39 +08:00
} ) ;
2021-10-29 16:58:46 +08:00
AddAssert ( "shown beatmaps of current ruleset" , ( ) = > overlay . Header . HeaderContent . Picker . Difficulties . All ( b = > b . Beatmap . Ruleset . OnlineID = = overlay . Header . RulesetSelector . Current . Value . OnlineID ) ) ;
2021-01-20 09:56:46 +08:00
AddAssert ( "left-most beatmap selected" , ( ) = > overlay . Header . HeaderContent . Picker . Difficulties . First ( ) . State = = BeatmapPicker . DifficultySelectorState . Selected ) ;
2019-10-04 22:57:39 +08:00
}
2021-01-13 16:57:29 +08:00
[Test]
public void TestExplicitBeatmap ( )
{
AddStep ( "show explicit map" , ( ) = >
{
2021-09-09 11:39:40 +08:00
var beatmapSet = getBeatmapSet ( ) ;
2021-10-29 16:58:46 +08:00
beatmapSet . HasExplicitContent = true ;
2021-01-13 16:57:29 +08:00
overlay . ShowBeatmapSet ( beatmapSet ) ;
} ) ;
}
2022-05-15 00:46:13 +08:00
[Test]
public void TestSpotlightBeatmap ( )
{
AddStep ( "show spotlight map" , ( ) = >
{
var beatmapSet = getBeatmapSet ( ) ;
beatmapSet . FeaturedInSpotlight = true ;
overlay . ShowBeatmapSet ( beatmapSet ) ;
} ) ;
}
2021-09-08 12:27:45 +08:00
[Test]
public void TestFeaturedBeatmap ( )
{
AddStep ( "show featured map" , ( ) = >
{
2021-09-09 11:39:40 +08:00
var beatmapSet = getBeatmapSet ( ) ;
2021-10-29 16:58:46 +08:00
beatmapSet . TrackId = 1 ;
2021-09-08 12:27:45 +08:00
overlay . ShowBeatmapSet ( beatmapSet ) ;
} ) ;
}
2022-05-15 00:46:13 +08:00
[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 ) ) ;
}
2019-06-13 17:14:57 +08:00
[Test]
public void TestHide ( )
{
2017-09-13 10:41:10 +08:00
AddStep ( @"hide" , overlay . Hide ) ;
2019-06-13 17:14:57 +08:00
}
[Test]
public void TestShowWithNoReload ( )
{
2017-09-13 10:41:10 +08:00
AddStep ( @"show without reload" , overlay . Show ) ;
}
2019-06-25 08:21:55 +08:00
2023-01-12 11:04:55 +08:00
[TestCase(BeatmapSetLookupType.BeatmapId)]
[TestCase(BeatmapSetLookupType.SetId)]
public void TestFetchLookupType ( BeatmapSetLookupType lookupType )
{
string type = string . Empty ;
AddStep ( "register request handling" , ( ) = >
{
( ( DummyAPIAccess ) API ) . HandleRequest = req = >
{
switch ( req )
{
case GetBeatmapSetRequest getBeatmapSet :
type = getBeatmapSet . Type . ToString ( ) ;
return true ;
}
return false ;
} ;
} ) ;
AddStep ( @"fetch" , ( ) = >
{
switch ( lookupType )
{
case BeatmapSetLookupType . BeatmapId :
overlay . FetchAndShowBeatmap ( 55 ) ;
break ;
case BeatmapSetLookupType . SetId :
overlay . FetchAndShowBeatmapSet ( 55 ) ;
break ;
}
} ) ;
AddAssert ( @"type is correct" , ( ) = > type = = lookupType . ToString ( ) ) ;
}
2021-10-29 16:58:46 +08:00
private APIBeatmapSet createManyDifficultiesBeatmapSet ( )
2019-08-23 23:31:53 +08:00
{
2021-10-29 16:58:46 +08:00
var set = getBeatmapSet ( ) ;
var beatmaps = new List < APIBeatmap > ( ) ;
2019-08-23 23:31:53 +08:00
for ( int i = 1 ; i < 41 ; i + + )
{
2021-10-29 16:58:46 +08:00
beatmaps . Add ( new APIBeatmap
2019-08-23 23:31:53 +08:00
{
2021-10-29 16:58:46 +08:00
OnlineID = i * 10 ,
DifficultyName = $"Test #{i}" ,
2021-11-22 13:26:24 +08:00
RulesetID = Ruleset . Value . OnlineID ,
2021-10-29 16:58:46 +08:00
StarRating = 2 + i * 0.1 ,
OverallDifficulty = 3.5f ,
FailTimes = new APIFailTimes
2019-08-23 23:31:53 +08:00
{
2021-10-29 16:58:46 +08:00
Fails = Enumerable . Range ( 1 , 100 ) . Select ( j = > j % 12 - 6 ) . ToArray ( ) ,
Retries = Enumerable . Range ( - 2 , 100 ) . Select ( j = > j % 12 - 6 ) . ToArray ( ) ,
2019-08-23 23:31:53 +08:00
} ,
2022-05-27 08:39:29 +08:00
Status = i % 2 = = 0 ? BeatmapOnlineStatus . Graveyard : BeatmapOnlineStatus . Loved ,
2019-08-23 23:31:53 +08:00
} ) ;
}
2021-11-04 15:44:05 +08:00
set . Beatmaps = beatmaps . ToArray ( ) ;
2021-10-29 16:58:46 +08:00
return set ;
2019-08-23 23:31:53 +08:00
}
2021-10-29 16:58:46 +08:00
private APIBeatmapSet getBeatmapSet ( )
2021-09-09 11:39:40 +08:00
{
2021-10-29 16:58:46 +08:00
var beatmapSet = CreateAPIBeatmapSet ( Ruleset . Value ) ;
2021-09-09 18:36:47 +08:00
// Make sure the overlay is reloaded (see `BeatmapSetInfo.Equals`).
2021-10-29 16:58:46 +08:00
beatmapSet . OnlineID = nextBeatmapSetId + + ;
2021-09-09 11:39:40 +08:00
return beatmapSet ;
}
2019-06-25 08:21:55 +08:00
private void downloadAssert ( bool shown )
{
2021-01-20 09:56:46 +08:00
AddAssert ( $"is download button {(shown ? " shown " : " hidden ")}" , ( ) = > overlay . Header . HeaderContent . DownloadButtonsVisible = = shown ) ;
2019-06-27 03:42:34 +08:00
}
private partial class TestBeatmapSetOverlay : BeatmapSetOverlay
{
2021-01-19 06:34:37 +08:00
public new BeatmapSetHeader Header = > base . Header ;
2019-06-25 08:21:55 +08:00
}
2017-09-13 10:41:10 +08:00
}
}