|
1 | 1 | import '@testing-library/jest-dom'; |
2 | | -import { render, screen, fireEvent } from '@testing-library/react'; |
| 2 | +import { render, screen, fireEvent, within } from '@testing-library/react'; |
3 | 3 | import userEvent from '@testing-library/user-event'; |
4 | 4 | import ColumnManagementModal, { ColumnManagementModalColumn } from './ColumnManagementModal'; |
5 | 5 |
|
@@ -31,6 +31,15 @@ const DEFAULT_COLUMNS: ColumnManagementModalColumn[] = [ |
31 | 31 | } |
32 | 32 | ]; |
33 | 33 |
|
| 34 | +interface ExtendedColumn extends ColumnManagementModalColumn { |
| 35 | + dataKey: string; |
| 36 | +} |
| 37 | + |
| 38 | +const EXTENDED_COLUMNS: ExtendedColumn[] = DEFAULT_COLUMNS.map((col) => ({ |
| 39 | + ...col, |
| 40 | + dataKey: `row.${col.key}` |
| 41 | +})); |
| 42 | + |
34 | 43 | const onClose = jest.fn(); |
35 | 44 | const setColumns = jest.fn(); |
36 | 45 |
|
@@ -164,6 +173,35 @@ describe('ColumnManagementModal component', () => { |
164 | 173 | expect(setColumns).not.toHaveBeenCalled(); |
165 | 174 | }); |
166 | 175 |
|
| 176 | + it('should preserve extended column fields when saving', () => { |
| 177 | + const applyColumnsMock = jest.fn(); |
| 178 | + render( |
| 179 | + <ColumnManagementModal<ExtendedColumn> |
| 180 | + appliedColumns={EXTENDED_COLUMNS} |
| 181 | + applyColumns={applyColumnsMock} |
| 182 | + isOpen |
| 183 | + onClose={onClose} |
| 184 | + data-testid="extended-column-modal" |
| 185 | + /> |
| 186 | + ); |
| 187 | + |
| 188 | + const modal = screen.getByTestId('extended-column-modal'); |
| 189 | + fireEvent.click(within(modal).getByTestId('column-check-impact')); |
| 190 | + fireEvent.click(within(modal).getByRole('button', { name: 'Save' })); |
| 191 | + |
| 192 | + expect(applyColumnsMock).toHaveBeenCalledTimes(1); |
| 193 | + const saved = applyColumnsMock.mock.calls[0][0] as ExtendedColumn[]; |
| 194 | + |
| 195 | + // Test that we have same number of columns |
| 196 | + expect(saved).toHaveLength(EXTENDED_COLUMNS.length); |
| 197 | + |
| 198 | + // Test that extension keys were preserved |
| 199 | + saved.forEach((col) => { |
| 200 | + const source = EXTENDED_COLUMNS.find((aec) => aec.key === col.key); |
| 201 | + expect(source?.dataKey).toBe(col.dataKey); |
| 202 | + }); |
| 203 | + }); |
| 204 | + |
167 | 205 | describe('enableDragDrop prop', () => { |
168 | 206 | it('should default enableDragDrop to false', () => { |
169 | 207 | // Default behavior should not enable drag and drop |
|
0 commit comments