Skip to content

Commit fdfe1bb

Browse files
committed
Add missing regression/confidence test for setSelection API
1 parent ec7863c commit fdfe1bb

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

src/components/basic_table/basic_table.test.tsx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
import React from 'react';
10+
import { act } from '@testing-library/react';
1011
import { render, screen } from '../../test/rtl';
1112
import { requiredProps } from '../../test';
1213
import { shouldRenderCustomStyles } from '../../test/internal';
@@ -459,6 +460,34 @@ describe('EuiBasicTable', () => {
459460
expect(onSelectionChange).toHaveBeenCalledWith([]);
460461
expect(container.querySelectorAll('[checked]')).toHaveLength(0);
461462
});
463+
464+
// TODO: Delete this test once deprecated API is removed
465+
test('deprecated setSelection ref API', () => {
466+
const props = {
467+
items: basicItems,
468+
columns: basicColumns,
469+
itemId: 'id',
470+
selection: {
471+
onSelectionChange: () => {},
472+
},
473+
};
474+
475+
let classRef: EuiBasicTable | null;
476+
render(
477+
<EuiBasicTable
478+
{...props}
479+
ref={(ref) => {
480+
classRef = ref;
481+
}}
482+
/>
483+
);
484+
expect(getCheckboxAt(1).checked).toBeFalsy();
485+
486+
act(() => {
487+
classRef!.setSelection([basicItems[0]]);
488+
});
489+
expect(getCheckboxAt(1).checked).toBeTruthy();
490+
});
462491
});
463492

464493
test('footers', () => {

0 commit comments

Comments
 (0)