2019-02-19 11:42:05 +08:00
|
|
|
import React from 'react';
|
|
|
|
import { mount } from 'enzyme';
|
2020-08-09 12:56:35 +08:00
|
|
|
import { SmileOutlined, LikeOutlined, HighlightOutlined } from '@ant-design/icons';
|
2019-02-19 11:42:05 +08:00
|
|
|
import KeyCode from 'rc-util/lib/KeyCode';
|
|
|
|
import copy from 'copy-to-clipboard';
|
|
|
|
import Title from '../Title';
|
2020-05-11 14:28:57 +08:00
|
|
|
import Link from '../Link';
|
2019-02-19 11:42:05 +08:00
|
|
|
import Paragraph from '../Paragraph';
|
|
|
|
import Base from '../Base'; // eslint-disable-line import/no-named-as-default
|
2019-08-26 22:53:20 +08:00
|
|
|
import mountTest from '../../../tests/shared/mountTest';
|
2020-01-02 19:10:16 +08:00
|
|
|
import rtlTest from '../../../tests/shared/rtlTest';
|
2019-10-01 14:06:09 +08:00
|
|
|
import Typography from '../Typography';
|
2020-03-20 15:07:47 +08:00
|
|
|
import { sleep } from '../../../tests/utils';
|
2020-06-13 14:24:56 +08:00
|
|
|
import TextArea from '../../input/TextArea';
|
2019-02-19 11:42:05 +08:00
|
|
|
|
|
|
|
jest.mock('copy-to-clipboard');
|
|
|
|
|
|
|
|
describe('Typography', () => {
|
2019-08-26 22:53:20 +08:00
|
|
|
mountTest(Paragraph);
|
|
|
|
mountTest(Base);
|
|
|
|
mountTest(Title);
|
2020-05-11 14:28:57 +08:00
|
|
|
mountTest(Link);
|
2019-08-26 22:53:20 +08:00
|
|
|
|
2020-01-02 19:10:16 +08:00
|
|
|
rtlTest(Paragraph);
|
|
|
|
rtlTest(Base);
|
|
|
|
rtlTest(Title);
|
2020-05-11 14:28:57 +08:00
|
|
|
rtlTest(Link);
|
2020-01-02 19:10:16 +08:00
|
|
|
|
2019-02-19 11:42:05 +08:00
|
|
|
const LINE_STR_COUNT = 20;
|
|
|
|
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
|
|
|
|
|
|
|
// Mock offsetHeight
|
|
|
|
const originOffsetHeight = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'offsetHeight')
|
|
|
|
.get;
|
|
|
|
Object.defineProperty(HTMLElement.prototype, 'offsetHeight', {
|
|
|
|
get() {
|
|
|
|
let html = this.innerHTML;
|
|
|
|
html = html.replace(/<[^>]*>/g, '');
|
|
|
|
const lines = Math.ceil(html.length / LINE_STR_COUNT);
|
|
|
|
return lines * 16;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
// Mock getComputedStyle
|
|
|
|
const originGetComputedStyle = window.getComputedStyle;
|
|
|
|
window.getComputedStyle = ele => {
|
|
|
|
const style = originGetComputedStyle(ele);
|
|
|
|
style.lineHeight = '16px';
|
|
|
|
return style;
|
|
|
|
};
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
errorSpy.mockReset();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterAll(() => {
|
|
|
|
errorSpy.mockRestore();
|
|
|
|
Object.defineProperty(HTMLElement.prototype, 'offsetHeight', {
|
|
|
|
get: originOffsetHeight,
|
|
|
|
});
|
|
|
|
window.getComputedStyle = originGetComputedStyle;
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Title', () => {
|
|
|
|
it('warning if `level` not correct', () => {
|
|
|
|
mount(<Title level={false} />);
|
|
|
|
|
2019-04-03 15:54:26 +08:00
|
|
|
expect(errorSpy).toHaveBeenCalledWith(
|
2020-07-28 20:39:43 +08:00
|
|
|
'Warning: [antd: Typography.Title] Title only accept `1 | 2 | 3 | 4 | 5` as `level` value. And `5` need 4.6.0+ version.',
|
2019-02-19 11:42:05 +08:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Base', () => {
|
|
|
|
describe('trigger ellipsis update', () => {
|
|
|
|
const fullStr =
|
|
|
|
'Bamboo is Little Light Bamboo is Little Light Bamboo is Little Light Bamboo is Little Light Bamboo is Little Light';
|
|
|
|
|
2020-03-20 15:07:47 +08:00
|
|
|
it('should trigger update', async () => {
|
2020-04-21 10:13:57 +08:00
|
|
|
const onEllipsis = jest.fn();
|
2019-02-19 11:42:05 +08:00
|
|
|
const wrapper = mount(
|
2020-04-21 10:13:57 +08:00
|
|
|
<Base ellipsis={{ onEllipsis }} component="p" editable>
|
2019-02-19 11:42:05 +08:00
|
|
|
{fullStr}
|
|
|
|
</Base>,
|
|
|
|
);
|
|
|
|
|
2020-03-20 15:07:47 +08:00
|
|
|
await sleep(20);
|
2019-02-19 11:42:05 +08:00
|
|
|
wrapper.update();
|
2019-08-13 14:07:17 +08:00
|
|
|
expect(wrapper.find('span:not(.anticon)').text()).toEqual('Bamboo is Little ...');
|
2020-04-21 10:13:57 +08:00
|
|
|
expect(onEllipsis).toHaveBeenCalledWith(true);
|
|
|
|
onEllipsis.mockReset();
|
2019-02-19 11:42:05 +08:00
|
|
|
|
2020-04-21 10:13:57 +08:00
|
|
|
wrapper.setProps({ ellipsis: { rows: 2, onEllipsis } });
|
2020-03-20 15:07:47 +08:00
|
|
|
await sleep(20);
|
2019-02-19 11:42:05 +08:00
|
|
|
wrapper.update();
|
2019-08-29 23:41:46 +08:00
|
|
|
expect(wrapper.find('span:not(.anticon)').text()).toEqual(
|
|
|
|
'Bamboo is Little Light Bamboo is Litt...',
|
|
|
|
);
|
2020-04-21 10:13:57 +08:00
|
|
|
expect(onEllipsis).not.toHaveBeenCalled();
|
2019-02-19 11:42:05 +08:00
|
|
|
|
2020-04-21 10:13:57 +08:00
|
|
|
wrapper.setProps({ ellipsis: { rows: 99, onEllipsis } });
|
2020-03-20 15:07:47 +08:00
|
|
|
await sleep(20);
|
2019-02-19 11:42:05 +08:00
|
|
|
wrapper.update();
|
|
|
|
expect(wrapper.find('p').text()).toEqual(fullStr);
|
2020-04-21 10:13:57 +08:00
|
|
|
expect(onEllipsis).toHaveBeenCalledWith(false);
|
2019-02-19 11:42:05 +08:00
|
|
|
|
|
|
|
wrapper.unmount();
|
|
|
|
});
|
|
|
|
|
2020-03-20 15:07:47 +08:00
|
|
|
it('should middle ellipsis', async () => {
|
2019-12-24 11:59:17 +08:00
|
|
|
const suffix = '--suffix';
|
|
|
|
const wrapper = mount(
|
|
|
|
<Base ellipsis={{ rows: 1, suffix }} component="p">
|
|
|
|
{fullStr}
|
|
|
|
</Base>,
|
|
|
|
);
|
|
|
|
|
2020-03-20 15:07:47 +08:00
|
|
|
await sleep(20);
|
2019-12-24 11:59:17 +08:00
|
|
|
wrapper.update();
|
|
|
|
expect(wrapper.find('p').text()).toEqual('Bamboo is...--suffix');
|
|
|
|
wrapper.unmount();
|
|
|
|
});
|
|
|
|
|
2020-03-20 15:07:47 +08:00
|
|
|
it('should front or middle ellipsis', async () => {
|
2019-12-24 11:59:17 +08:00
|
|
|
const suffix = '--The information is very important';
|
|
|
|
const wrapper = mount(
|
|
|
|
<Base ellipsis={{ rows: 1, suffix }} component="p">
|
|
|
|
{fullStr}
|
|
|
|
</Base>,
|
|
|
|
);
|
|
|
|
|
2020-03-20 15:07:47 +08:00
|
|
|
await sleep(20);
|
2019-12-24 11:59:17 +08:00
|
|
|
wrapper.update();
|
|
|
|
expect(wrapper.find('p').text()).toEqual('...--The information is very important');
|
|
|
|
|
|
|
|
wrapper.setProps({ ellipsis: { rows: 2, suffix } });
|
2020-03-20 15:07:47 +08:00
|
|
|
await sleep(20);
|
2019-12-24 11:59:17 +08:00
|
|
|
wrapper.update();
|
|
|
|
expect(wrapper.find('p').text()).toEqual('Ba...--The information is very important');
|
|
|
|
|
|
|
|
wrapper.setProps({ ellipsis: { rows: 99, suffix } });
|
2020-03-20 15:07:47 +08:00
|
|
|
await sleep(20);
|
2019-12-24 11:59:17 +08:00
|
|
|
wrapper.update();
|
|
|
|
expect(wrapper.find('p').text()).toEqual(fullStr + suffix);
|
|
|
|
|
|
|
|
wrapper.unmount();
|
|
|
|
});
|
|
|
|
|
2020-03-20 15:07:47 +08:00
|
|
|
it('connect children', async () => {
|
2019-10-01 14:06:09 +08:00
|
|
|
const bamboo = 'Bamboo';
|
|
|
|
const is = ' is ';
|
|
|
|
|
2019-02-19 11:42:05 +08:00
|
|
|
const wrapper = mount(
|
|
|
|
<Base ellipsis component="p" editable>
|
2019-10-01 14:06:09 +08:00
|
|
|
{bamboo}
|
|
|
|
{is}
|
2019-02-19 11:42:05 +08:00
|
|
|
<code>Little</code>
|
|
|
|
<code>Light</code>
|
|
|
|
</Base>,
|
|
|
|
);
|
|
|
|
|
2020-03-20 15:07:47 +08:00
|
|
|
await sleep(20);
|
2019-02-19 11:42:05 +08:00
|
|
|
wrapper.update();
|
|
|
|
|
2019-08-13 14:07:17 +08:00
|
|
|
expect(wrapper.find('span:not(.anticon)').text()).toEqual('Bamboo is Little...');
|
2019-02-19 11:42:05 +08:00
|
|
|
});
|
|
|
|
|
2020-03-20 15:07:47 +08:00
|
|
|
it('should expandable work', async () => {
|
2019-02-19 11:42:05 +08:00
|
|
|
const onExpand = jest.fn();
|
|
|
|
const wrapper = mount(
|
|
|
|
<Base ellipsis={{ expandable: true, onExpand }} component="p" copyable editable>
|
|
|
|
{fullStr}
|
|
|
|
</Base>,
|
|
|
|
);
|
|
|
|
|
2020-03-20 15:07:47 +08:00
|
|
|
await sleep(20);
|
2019-02-19 11:42:05 +08:00
|
|
|
wrapper.update();
|
|
|
|
|
|
|
|
wrapper.find('.ant-typography-expand').simulate('click');
|
2019-04-03 15:54:26 +08:00
|
|
|
expect(onExpand).toHaveBeenCalled();
|
2020-03-20 15:07:47 +08:00
|
|
|
await sleep(20);
|
2019-02-19 11:42:05 +08:00
|
|
|
wrapper.update();
|
|
|
|
|
|
|
|
expect(wrapper.find('p').text()).toEqual(fullStr);
|
|
|
|
});
|
|
|
|
|
2020-05-26 11:54:52 +08:00
|
|
|
it('should have custom expand style', async () => {
|
|
|
|
const symbol = 'more';
|
2020-09-16 16:00:12 +08:00
|
|
|
const wrapper = mount(<Base ellipsis={{ expandable: true, symbol }} component="p"></Base>);
|
2020-05-26 11:54:52 +08:00
|
|
|
|
|
|
|
await sleep(20);
|
|
|
|
wrapper.update();
|
|
|
|
});
|
|
|
|
|
2019-02-19 11:42:05 +08:00
|
|
|
it('can use css ellipsis', () => {
|
|
|
|
const wrapper = mount(<Base ellipsis component="p" />);
|
|
|
|
expect(wrapper.find('.ant-typography-ellipsis-single-line').length).toBeTruthy();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('copyable', () => {
|
2020-08-09 12:56:35 +08:00
|
|
|
function copyTest(name, text, target, icon, tooltips) {
|
2020-08-18 16:14:14 +08:00
|
|
|
it(name, async () => {
|
2020-03-20 15:07:47 +08:00
|
|
|
jest.useFakeTimers();
|
2019-02-19 11:42:05 +08:00
|
|
|
const onCopy = jest.fn();
|
|
|
|
const wrapper = mount(
|
2020-08-09 12:56:35 +08:00
|
|
|
<Base component="p" copyable={{ text, onCopy, icon, tooltips }}>
|
2019-02-19 11:42:05 +08:00
|
|
|
test copy
|
|
|
|
</Base>,
|
|
|
|
);
|
|
|
|
|
2020-08-09 12:56:35 +08:00
|
|
|
if (icon) {
|
|
|
|
expect(wrapper.find('.anticon-smile').length).toBeTruthy();
|
|
|
|
} else {
|
|
|
|
expect(wrapper.find('.anticon-copy').length).toBeTruthy();
|
|
|
|
}
|
|
|
|
|
|
|
|
wrapper.find('.ant-typography-copy').first().simulate('mouseenter');
|
|
|
|
jest.runAllTimers();
|
|
|
|
wrapper.update();
|
|
|
|
|
|
|
|
if (tooltips === undefined || tooltips === true) {
|
|
|
|
expect(wrapper.find('.ant-tooltip-inner').text()).toBe('Copy');
|
|
|
|
} else if (tooltips === false) {
|
|
|
|
expect(wrapper.find('.ant-tooltip-inner').length).toBeFalsy();
|
2020-08-18 16:14:14 +08:00
|
|
|
} else if (tooltips[0] === '' && tooltips[1] === '') {
|
|
|
|
expect(wrapper.find('.ant-tooltip-inner').length).toBeFalsy();
|
|
|
|
} else if (tooltips[0] === '' && tooltips[1]) {
|
|
|
|
expect(wrapper.find('.ant-tooltip-inner').length).toBeFalsy();
|
|
|
|
} else if (tooltips[1] === '' && tooltips[0]) {
|
|
|
|
expect(wrapper.find('.ant-tooltip-inner').text()).toBe(tooltips[0]);
|
2020-08-09 12:56:35 +08:00
|
|
|
} else {
|
|
|
|
expect(wrapper.find('.ant-tooltip-inner').text()).toBe(tooltips[0]);
|
|
|
|
}
|
|
|
|
|
2020-04-21 10:13:57 +08:00
|
|
|
wrapper.find('.ant-typography-copy').first().simulate('click');
|
2020-08-18 16:14:14 +08:00
|
|
|
jest.useRealTimers();
|
|
|
|
wrapper.find('.ant-typography-copy').first().simulate('mouseenter');
|
|
|
|
// tooltips 为 ['', 'xxx'] 时,切换时需要延时 mousenEnterDelay 的时长
|
|
|
|
if (tooltips && tooltips[0] === '' && tooltips[1]) {
|
|
|
|
await sleep(150);
|
|
|
|
}
|
2019-02-19 11:42:05 +08:00
|
|
|
|
2020-08-18 16:14:14 +08:00
|
|
|
expect(copy.lastStr).toEqual(target);
|
2019-02-19 11:42:05 +08:00
|
|
|
wrapper.update();
|
2019-04-03 15:54:26 +08:00
|
|
|
expect(onCopy).toHaveBeenCalled();
|
2019-02-19 11:42:05 +08:00
|
|
|
|
2020-08-09 12:56:35 +08:00
|
|
|
let copiedIcon = '.anticon-check';
|
|
|
|
if (icon && icon.length > 1) {
|
|
|
|
copiedIcon = '.anticon-like';
|
|
|
|
} else {
|
|
|
|
copiedIcon = '.anticon-check';
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(wrapper.find(copiedIcon).length).toBeTruthy();
|
2020-08-18 16:14:14 +08:00
|
|
|
wrapper.find('.ant-typography-copy').first().simulate('mouseenter');
|
2020-08-09 12:56:35 +08:00
|
|
|
|
|
|
|
if (tooltips === undefined || tooltips === true) {
|
|
|
|
expect(wrapper.find('.ant-tooltip-inner').text()).toBe('Copied');
|
|
|
|
} else if (tooltips === false) {
|
|
|
|
expect(wrapper.find('.ant-tooltip-inner').length).toBeFalsy();
|
2020-08-18 16:14:14 +08:00
|
|
|
} else if (tooltips[0] === '' && tooltips[1] === '') {
|
|
|
|
expect(wrapper.find('.ant-tooltip-inner').length).toBeFalsy();
|
|
|
|
} else if (tooltips[0] === '' && tooltips[1]) {
|
|
|
|
expect(wrapper.find('.ant-tooltip-inner').text()).toBe(tooltips[1]);
|
|
|
|
} else if (tooltips[1] === '' && tooltips[0]) {
|
|
|
|
expect(wrapper.find('.ant-tooltip-inner').text()).toBe('');
|
2020-08-09 12:56:35 +08:00
|
|
|
} else {
|
|
|
|
expect(wrapper.find('.ant-tooltip-inner').text()).toBe(tooltips[1]);
|
|
|
|
}
|
2019-02-19 11:42:05 +08:00
|
|
|
|
2020-08-18 16:14:14 +08:00
|
|
|
jest.useFakeTimers();
|
2019-02-19 11:42:05 +08:00
|
|
|
jest.runAllTimers();
|
|
|
|
wrapper.update();
|
|
|
|
|
|
|
|
// Will set back when 3 seconds pass
|
2020-08-09 12:56:35 +08:00
|
|
|
expect(wrapper.find(copiedIcon).length).toBeFalsy();
|
2020-08-18 16:14:14 +08:00
|
|
|
wrapper.unmount();
|
2020-03-20 15:07:47 +08:00
|
|
|
jest.useRealTimers();
|
2019-02-19 11:42:05 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
copyTest('basic copy', undefined, 'test copy');
|
|
|
|
copyTest('customize copy', 'bamboo', 'bamboo');
|
2020-08-09 12:56:35 +08:00
|
|
|
copyTest('customize copy icon', 'bamboo', 'bamboo', <SmileOutlined />);
|
|
|
|
copyTest('customize copy icon by pass array', 'bamboo', 'bamboo', [
|
|
|
|
<SmileOutlined key="copy-icon" />,
|
|
|
|
]);
|
|
|
|
copyTest('customize copy icon and copied icon ', 'bamboo', 'bamboo', [
|
|
|
|
<SmileOutlined key="copy-icon" />,
|
|
|
|
<LikeOutlined key="copied-icon" />,
|
|
|
|
]);
|
|
|
|
copyTest('customize copy show tooltips', 'bamboo', 'bamboo', undefined, true);
|
|
|
|
copyTest('customize copy hide tooltips', 'bamboo', 'bamboo', undefined, false);
|
|
|
|
copyTest('customize copy tooltips text', 'bamboo', 'bamboo', undefined, [
|
|
|
|
'click here',
|
|
|
|
'you clicked!!',
|
|
|
|
]);
|
2020-08-18 16:14:14 +08:00
|
|
|
copyTest('tooltips contains two empty text', 'bamboo', 'bamboo', undefined, ['', '']);
|
|
|
|
copyTest('tooltips contains one empty text', 'bamboo', 'bamboo', undefined, [
|
|
|
|
'',
|
|
|
|
'you clicked!!',
|
|
|
|
]);
|
|
|
|
copyTest('tooltips contains one empty text 2', 'bamboo', 'bamboo', undefined, [
|
|
|
|
'click here',
|
|
|
|
'',
|
|
|
|
]);
|
2019-02-19 11:42:05 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('editable', () => {
|
2020-08-09 12:56:35 +08:00
|
|
|
function testStep({ name = '', icon, tooltip } = {}, submitFunc, expectFunc) {
|
2019-02-19 11:42:05 +08:00
|
|
|
it(name, () => {
|
2020-08-09 12:56:35 +08:00
|
|
|
jest.useFakeTimers();
|
2019-02-19 11:42:05 +08:00
|
|
|
const onStart = jest.fn();
|
|
|
|
const onChange = jest.fn();
|
|
|
|
|
2019-04-25 17:42:59 +08:00
|
|
|
const className = 'test';
|
|
|
|
const style = {};
|
|
|
|
|
|
|
|
const wrapper = mount(
|
2020-08-09 12:56:35 +08:00
|
|
|
<Paragraph
|
|
|
|
editable={{ onChange, onStart, icon, tooltip }}
|
|
|
|
className={className}
|
|
|
|
style={style}
|
|
|
|
>
|
2019-04-25 17:42:59 +08:00
|
|
|
Bamboo
|
|
|
|
</Paragraph>,
|
|
|
|
);
|
2019-02-19 11:42:05 +08:00
|
|
|
|
2020-08-09 12:56:35 +08:00
|
|
|
if (icon) {
|
|
|
|
expect(wrapper.find('.anticon-highlight').length).toBeTruthy();
|
|
|
|
} else {
|
|
|
|
expect(wrapper.find('.anticon-edit').length).toBeTruthy();
|
|
|
|
}
|
|
|
|
|
|
|
|
wrapper.find('.ant-typography-edit').first().simulate('mouseenter');
|
|
|
|
jest.runAllTimers();
|
|
|
|
wrapper.update();
|
|
|
|
|
|
|
|
if (tooltip === undefined || tooltip === true) {
|
|
|
|
expect(wrapper.find('.ant-tooltip-inner').text()).toBe('Edit');
|
|
|
|
} else if (tooltip === false) {
|
|
|
|
expect(wrapper.find('.ant-tooltip-inner').length).toBeFalsy();
|
|
|
|
} else {
|
|
|
|
expect(wrapper.find('.ant-tooltip-inner').text()).toBe(tooltip);
|
|
|
|
}
|
|
|
|
|
2020-04-21 10:13:57 +08:00
|
|
|
wrapper.find('.ant-typography-edit').first().simulate('click');
|
2019-02-19 11:42:05 +08:00
|
|
|
|
2019-04-03 15:54:26 +08:00
|
|
|
expect(onStart).toHaveBeenCalled();
|
2019-02-19 11:42:05 +08:00
|
|
|
|
2019-04-25 17:42:59 +08:00
|
|
|
// Should have className
|
|
|
|
const props = wrapper.find('div').props();
|
|
|
|
expect(props.style).toEqual(style);
|
|
|
|
expect(props.className.includes(className)).toBeTruthy();
|
|
|
|
|
2020-06-13 14:24:56 +08:00
|
|
|
wrapper.find(TextArea).simulate('change', {
|
2019-02-19 11:42:05 +08:00
|
|
|
target: { value: 'Bamboo' },
|
|
|
|
});
|
|
|
|
|
2020-08-09 12:56:35 +08:00
|
|
|
if (submitFunc) {
|
|
|
|
submitFunc(wrapper);
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
2019-02-19 11:42:05 +08:00
|
|
|
|
|
|
|
if (expectFunc) {
|
|
|
|
expectFunc(onChange);
|
|
|
|
} else {
|
2019-04-03 15:54:26 +08:00
|
|
|
expect(onChange).toHaveBeenCalledWith('Bamboo');
|
2019-02-19 11:42:05 +08:00
|
|
|
expect(onChange).toHaveBeenCalledTimes(1);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-08-09 12:56:35 +08:00
|
|
|
testStep({ name: 'by key up' }, wrapper => {
|
2019-02-19 11:42:05 +08:00
|
|
|
// Not trigger when inComposition
|
2020-06-13 14:24:56 +08:00
|
|
|
wrapper.find(TextArea).simulate('compositionStart');
|
|
|
|
wrapper.find(TextArea).simulate('keyDown', { keyCode: KeyCode.ENTER });
|
|
|
|
wrapper.find(TextArea).simulate('compositionEnd');
|
|
|
|
wrapper.find(TextArea).simulate('keyUp', { keyCode: KeyCode.ENTER });
|
2019-02-19 11:42:05 +08:00
|
|
|
|
|
|
|
// Now trigger
|
2020-06-13 14:24:56 +08:00
|
|
|
wrapper.find(TextArea).simulate('keyDown', { keyCode: KeyCode.ENTER });
|
|
|
|
wrapper.find(TextArea).simulate('keyUp', { keyCode: KeyCode.ENTER });
|
2019-02-19 11:42:05 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
testStep(
|
2020-08-09 12:56:35 +08:00
|
|
|
{ name: 'by esc key' },
|
2019-02-19 11:42:05 +08:00
|
|
|
wrapper => {
|
2020-06-13 14:24:56 +08:00
|
|
|
wrapper.find(TextArea).simulate('keyDown', { keyCode: KeyCode.ESC });
|
|
|
|
wrapper.find(TextArea).simulate('keyUp', { keyCode: KeyCode.ESC });
|
2019-02-19 11:42:05 +08:00
|
|
|
},
|
|
|
|
onChange => {
|
2020-04-03 15:02:11 +08:00
|
|
|
// eslint-disable-next-line jest/no-standalone-expect
|
2019-04-03 15:54:26 +08:00
|
|
|
expect(onChange).not.toHaveBeenCalled();
|
2019-02-19 11:42:05 +08:00
|
|
|
},
|
|
|
|
);
|
|
|
|
|
2020-08-09 12:56:35 +08:00
|
|
|
testStep({ name: 'by blur' }, wrapper => {
|
2020-06-13 14:24:56 +08:00
|
|
|
wrapper.find(TextArea).simulate('blur');
|
2019-02-19 11:42:05 +08:00
|
|
|
});
|
2020-08-09 12:56:35 +08:00
|
|
|
|
|
|
|
testStep({ name: 'customize edit icon', icon: <HighlightOutlined /> });
|
|
|
|
testStep({ name: 'customize edit show tooltip', tooltip: true });
|
|
|
|
testStep({ name: 'customize edit hide tooltip', tooltip: false });
|
|
|
|
testStep({ name: 'customize edit tooltip text', tooltip: 'click to edit text' });
|
2019-02-19 11:42:05 +08:00
|
|
|
});
|
2020-02-07 13:15:24 +08:00
|
|
|
|
|
|
|
it('should focus at the end of textarea', () => {
|
|
|
|
const wrapper = mount(<Paragraph editable>content</Paragraph>);
|
2020-04-21 10:13:57 +08:00
|
|
|
wrapper.find('.ant-typography-edit').first().simulate('click');
|
2020-02-07 13:15:24 +08:00
|
|
|
const textareaNode = wrapper.find('textarea').getDOMNode();
|
|
|
|
expect(textareaNode.selectionStart).toBe(7);
|
|
|
|
expect(textareaNode.selectionEnd).toBe(7);
|
|
|
|
});
|
2019-02-19 11:42:05 +08:00
|
|
|
});
|
2019-10-01 14:06:09 +08:00
|
|
|
|
|
|
|
it('warning if use setContentRef', () => {
|
|
|
|
function refFunc() {}
|
|
|
|
mount(<Typography setContentRef={refFunc} />);
|
|
|
|
|
|
|
|
expect(errorSpy).toHaveBeenCalledWith(
|
|
|
|
'Warning: [antd: Typography] `setContentRef` is deprecated. Please use `ref` instead.',
|
|
|
|
);
|
|
|
|
});
|
2019-02-19 11:42:05 +08:00
|
|
|
});
|