11import React from 'react'
22import { describe , it , expect , vi , beforeEach } from 'vitest'
3- import { render , screen , fireEvent } from '@testing-library/react'
3+ import { render , screen , fireEvent , waitFor } from '@testing-library/react'
44import { ChargingSiteFSEGrid } from '../../components/ChargingSiteFSEGrid'
55import { wrapper } from '@/tests/utils/wrapper.jsx'
66
@@ -30,6 +30,32 @@ vi.mock('@/components/BCDataGrid/BCGridViewer.jsx', () => ({
3030 >
3131 Row Click
3232 </ button >
33+ < button
34+ onClick = { ( ) =>
35+ props . gridOptions ?. onSelectionChanged ?. ( {
36+ api : {
37+ getSelectedNodes : ( ) => [
38+ { data : { chargingEquipmentId : 2 , status : { status : 'Validated' } } }
39+ ]
40+ }
41+ } )
42+ }
43+ >
44+ Select Validated
45+ </ button >
46+ < button
47+ onClick = { ( ) =>
48+ props . gridOptions ?. onSelectionChanged ?. ( {
49+ api : {
50+ getSelectedNodes : ( ) => [
51+ { data : { chargingEquipmentId : 3 , status : { status : 'Submitted' } } }
52+ ]
53+ }
54+ } )
55+ }
56+ >
57+ Select Submitted
58+ </ button >
3359 </ div >
3460 ) )
3561} ) )
@@ -52,6 +78,16 @@ describe('ChargingSiteFSEGrid', () => {
5278 chargingEquipmentId : 1 ,
5379 status : { status : 'Draft' } ,
5480 registrationNumber : 'REG001'
81+ } ,
82+ {
83+ chargingEquipmentId : 2 ,
84+ status : { status : 'Validated' } ,
85+ registrationNumber : 'REG002'
86+ } ,
87+ {
88+ chargingEquipmentId : 3 ,
89+ status : { status : 'Submitted' } ,
90+ registrationNumber : 'REG003'
5591 }
5692 ] ,
5793 status : { status : 'Draft' } ,
@@ -250,4 +286,40 @@ describe('ChargingSiteFSEGrid', () => {
250286 )
251287 } )
252288 } )
289+
290+ describe ( 'Return to draft button rules' , ( ) => {
291+ it ( 'disables Return to draft for IDIR when a Validated row is selected' , async ( ) => {
292+ const idirProps = {
293+ ...mockProps ,
294+ isIDIR : true ,
295+ hasAnyRole : vi . fn ( ( ) => true ) ,
296+ hasRoles : vi . fn ( ( role ) => role === 'analyst' )
297+ }
298+ render ( < ChargingSiteFSEGrid { ...idirProps } /> , { wrapper } )
299+
300+ fireEvent . click ( screen . getByText ( 'Select Validated' ) )
301+
302+ await waitFor ( ( ) => {
303+ expect (
304+ screen . getByRole ( 'button' , {
305+ name : 'chargingSite:buttons.returnSelectedToDraft'
306+ } )
307+ ) . toBeDisabled ( )
308+ } )
309+ } )
310+
311+ it ( 'keeps Return to draft enabled for non-IDIR when a Validated row is selected' , async ( ) => {
312+ render ( < ChargingSiteFSEGrid { ...mockProps } /> , { wrapper } )
313+
314+ fireEvent . click ( screen . getByText ( 'Select Validated' ) )
315+
316+ await waitFor ( ( ) => {
317+ expect (
318+ screen . getByRole ( 'button' , {
319+ name : 'chargingSite:buttons.returnSelectedToDraft'
320+ } )
321+ ) . toBeEnabled ( )
322+ } )
323+ } )
324+ } )
253325} )
0 commit comments