2022-08-18 17:40:47 +08:00
|
|
|
import type { render } from '../../../tests/utils';
|
2023-08-04 16:14:56 +08:00
|
|
|
import { fireEvent, screen } from '../../../tests/utils';
|
2022-08-18 17:40:47 +08:00
|
|
|
|
|
|
|
export function openPicker(wrapper: ReturnType<typeof render>, index = 0) {
|
|
|
|
fireEvent.mouseDown(wrapper.container?.querySelectorAll('input')?.[index]!);
|
|
|
|
fireEvent.focus(wrapper.container?.querySelectorAll('input')?.[index]!);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function closePicker(wrapper: ReturnType<typeof render>, index = 0) {
|
|
|
|
fireEvent.blur(wrapper.container?.querySelectorAll('input')[index]!);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function selectCell(wrapper: ReturnType<typeof render>, text: string | number, index = 0) {
|
|
|
|
let matchCell: HTMLTableCellElement | null = null;
|
|
|
|
const tds = wrapper.container?.querySelectorAll('table')?.[index]?.querySelectorAll('td');
|
2022-11-19 13:47:33 +08:00
|
|
|
tds.forEach((td) => {
|
2022-08-18 17:40:47 +08:00
|
|
|
if (td.querySelector('div')?.innerHTML === String(text) && td.className.includes('-in-view')) {
|
|
|
|
matchCell = td;
|
|
|
|
fireEvent.click(td);
|
|
|
|
}
|
|
|
|
});
|
2023-06-07 21:59:21 +08:00
|
|
|
/* istanbul ignore next */
|
2022-08-18 17:40:47 +08:00
|
|
|
if (!matchCell) {
|
|
|
|
throw new Error('Cell not match in picker panel.');
|
|
|
|
}
|
|
|
|
return matchCell;
|
|
|
|
}
|
2023-08-04 16:14:56 +08:00
|
|
|
|
|
|
|
export const closeCircleByRole = { role: 'img', options: { name: 'close-circle' } } as const;
|
|
|
|
|
|
|
|
export function expectCloseCircle(shouldExist: boolean) {
|
|
|
|
const { role, options } = closeCircleByRole;
|
|
|
|
const count = shouldExist ? 1 : 0;
|
|
|
|
return expect(screen.queryAllByRole(role, options).length).toStrictEqual(count);
|
|
|
|
}
|