@@ -118,6 +118,32 @@ const activateUser = async (setupActionSpies: () => void) => {
118
118
fireEvent . click ( confirmButton )
119
119
}
120
120
121
+ const markUserDormant = async ( setupActionSpies : ( ) => void ) => {
122
+ const moreButtons = await screen . findAllByLabelText ( "more" )
123
+ const markAsDormantMoreButton = moreButtons [ 1 ]
124
+ fireEvent . click ( markAsDormantMoreButton )
125
+
126
+ const menu = screen . getByRole ( "menu" )
127
+ const text = t ( "markUserDormantMenuItem" , { ns : "usersPage" } )
128
+ const markAsDormant = within ( menu ) . getByText ( text )
129
+ fireEvent . click ( markAsDormant )
130
+
131
+ // Check if the confirm message is displayed
132
+ const confirmDialog = screen . getByRole ( "dialog" )
133
+ expect ( confirmDialog ) . toHaveTextContent (
134
+ `Do you want to mark the user TestUser2 as dormant?` ,
135
+ )
136
+
137
+ // Setup spies to check the actions after
138
+ setupActionSpies ( )
139
+
140
+ // Click on the "Confirm" button
141
+ const confirmButton = within ( confirmDialog ) . getByText (
142
+ UsersPageLanguage . markUserDormantDialogAction ,
143
+ )
144
+ fireEvent . click ( confirmButton )
145
+ }
146
+
121
147
const resetUserPassword = async ( setupActionSpies : ( ) => void ) => {
122
148
const moreButtons = await screen . findAllByLabelText ( "more" )
123
149
const firstMoreButton = moreButtons [ 0 ]
@@ -345,6 +371,50 @@ describe("UsersPage", () => {
345
371
} )
346
372
} )
347
373
374
+ describe ( "mark user as dormant" , ( ) => {
375
+ describe ( "when user is successfully marked as dormant" , ( ) => {
376
+ it ( "shows a success message and refreshes the page" , async ( ) => {
377
+ renderPage ( )
378
+
379
+ await markUserDormant ( ( ) => {
380
+ jest . spyOn ( API , "markUserDormant" ) . mockResolvedValueOnce ( {
381
+ ...MockUser2 ,
382
+ status : "dormant" ,
383
+ } )
384
+ jest . spyOn ( API , "getUsers" ) . mockImplementationOnce ( ( ) =>
385
+ Promise . resolve ( {
386
+ users : [ MockUser , MockUser2 ] ,
387
+ count : 2 ,
388
+ } ) ,
389
+ )
390
+ } )
391
+
392
+ // Check if the success message is displayed
393
+ await screen . findByText ( usersXServiceLanguage . markUserDormantSuccess )
394
+
395
+ // Check if the API was called correctly
396
+ expect ( API . markUserDormant ) . toBeCalledTimes ( 1 )
397
+ expect ( API . markUserDormant ) . toBeCalledWith ( MockUser2 . id )
398
+ } )
399
+ } )
400
+ describe ( "when can't mark user as dormant" , ( ) => {
401
+ it ( "shows an error message" , async ( ) => {
402
+ renderPage ( )
403
+
404
+ await markUserDormant ( ( ) => {
405
+ jest . spyOn ( API , "markUserDormant" ) . mockRejectedValueOnce ( { } )
406
+ } )
407
+
408
+ // Check if the error message is displayed
409
+ await screen . findByText ( usersXServiceLanguage . markUserDormantError )
410
+
411
+ // Check if the API was called correctly
412
+ expect ( API . markUserDormant ) . toBeCalledTimes ( 1 )
413
+ expect ( API . markUserDormant ) . toBeCalledWith ( MockUser2 . id )
414
+ } )
415
+ } )
416
+ } )
417
+
348
418
describe ( "reset user password" , ( ) => {
349
419
describe ( "when it is success" , ( ) => {
350
420
it ( "shows a success message" , async ( ) => {
0 commit comments