ant-design/components/typography/__tests__/enter-key-callback.test.tsx
yykoypj cfc790d6fe
test: move test cases to @testing/library for Typography (#35955)
* test: move test cases to @testing/library for Typography

* fix: waitFor for tooltip test

* fix: sleep to wait copy hide

* test: refactor focus test
2022-06-09 18:09:43 +08:00

33 lines
984 B
TypeScript

import React from 'react';
import KeyCode from 'rc-util/lib/KeyCode';
import Paragraph from '../Paragraph';
import { fireEvent, render } from '../../../tests/utils';
test('Callback on enter key is triggered', () => {
const onEditStart = jest.fn();
const onCopy = jest.fn();
const { container: wrapper } = render(
<Paragraph
copyable={{
onCopy,
}}
editable={{
onStart: onEditStart,
}}
>
test
</Paragraph>,
);
const timer: any = 9527;
jest.spyOn(window, 'setTimeout').mockReturnValue(timer);
jest.spyOn(window, 'clearTimeout');
// must copy first, because editing button will hide copy button
fireEvent.keyUp(wrapper.querySelectorAll('.ant-typography-copy')[0], { keyCode: KeyCode.ENTER });
fireEvent.keyUp(wrapper.querySelectorAll('.anticon-edit')[0], { keyCode: KeyCode.ENTER });
expect(onEditStart.mock.calls.length).toBe(1);
expect(onCopy.mock.calls.length).toBe(1);
jest.restoreAllMocks();
});