2025-02-06 22:25:45 +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.
using System ;
using System.Diagnostics ;
using System.Linq ;
2025-02-07 18:13:51 +08:00
using NUnit.Framework ;
2025-02-06 22:25:45 +08:00
using osu.Framework.Allocation ;
using osu.Framework.Audio ;
using osu.Framework.Graphics ;
using osu.Framework.Platform ;
using osu.Framework.Testing ;
using osu.Game.Beatmaps ;
2025-02-07 18:13:51 +08:00
using osu.Game.Collections ;
2025-02-06 22:25:45 +08:00
using osu.Game.Database ;
using osu.Game.Online.Rooms ;
using osu.Game.Overlays ;
using osu.Game.Rulesets ;
using osu.Game.Rulesets.Osu ;
using osu.Game.Screens.OnlinePlay.Playlists ;
using osuTK ;
2025-02-07 18:13:51 +08:00
using osuTK.Input ;
using SharpCompress ;
2025-02-06 22:25:45 +08:00
namespace osu.Game.Tests.Visual.Playlists
{
2025-02-07 18:13:51 +08:00
public partial class TestSceneAddPlaylistToCollectionButton : OsuManualInputManagerTestScene
2025-02-06 22:25:45 +08:00
{
private BeatmapManager manager = null ! ;
private BeatmapSetInfo importedBeatmap = null ! ;
private Room room = null ! ;
2025-02-07 18:13:51 +08:00
private AddPlaylistToCollectionButton button = null ! ;
2025-02-06 22:25:45 +08:00
[BackgroundDependencyLoader]
private void load ( GameHost host , AudioManager audio )
{
Dependencies . Cache ( new RealmRulesetStore ( Realm ) ) ;
Dependencies . Cache ( manager = new BeatmapManager ( LocalStorage , Realm , API , audio , Resources , host , Beatmap . Default ) ) ;
Dependencies . Cache ( Realm ) ;
2025-02-07 18:13:51 +08:00
Add ( notificationOverlay ) ;
2025-02-06 22:25:45 +08:00
}
[Cached(typeof(INotificationOverlay))]
private NotificationOverlay notificationOverlay = new NotificationOverlay
{
Anchor = Anchor . TopRight ,
Origin = Anchor . TopRight ,
} ;
[SetUpSteps]
public void SetUpSteps ( )
{
2025-02-07 18:13:51 +08:00
AddStep ( "clear realm" , ( ) = > Realm . Realm . Write ( ( ) = > Realm . Realm . RemoveAll < BeatmapCollection > ( ) ) ) ;
AddStep ( "clear notifications" , ( ) = > notificationOverlay . AllNotifications . Empty ( ) ) ;
2025-02-06 22:25:45 +08:00
importBeatmap ( ) ;
setupRoom ( ) ;
AddStep ( "create button" , ( ) = >
{
2025-02-07 18:13:51 +08:00
Add ( button = new AddPlaylistToCollectionButton ( room )
2025-02-06 22:25:45 +08:00
{
2025-02-07 18:13:51 +08:00
Anchor = Anchor . Centre ,
Origin = Anchor . Centre ,
Size = new Vector2 ( 300 , 40 ) ,
2025-02-06 22:25:45 +08:00
} ) ;
} ) ;
}
2025-02-07 18:13:51 +08:00
[Test]
public void TestButtonFlow ( )
{
AddStep ( "move mouse to button" , ( ) = > InputManager . MoveMouseTo ( button ) ) ;
AddStep ( "click button" , ( ) = > InputManager . Click ( MouseButton . Left ) ) ;
2025-02-14 13:58:04 +08:00
AddUntilStep ( "notification shown" , ( ) = > notificationOverlay . AllNotifications . Any ( n = > n . Text . ToString ( ) . StartsWith ( "Created new collection" , StringComparison . Ordinal ) ) ) ;
2025-02-07 18:13:51 +08:00
2025-02-14 13:58:04 +08:00
AddUntilStep ( "realm is updated" , ( ) = > Realm . Realm . All < BeatmapCollection > ( ) . FirstOrDefault ( c = > c . Name = = room . Name ) ! = null ) ;
2025-02-07 18:13:51 +08:00
}
2025-02-06 22:25:45 +08:00
private void importBeatmap ( ) = > AddStep ( "import beatmap" , ( ) = >
{
var beatmap = CreateBeatmap ( new OsuRuleset ( ) . RulesetInfo ) ;
Debug . Assert ( beatmap . BeatmapInfo . BeatmapSet ! = null ) ;
importedBeatmap = manager . Import ( beatmap . BeatmapInfo . BeatmapSet ) ! . Value . Detach ( ) ;
} ) ;
private void setupRoom ( ) = > AddStep ( "setup room" , ( ) = >
{
room = new Room
{
Name = "my awesome room" ,
MaxAttempts = 5 ,
Host = API . LocalUser . Value
} ;
room . RecentParticipants = [ room . Host ] ;
room . EndDate = DateTimeOffset . Now . AddMinutes ( 5 ) ;
room . Playlist =
[
new PlaylistItem ( importedBeatmap . Beatmaps . First ( ) )
{
RulesetID = new OsuRuleset ( ) . RulesetInfo . OnlineID
}
] ;
} ) ;
}
}