2022-02-09 18:07:52 +08:00
|
|
|
import KeyCode from 'rc-util/lib/KeyCode';
|
2022-06-22 14:57:09 +08:00
|
|
|
import React from 'react';
|
2022-06-09 18:09:43 +08:00
|
|
|
import { fireEvent, render } from '../../../tests/utils';
|
2022-06-22 14:57:09 +08:00
|
|
|
import Paragraph from '../Paragraph';
|
2022-02-09 18:07:52 +08:00
|
|
|
|
|
|
|
test('Callback on enter key is triggered', () => {
|
2023-06-07 11:54:50 +08:00
|
|
|
const onEditStart = vi.fn();
|
|
|
|
const onCopy = vi.fn();
|
2022-02-09 18:07:52 +08:00
|
|
|
|
2022-06-09 18:09:43 +08:00
|
|
|
const { container: wrapper } = render(
|
2022-02-09 18:07:52 +08:00
|
|
|
<Paragraph
|
|
|
|
copyable={{
|
|
|
|
onCopy,
|
|
|
|
}}
|
|
|
|
editable={{
|
|
|
|
onStart: onEditStart,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
test
|
|
|
|
</Paragraph>,
|
|
|
|
);
|
|
|
|
const timer: any = 9527;
|
2023-06-07 11:54:50 +08:00
|
|
|
vi.spyOn(window, 'setTimeout').mockReturnValue(timer);
|
|
|
|
vi.spyOn(window, 'clearTimeout');
|
2022-02-09 18:07:52 +08:00
|
|
|
// must copy first, because editing button will hide copy button
|
2022-06-09 18:09:43 +08:00
|
|
|
fireEvent.keyUp(wrapper.querySelectorAll('.ant-typography-copy')[0], { keyCode: KeyCode.ENTER });
|
|
|
|
fireEvent.keyUp(wrapper.querySelectorAll('.anticon-edit')[0], { keyCode: KeyCode.ENTER });
|
2022-02-09 18:07:52 +08:00
|
|
|
|
|
|
|
expect(onEditStart.mock.calls.length).toBe(1);
|
|
|
|
expect(onCopy.mock.calls.length).toBe(1);
|
2023-06-07 11:54:50 +08:00
|
|
|
vi.restoreAllMocks();
|
2022-02-09 18:07:52 +08:00
|
|
|
});
|