Skip to content

Commit f2e6f4b

Browse files
author
Johannes Weber
committed
chore: Increase test coverage
1 parent b3961c7 commit f2e6f4b

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed

src/table/__tests__/resizable-columns.test.tsx

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,70 @@ describe('resize in rtl', () => {
523523
});
524524
});
525525

526+
describe('Error handling when getResizerElements returns null', () => {
527+
const singleColumnDefinition = [{ id: 'id', header: 'Id', cell: (item: any) => item.id, width: 150, minWidth: 80 }];
528+
529+
beforeEach(() => {
530+
jest.doMock('../../../lib/components/table/resizer/resizer-lookup', () => ({
531+
...jest.requireActual('../../../lib/components/table/resizer/resizer-lookup'),
532+
getResizerElements: jest.fn(() => null),
533+
}));
534+
});
535+
536+
afterEach(() => {
537+
jest.resetModules();
538+
});
539+
540+
test('gracefully handles null getResizerElements during resize operations', () => {
541+
const onChange = jest.fn();
542+
const { wrapper } = renderTable(
543+
<Table
544+
{...defaultProps}
545+
columnDefinitions={singleColumnDefinition}
546+
onColumnWidthsChange={event => onChange(event.detail)}
547+
/>
548+
);
549+
550+
// Test updateColumnWidth and resizeColumn (lines 78, 155)
551+
// When getResizerElements returns null, the functions return early without DOM manipulation
552+
// but onWidthUpdate callback is still called (before the null check)
553+
expect(() => {
554+
firePointerdown(wrapper.findColumnResizer(1)!);
555+
firePointermove(200);
556+
firePointerup(200);
557+
}).not.toThrow();
558+
559+
// onChange is called because onWidthUpdate is invoked before the null check
560+
expect(onChange).toHaveBeenCalledTimes(1);
561+
expect(onChange).toHaveBeenCalledWith({ widths: [200] });
562+
});
563+
564+
test('gracefully handles null getResizerElements in UAP button clicks', () => {
565+
const onChange = jest.fn();
566+
const { wrapper } = renderTable(
567+
<Table
568+
{...defaultProps}
569+
columnDefinitions={singleColumnDefinition}
570+
onColumnWidthsChange={event => onChange(event.detail)}
571+
/>
572+
);
573+
574+
// Show UAP buttons
575+
wrapper.findColumnResizer(1)!.click();
576+
577+
// Test onDirectionClick (line 173) - should not throw or trigger onChange
578+
expect(() => {
579+
const dragHandle = findDragHandle();
580+
const inlineEndButton = dragHandle.findVisibleDirectionButtonInlineEnd();
581+
if (inlineEndButton) {
582+
inlineEndButton.click();
583+
}
584+
}).not.toThrow();
585+
586+
expect(onChange).not.toHaveBeenCalled();
587+
});
588+
});
589+
526590
describe('UAP buttons', () => {
527591
// Makes the drag buttons (which are positioned in a portal) easier to find if there's only one set.
528592
const singleColumnDefinition = [{ id: 'id', header: 'Id', cell: (item: any) => item.id, width: 150, minWidth: 80 }];

src/table/resizer/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,6 @@ export function Resizer({
203203
};
204204

205205
const onPointerMove = (event: PointerEvent) => {
206-
// TODO: Only set it to true after a certain number of pixels travelled?
207206
setIsDragging(true);
208207
clearTimeout(autoGrowTimeout.current);
209208
const offset = getLogicalPageX(event);

0 commit comments

Comments
 (0)