55using System . Linq ;
66using System . Threading ;
77using NUnit . Framework ;
8+ using osu . Framework . Extensions ;
89using osu . Framework . Extensions . ObjectExtensions ;
910using osu . Framework . Graphics ;
1011using osu . Framework . Graphics . Sprites ;
@@ -55,6 +56,68 @@ public void TestAddUser()
5556 AddAssert ( "two unique panels" , ( ) => this . ChildrenOfType < ParticipantPanel > ( ) . Select ( p => p . Current . Value ) . Distinct ( ) . Count ( ) == 2 ) ;
5657 }
5758
59+ [ Test ]
60+ public void TestSlots ( )
61+ {
62+ setUpList ( ) ;
63+ AddAssert ( "one unique panel" , ( ) => this . ChildrenOfType < ParticipantPanel > ( ) . Select ( p => p . Current . Value ) . Distinct ( ) . Count ( ) == 1 ) ;
64+
65+ AddStep ( "add user" , ( ) => MultiplayerClient . AddUser ( new APIUser
66+ {
67+ Id = 3 ,
68+ Username = "Second" ,
69+ CoverUrl = TestResources . COVER_IMAGE_3 ,
70+ } ) ) ;
71+
72+ AddAssert ( "two unique panels" , ( ) => this . ChildrenOfType < ParticipantPanel > ( ) . Select ( p => p . Current . Value ) . Distinct ( ) . Count ( ) == 2 ) ;
73+
74+ AddStep ( "introduce slots" , ( ) => MultiplayerClient . ChangeMatchRoomState ( new StandardMatchRoomState
75+ {
76+ Slots = [ null , 3 , null , null , 1001 , null , null ]
77+ } ) . WaitSafely ( ) ) ;
78+
79+ AddStep ( "click first slot" , ( ) =>
80+ {
81+ InputManager . MoveMouseTo ( this . ChildrenOfType < ParticipantPanel > ( ) . First ( ) ) ;
82+ InputManager . Click ( MouseButton . Left ) ;
83+ } ) ;
84+ AddUntilStep ( "slots changed" , ( ) => ( ( StandardMatchRoomState ) MultiplayerClient . ClientRoom ! . MatchState ! ) . Slots ,
85+ ( ) => Is . EquivalentTo ( new int ? [ ] { 1001 , 3 , null , null , null , null , null } ) ) ;
86+
87+ AddStep ( "click second slot" , ( ) =>
88+ {
89+ InputManager . MoveMouseTo ( this . ChildrenOfType < ParticipantPanel > ( ) . ElementAt ( 1 ) ) ;
90+ InputManager . Click ( MouseButton . Left ) ;
91+ } ) ;
92+ AddUntilStep ( "slots not changed" , ( ) => ( ( StandardMatchRoomState ) MultiplayerClient . ClientRoom ! . MatchState ! ) . Slots ,
93+ ( ) => Is . EquivalentTo ( new int ? [ ] { 1001 , 3 , null , null , null , null , null } ) ) ;
94+
95+ AddStep ( "click last slot" , ( ) =>
96+ {
97+ InputManager . MoveMouseTo ( this . ChildrenOfType < ParticipantPanel > ( ) . Last ( ) ) ;
98+ InputManager . Click ( MouseButton . Left ) ;
99+ } ) ;
100+ AddUntilStep ( "slots changed" , ( ) => ( ( StandardMatchRoomState ) MultiplayerClient . ClientRoom ! . MatchState ! ) . Slots ,
101+ ( ) => Is . EquivalentTo ( new int ? [ ] { null , 3 , null , null , null , null , 1001 } ) ) ;
102+
103+ AddStep ( "shuffle slots" , ( ) => MultiplayerClient . ChangeMatchRoomState ( new StandardMatchRoomState
104+ {
105+ Slots = [ null , null , 1001 , null , null , null , 3 ]
106+ } ) . WaitSafely ( ) ) ;
107+ AddStep ( "remove slots" , ( ) => MultiplayerClient . ChangeMatchRoomState ( new StandardMatchRoomState
108+ {
109+ Slots = [ null , 3 , null , 1001 ]
110+ } ) . WaitSafely ( ) ) ;
111+ AddStep ( "add slots" , ( ) => MultiplayerClient . ChangeMatchRoomState ( new StandardMatchRoomState
112+ {
113+ Slots = [ null , null , 3 , null , 1001 , null ]
114+ } ) . WaitSafely ( ) ) ;
115+ AddStep ( "turn off slots" , ( ) => MultiplayerClient . ChangeMatchRoomState ( new StandardMatchRoomState
116+ {
117+ Slots = null
118+ } ) . WaitSafely ( ) ) ;
119+ }
120+
58121 [ Test ]
59122 public void TestAddReferee ( )
60123 {
@@ -86,7 +149,7 @@ public void TestAddUnresolvedUser()
86149
87150 AddUntilStep ( "two unique panels" , ( ) => this . ChildrenOfType < ParticipantPanel > ( ) . Select ( p => p . Current . Value ) . Distinct ( ) . Count ( ) == 2 ) ;
88151
89- AddStep ( "kick null user" , ( ) => this . ChildrenOfType < ParticipantPanel > ( ) . Single ( p => p . Current . Value . User == null )
152+ AddStep ( "kick null user" , ( ) => this . ChildrenOfType < ParticipantPanel > ( ) . Single ( p => p . Current . Value . User ? . User == null )
90153 . ChildrenOfType < ParticipantPanel . KickButton > ( ) . Single ( ) . TriggerClick ( ) ) ;
91154
92155 AddUntilStep ( "null user kicked" , ( ) => MultiplayerClient . ClientRoom . AsNonNull ( ) . Users . Count == 1 ) ;
@@ -111,7 +174,7 @@ public void TestRemoveUser()
111174
112175 AddStep ( "remove host" , ( ) => MultiplayerClient . RemoveUser ( API . LocalUser . Value ) ) ;
113176
114- AddAssert ( "single panel is for second user" , ( ) => this . ChildrenOfType < ParticipantPanel > ( ) . Single ( ) . Current . Value . UserID == secondUser ? . Id ) ;
177+ AddAssert ( "single panel is for second user" , ( ) => this . ChildrenOfType < ParticipantPanel > ( ) . Single ( ) . Current . Value . User ? . UserID == secondUser ? . Id ) ;
115178 }
116179
117180 [ Test ]
@@ -150,7 +213,7 @@ public void TestBeatmapDownloadingStates()
150213
151214 AddRepeatStep ( "increment progress" , ( ) =>
152215 {
153- float progress = this . ChildrenOfType < ParticipantPanel > ( ) . Single ( ) . Current . Value . BeatmapAvailability . DownloadProgress ?? 0 ;
216+ float progress = this . ChildrenOfType < ParticipantPanel > ( ) . Single ( ) . Current . Value . User ? . BeatmapAvailability . DownloadProgress ?? 0 ;
154217 MultiplayerClient . ChangeBeatmapAvailability ( BeatmapAvailability . Downloading ( progress + RNG . NextSingle ( 0.1f ) ) ) ;
155218 } , 25 ) ;
156219
@@ -195,16 +258,16 @@ public void TestCrownChangesStateWhenHostTransferred()
195258 } ) ) ;
196259
197260 AddUntilStep ( "first user crown visible" ,
198- ( ) => this . ChildrenOfType < ParticipantPanel > ( ) . Single ( p => p . Current . Value . UserID == 1001 ) . ChildrenOfType < SpriteIcon > ( ) . First ( ) . Alpha == 1 ) ;
261+ ( ) => this . ChildrenOfType < ParticipantPanel > ( ) . Single ( p => p . Current . Value . User ? . UserID == 1001 ) . ChildrenOfType < SpriteIcon > ( ) . First ( ) . Alpha == 1 ) ;
199262 AddUntilStep ( "second user crown hidden" ,
200- ( ) => this . ChildrenOfType < ParticipantPanel > ( ) . Single ( p => p . Current . Value . UserID == 3 ) . ChildrenOfType < SpriteIcon > ( ) . First ( ) . Alpha == 0 ) ;
263+ ( ) => this . ChildrenOfType < ParticipantPanel > ( ) . Single ( p => p . Current . Value . User ? . UserID == 3 ) . ChildrenOfType < SpriteIcon > ( ) . First ( ) . Alpha == 0 ) ;
201264
202265 AddStep ( "make second user host" , ( ) => MultiplayerClient . TransferHost ( 3 ) ) ;
203266
204267 AddUntilStep ( "first user crown visible" ,
205- ( ) => this . ChildrenOfType < ParticipantPanel > ( ) . Single ( p => p . Current . Value . UserID == 1001 ) . ChildrenOfType < SpriteIcon > ( ) . First ( ) . Alpha == 0 ) ;
268+ ( ) => this . ChildrenOfType < ParticipantPanel > ( ) . Single ( p => p . Current . Value . User ? . UserID == 1001 ) . ChildrenOfType < SpriteIcon > ( ) . First ( ) . Alpha == 0 ) ;
206269 AddUntilStep ( "second user crown hidden" ,
207- ( ) => this . ChildrenOfType < ParticipantPanel > ( ) . Single ( p => p . Current . Value . UserID == 3 ) . ChildrenOfType < SpriteIcon > ( ) . First ( ) . Alpha == 1 ) ;
270+ ( ) => this . ChildrenOfType < ParticipantPanel > ( ) . Single ( p => p . Current . Value . User ? . UserID == 3 ) . ChildrenOfType < SpriteIcon > ( ) . First ( ) . Alpha == 1 ) ;
208271 }
209272
210273 [ Test ]
@@ -221,8 +284,8 @@ public void TestHostGetsPinnedToTop()
221284 AddStep ( "make second user host" , ( ) => MultiplayerClient . TransferHost ( 3 ) ) ;
222285 AddAssert ( "second user above first" , ( ) =>
223286 {
224- var first = this . ChildrenOfType < ParticipantPanel > ( ) . Single ( u => u . Current . Value . UserID == 1001 ) ;
225- var second = this . ChildrenOfType < ParticipantPanel > ( ) . Single ( u => u . Current . Value . UserID == 3 ) ;
287+ var first = this . ChildrenOfType < ParticipantPanel > ( ) . Single ( u => u . Current . Value . User ? . UserID == 1001 ) ;
288+ var second = this . ChildrenOfType < ParticipantPanel > ( ) . Single ( u => u . Current . Value . User ? . UserID == 3 ) ;
226289 return second . ScreenSpaceDrawQuad . TopLeft . Y < first . ScreenSpaceDrawQuad . TopLeft . Y ;
227290 } ) ;
228291 }
0 commit comments