@@ -80,10 +80,40 @@ describe('ColumnManagementModal component', () => {
8080 fireEvent . click ( screen . getByText ( 'Score' ) ) ;
8181
8282 fireEvent . click ( screen . getByText ( 'Reset to default' ) ) ;
83-
83+
8484 expect ( getCheckboxesState ( ) ) . toEqual ( DEFAULT_COLUMNS . map ( c => c . isShownByDefault ) ) ;
8585 } ) ;
8686
87+ it ( 'should call onReset callback when reset to default is clicked' , ( ) => {
88+ const onResetMock = jest . fn ( ) ;
89+ render ( < ColumnManagementModal
90+ appliedColumns = { DEFAULT_COLUMNS }
91+ applyColumns = { setColumns }
92+ isOpen
93+ onClose = { onClose }
94+ onReset = { onResetMock }
95+ /> ) ;
96+
97+ const resetButtons = screen . getAllByText ( 'Reset to default' ) ;
98+ // Click the last one rendered (the new modal)
99+ fireEvent . click ( resetButtons [ resetButtons . length - 1 ] ) ;
100+
101+ expect ( onResetMock ) . toHaveBeenCalledTimes ( 1 ) ;
102+ } ) ;
103+
104+ it ( 'should display custom reset button label' , ( ) => {
105+ const customLabel = 'Restaurer par défaut' ;
106+ render ( < ColumnManagementModal
107+ appliedColumns = { DEFAULT_COLUMNS }
108+ applyColumns = { setColumns }
109+ isOpen
110+ onClose = { onClose }
111+ resetToDefaultLabel = { customLabel }
112+ /> ) ;
113+
114+ expect ( screen . getByText ( customLabel ) ) . toBeInTheDocument ( ) ;
115+ } ) ;
116+
87117 it ( 'should set all columns to show upon clicking on "Select all"' , async ( ) => {
88118 // disable Impact column which is enabled by default
89119 fireEvent . click ( screen . getByText ( 'Impact' ) ) ;
@@ -138,4 +168,40 @@ describe('ColumnManagementModal component', () => {
138168 expect ( screen . getByTestId ( 'drag-drop-sort' ) ) . toBeInTheDocument ( ) ;
139169 } ) ;
140170 } ) ;
171+
172+ describe ( 'reset functionality' , ( ) => {
173+ it ( 'should reset column order to original when reset to default is clicked' , ( ) => {
174+ const reorderedColumns = [
175+ DEFAULT_COLUMNS [ 3 ] , // Score (last -> first)
176+ DEFAULT_COLUMNS [ 0 ] , // ID
177+ DEFAULT_COLUMNS [ 2 ] , // Impact
178+ DEFAULT_COLUMNS [ 1 ] , // Publish date
179+ ] ;
180+
181+ const applyColumnsMock = jest . fn ( ) ;
182+ render ( < ColumnManagementModal
183+ appliedColumns = { reorderedColumns }
184+ applyColumns = { applyColumnsMock }
185+ isOpen
186+ onClose = { onClose }
187+ /> ) ;
188+
189+ // Click reset to default - get all buttons and click the last one
190+ const resetButtons = screen . getAllByText ( 'Reset to default' ) ;
191+ fireEvent . click ( resetButtons [ resetButtons . length - 1 ] ) ;
192+
193+ // Click save to apply changes
194+ const saveButtons = screen . getAllByText ( 'Save' ) ;
195+ fireEvent . click ( saveButtons [ saveButtons . length - 1 ] ) ;
196+
197+ // Verify that the saved columns match the original reordered columns order
198+ // (after reset, it should restore the order from appliedColumns which is reorderedColumns)
199+ expect ( applyColumnsMock ) . toHaveBeenCalledWith (
200+ reorderedColumns . map ( col => ( {
201+ ...col ,
202+ isShown : col . isShownByDefault
203+ } ) )
204+ ) ;
205+ } ) ;
206+ } ) ;
141207} ) ;
0 commit comments