Skip to content

Commit 9768c9b

Browse files
authored
Merge branch 'develop' into feat/hamed-fse-excel-download-fixes-3861
2 parents 46bfbc6 + f911dad commit 9768c9b

File tree

2 files changed

+79
-5
lines changed

2 files changed

+79
-5
lines changed

frontend/src/views/ChargingSite/__tests__/components/ChargingSiteFSEGrid.test.jsx

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react'
22
import { 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'
44
import { ChargingSiteFSEGrid } from '../../components/ChargingSiteFSEGrid'
55
import { 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
})

frontend/src/views/ChargingSite/components/ChargingSiteFSEGrid.jsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,18 @@ export const ChargingSiteFSEGrid = ({
7070
return selectedEquipment.every((eq) => eq.status.status === 'Draft' || eq.status.status === 'Updated')
7171
}, [selectedRows, equipmentList])
7272

73-
// Check if selected equipment can be returned to draft (only from Submitted or Validated status)
73+
// Check if selected equipment can be returned to draft (only from Submitted status)
7474
const canReturnToDraft = useMemo(() => {
7575
if (selectedRows.length === 0) return false
7676
const selectedEquipment = equipmentList.filter((eq) =>
7777
selectedRows.includes(eq.chargingEquipmentId)
7878
)
79-
return selectedEquipment.every((eq) =>
80-
eq.status.status === 'Submitted' || eq.status.status === 'Validated'
79+
return selectedEquipment.every((eq) =>
80+
isIDIR
81+
? eq.status.status === 'Submitted'
82+
: eq.status.status === 'Submitted' || eq.status.status === 'Validated'
8183
)
82-
}, [selectedRows, equipmentList])
84+
}, [selectedRows, equipmentList, isIDIR])
8385

8486
// Check if selected equipment can be validated (only from Submitted status)
8587
const canValidate = useMemo(() => {

0 commit comments

Comments
 (0)