Skip to content

Commit c8ac82e

Browse files
committed
test: preserve extension keys on columns
Assisted-by: Cursor
1 parent 618b60c commit c8ac82e

1 file changed

Lines changed: 39 additions & 1 deletion

File tree

packages/module/src/ColumnManagementModal/ColumnManagementModal.test.tsx

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import '@testing-library/jest-dom';
2-
import { render, screen, fireEvent } from '@testing-library/react';
2+
import { render, screen, fireEvent, within } from '@testing-library/react';
33
import userEvent from '@testing-library/user-event';
44
import ColumnManagementModal, { ColumnManagementModalColumn } from './ColumnManagementModal';
55

@@ -31,6 +31,15 @@ const DEFAULT_COLUMNS: ColumnManagementModalColumn[] = [
3131
}
3232
];
3333

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+
3443
const onClose = jest.fn();
3544
const setColumns = jest.fn();
3645

@@ -164,6 +173,35 @@ describe('ColumnManagementModal component', () => {
164173
expect(setColumns).not.toHaveBeenCalled();
165174
});
166175

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+
167205
describe('enableDragDrop prop', () => {
168206
it('should default enableDragDrop to false', () => {
169207
// Default behavior should not enable drag and drop

0 commit comments

Comments
 (0)