mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-25 00:08:27 +08:00
502dac12aa
* docs: fix code * feat: lint * feat: prettier * feat: test * feat: review * feat: format html * feat: format html
34 lines
985 B
TypeScript
34 lines
985 B
TypeScript
import React from 'react';
|
|
import KeyCode from 'rc-util/lib/KeyCode';
|
|
|
|
import { fireEvent, render } from '../../../tests/utils';
|
|
import Paragraph from '../Paragraph';
|
|
|
|
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();
|
|
});
|