From 09363b60171c4889762d86675c10c581f41e0b71 Mon Sep 17 00:00:00 2001 From: nicolethoen Date: Fri, 30 Jan 2026 09:20:23 -0500 Subject: [PATCH] fix(ColumnManagementModal): update reset to default behavior --- .../ColumnManagementModal.test.tsx | 68 ++++++++++++++++++- .../ColumnManagementModal.tsx | 12 +++- 2 files changed, 77 insertions(+), 3 deletions(-) diff --git a/packages/module/src/ColumnManagementModal/ColumnManagementModal.test.tsx b/packages/module/src/ColumnManagementModal/ColumnManagementModal.test.tsx index 6c4b7ae5..7ec26827 100644 --- a/packages/module/src/ColumnManagementModal/ColumnManagementModal.test.tsx +++ b/packages/module/src/ColumnManagementModal/ColumnManagementModal.test.tsx @@ -80,10 +80,40 @@ describe('ColumnManagementModal component', () => { fireEvent.click(screen.getByText('Score')); fireEvent.click(screen.getByText('Reset to default')); - + expect(getCheckboxesState()).toEqual(DEFAULT_COLUMNS.map(c => c.isShownByDefault)); }); + it('should call onReset callback when reset to default is clicked', () => { + const onResetMock = jest.fn(); + render(); + + const resetButtons = screen.getAllByText('Reset to default'); + // Click the last one rendered (the new modal) + fireEvent.click(resetButtons[resetButtons.length - 1]); + + expect(onResetMock).toHaveBeenCalledTimes(1); + }); + + it('should display custom reset button label', () => { + const customLabel = 'Restaurer par défaut'; + render(); + + expect(screen.getByText(customLabel)).toBeInTheDocument(); + }); + it('should set all columns to show upon clicking on "Select all"', async () => { // disable Impact column which is enabled by default fireEvent.click(screen.getByText('Impact')); @@ -138,4 +168,40 @@ describe('ColumnManagementModal component', () => { expect(screen.getByTestId('drag-drop-sort')).toBeInTheDocument(); }); }); + + describe('reset functionality', () => { + it('should reset column order to original when reset to default is clicked', () => { + const reorderedColumns = [ + DEFAULT_COLUMNS[3], // Score (last -> first) + DEFAULT_COLUMNS[0], // ID + DEFAULT_COLUMNS[2], // Impact + DEFAULT_COLUMNS[1], // Publish date + ]; + + const applyColumnsMock = jest.fn(); + render(); + + // Click reset to default - get all buttons and click the last one + const resetButtons = screen.getAllByText('Reset to default'); + fireEvent.click(resetButtons[resetButtons.length - 1]); + + // Click save to apply changes + const saveButtons = screen.getAllByText('Save'); + fireEvent.click(saveButtons[saveButtons.length - 1]); + + // Verify that the saved columns match the original reordered columns order + // (after reset, it should restore the order from appliedColumns which is reorderedColumns) + expect(applyColumnsMock).toHaveBeenCalledWith( + reorderedColumns.map(col => ({ + ...col, + isShown: col.isShownByDefault + })) + ); + }); + }); }); diff --git a/packages/module/src/ColumnManagementModal/ColumnManagementModal.tsx b/packages/module/src/ColumnManagementModal/ColumnManagementModal.tsx index 6d88268f..006cb6c3 100644 --- a/packages/module/src/ColumnManagementModal/ColumnManagementModal.tsx +++ b/packages/module/src/ColumnManagementModal/ColumnManagementModal.tsx @@ -40,6 +40,10 @@ export interface ColumnManagementModalProps extends Omit void; + /** Custom label for reset to default button */ + resetToDefaultLabel?: string; } const ColumnManagementModal: FunctionComponent = ( @@ -51,6 +55,8 @@ const ColumnManagementModal: FunctionComponent = ( applyColumns, ouiaId = 'ColumnManagementModal', enableDragDrop = false, + onReset, + resetToDefaultLabel = 'Reset to default', ...props }: ColumnManagementModalProps) => { const [ currentColumns, setCurrentColumns ] = useState(() => @@ -72,7 +78,9 @@ const ColumnManagementModal: FunctionComponent = ( })); const resetToDefault = () => { - setCurrentColumns(currentColumns.map(column => ({ ...column, isShown: column.isShownByDefault ?? false }))); + // Reset both visibility and order to match the original appliedColumns + setCurrentColumns(appliedColumns.map(column => ({ ...column, isShown: column.isShownByDefault ?? false }))); + onReset?.(); }; const updateColumns = (items: ListManagerItem[]) => { @@ -131,7 +139,7 @@ const ColumnManagementModal: FunctionComponent = ( <> {description} }