mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-11 11:32:52 +08:00
type: type optimization (#38510)
This commit is contained in:
parent
07462491ab
commit
d52b8c6afb
@ -152,7 +152,7 @@ describe('Test utils function', () => {
|
|||||||
|
|
||||||
describe('TransButton', () => {
|
describe('TransButton', () => {
|
||||||
it('can be focus/blur', () => {
|
it('can be focus/blur', () => {
|
||||||
const ref = React.createRef<any>();
|
const ref = React.createRef<HTMLDivElement>();
|
||||||
render(<TransButton ref={ref}>TransButton</TransButton>);
|
render(<TransButton ref={ref}>TransButton</TransButton>);
|
||||||
expect(typeof ref.current?.focus).toBe('function');
|
expect(typeof ref.current?.focus).toBe('function');
|
||||||
expect(typeof ref.current?.blur).toBe('function');
|
expect(typeof ref.current?.blur).toBe('function');
|
||||||
|
@ -174,7 +174,7 @@ describe('Wave component', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('bindAnimationEvent should return when node is null', () => {
|
it('bindAnimationEvent should return when node is null', () => {
|
||||||
const ref = React.createRef<any>();
|
const ref = React.createRef<Wave>();
|
||||||
render(
|
render(
|
||||||
<Wave ref={ref}>
|
<Wave ref={ref}>
|
||||||
<button type="button" disabled>
|
<button type="button" disabled>
|
||||||
@ -186,7 +186,7 @@ describe('Wave component', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('bindAnimationEvent.onClick should return when children is hidden', () => {
|
it('bindAnimationEvent.onClick should return when children is hidden', () => {
|
||||||
const ref = React.createRef<any>();
|
const ref = React.createRef<Wave>();
|
||||||
render(
|
render(
|
||||||
<Wave ref={ref}>
|
<Wave ref={ref}>
|
||||||
<button type="button" style={{ display: 'none' }}>
|
<button type="button" style={{ display: 'none' }}>
|
||||||
@ -198,7 +198,7 @@ describe('Wave component', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('bindAnimationEvent.onClick should return when children is input', () => {
|
it('bindAnimationEvent.onClick should return when children is input', () => {
|
||||||
const ref = React.createRef<any>();
|
const ref = React.createRef<Wave>();
|
||||||
render(
|
render(
|
||||||
<Wave ref={ref}>
|
<Wave ref={ref}>
|
||||||
<input />
|
<input />
|
||||||
|
@ -160,7 +160,7 @@ class Wave extends React.Component<WaveProps> {
|
|||||||
: `${getPrefixCls('')}-click-animating-without-extra-node`;
|
: `${getPrefixCls('')}-click-animating-without-extra-node`;
|
||||||
}
|
}
|
||||||
|
|
||||||
bindAnimationEvent = (node: HTMLElement) => {
|
bindAnimationEvent = (node?: HTMLElement) => {
|
||||||
if (
|
if (
|
||||||
!node ||
|
!node ||
|
||||||
!node.getAttribute ||
|
!node.getAttribute ||
|
||||||
|
@ -2,6 +2,7 @@ import React from 'react';
|
|||||||
import { act } from 'react-dom/test-utils';
|
import { act } from 'react-dom/test-utils';
|
||||||
import ConfigProvider from '..';
|
import ConfigProvider from '..';
|
||||||
import { render } from '../../../tests/utils';
|
import { render } from '../../../tests/utils';
|
||||||
|
import type { FormInstance } from '../../form';
|
||||||
import Form from '../../form';
|
import Form from '../../form';
|
||||||
import zhCN from '../../locale/zh_CN';
|
import zhCN from '../../locale/zh_CN';
|
||||||
|
|
||||||
@ -16,7 +17,7 @@ describe('ConfigProvider.Form', () => {
|
|||||||
|
|
||||||
describe('form validateMessages', () => {
|
describe('form validateMessages', () => {
|
||||||
const renderComponent = ({ validateMessages }: { validateMessages?: any }) => {
|
const renderComponent = ({ validateMessages }: { validateMessages?: any }) => {
|
||||||
const formRef = React.createRef<any>();
|
const formRef = React.createRef<FormInstance>();
|
||||||
const { container } = render(
|
const { container } = render(
|
||||||
<ConfigProvider locale={zhCN} form={{ validateMessages }}>
|
<ConfigProvider locale={zhCN} form={{ validateMessages }}>
|
||||||
<Form ref={formRef} initialValues={{ age: 18 }}>
|
<Form ref={formRef} initialValues={{ age: 18 }}>
|
||||||
|
@ -3,6 +3,7 @@ import React from 'react';
|
|||||||
import Input from '..';
|
import Input from '..';
|
||||||
import { fireEvent, render } from '../../../tests/utils';
|
import { fireEvent, render } from '../../../tests/utils';
|
||||||
import type { InputRef } from '../Input';
|
import type { InputRef } from '../Input';
|
||||||
|
import type { TextAreaRef } from '../TextArea';
|
||||||
|
|
||||||
const { TextArea } = Input;
|
const { TextArea } = Input;
|
||||||
|
|
||||||
@ -49,7 +50,7 @@ describe('Input.Focus', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('all', () => {
|
it('all', () => {
|
||||||
const ref = React.createRef<any>();
|
const ref = React.createRef<TextAreaRef>();
|
||||||
render(<TextArea ref={ref} defaultValue="light" />);
|
render(<TextArea ref={ref} defaultValue="light" />);
|
||||||
ref.current!.focus({ cursor: 'all' });
|
ref.current!.focus({ cursor: 'all' });
|
||||||
|
|
||||||
|
@ -317,12 +317,12 @@ describe('Sider', () => {
|
|||||||
).toBeTruthy();
|
).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
['Layout', 'Header', 'Footer', 'Sider'].forEach(tag => {
|
(['Layout', 'Header', 'Footer', 'Sider'] as const).forEach(tag => {
|
||||||
const ComponentMap = { Layout, Header, Footer, Sider };
|
const ComponentMap = { Layout, Header, Footer, Sider };
|
||||||
it(`should get ${tag} element from ref`, () => {
|
it(`should get ${tag} element from ref`, () => {
|
||||||
const ref = React.createRef<any>();
|
const ref = React.createRef<HTMLDivElement>();
|
||||||
const onSelect = jest.fn();
|
const onSelect = jest.fn();
|
||||||
const Component = ComponentMap[tag as keyof typeof ComponentMap];
|
const Component = ComponentMap[tag];
|
||||||
render(
|
render(
|
||||||
<Component onSelect={onSelect} ref={ref}>
|
<Component onSelect={onSelect} ref={ref}>
|
||||||
{tag}
|
{tag}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import type { KeyWiseTransferItem } from '..';
|
||||||
import { render } from '../../../tests/utils';
|
import { render } from '../../../tests/utils';
|
||||||
import type { TransferListProps } from '../list';
|
import type { TransferListProps } from '../list';
|
||||||
|
import type TransferList from '../list';
|
||||||
import List from '../list';
|
import List from '../list';
|
||||||
|
|
||||||
const listCommonProps: TransferListProps<any> = {
|
const listCommonProps: TransferListProps<any> = {
|
||||||
@ -34,18 +36,22 @@ describe('Transfer.List', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('when component has been unmounted, componentWillUnmount should be called', () => {
|
it('when component has been unmounted, componentWillUnmount should be called', () => {
|
||||||
const instance = React.createRef<any>();
|
const instance = React.createRef<TransferList<KeyWiseTransferItem>>();
|
||||||
const { unmount } = render(<List ref={instance} {...listCommonProps} />);
|
const { unmount } = render(<List ref={instance} {...listCommonProps} />);
|
||||||
const willUnmount = jest.spyOn(instance.current, 'componentWillUnmount');
|
const willUnmount = jest.spyOn(instance.current!, 'componentWillUnmount');
|
||||||
unmount();
|
unmount();
|
||||||
expect(willUnmount).toHaveBeenCalled();
|
expect(willUnmount).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('when value is not exists, handleFilter should return', () => {
|
it('when value is not exists, handleFilter should return', () => {
|
||||||
const handleFilter = jest.fn();
|
const handleFilter = jest.fn();
|
||||||
const instance = React.createRef<any>();
|
const instance = React.createRef<TransferList<KeyWiseTransferItem>>();
|
||||||
render(<List ref={instance} {...listCommonProps} handleFilter={handleFilter} />);
|
render(<List ref={instance} {...listCommonProps} handleFilter={handleFilter} />);
|
||||||
expect(instance.current?.handleFilter({ target: 'test' })).toBe(undefined);
|
expect(
|
||||||
|
instance.current?.handleFilter({
|
||||||
|
target: 'test',
|
||||||
|
} as unknown as React.ChangeEvent<HTMLInputElement>),
|
||||||
|
).toBe(undefined);
|
||||||
expect(handleFilter).toHaveBeenCalled();
|
expect(handleFilter).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
it('should render correctly when dataSource is not exists', () => {
|
it('should render correctly when dataSource is not exists', () => {
|
||||||
|
@ -44,7 +44,7 @@ describe('Typography.Editable', () => {
|
|||||||
|
|
||||||
it('should use editConfig.text over children in editing mode ', async () => {
|
it('should use editConfig.text over children in editing mode ', async () => {
|
||||||
const suffix = '--The information is very important';
|
const suffix = '--The information is very important';
|
||||||
const ref = React.createRef<any>();
|
const ref = React.createRef<HTMLElement>();
|
||||||
const { container: wrapper, unmount } = render(
|
const { container: wrapper, unmount } = render(
|
||||||
<Base
|
<Base
|
||||||
ellipsis={{ rows: 1, suffix }}
|
ellipsis={{ rows: 1, suffix }}
|
||||||
@ -65,7 +65,7 @@ describe('Typography.Editable', () => {
|
|||||||
|
|
||||||
it('should use children as the fallback of editConfig.text in editing mode', async () => {
|
it('should use children as the fallback of editConfig.text in editing mode', async () => {
|
||||||
const suffix = '--The information is very important';
|
const suffix = '--The information is very important';
|
||||||
const ref = React.createRef<any>();
|
const ref = React.createRef<HTMLElement>();
|
||||||
const { container: wrapper, unmount } = render(
|
const { container: wrapper, unmount } = render(
|
||||||
<Base ellipsis={{ rows: 1, suffix }} component="p" ref={ref} editable>
|
<Base ellipsis={{ rows: 1, suffix }} component="p" ref={ref} editable>
|
||||||
{fullStr}
|
{fullStr}
|
||||||
|
@ -65,7 +65,7 @@ describe('Typography.Ellipsis', () => {
|
|||||||
'Bamboo is Little Light Bamboo is Little Light Bamboo is Little Light Bamboo is Little Light Bamboo is Little Light';
|
'Bamboo is Little Light Bamboo is Little Light Bamboo is Little Light Bamboo is Little Light Bamboo is Little Light';
|
||||||
|
|
||||||
it('should trigger update', async () => {
|
it('should trigger update', async () => {
|
||||||
const ref = React.createRef<any>();
|
const ref = React.createRef<HTMLElement>();
|
||||||
const onEllipsis = jest.fn();
|
const onEllipsis = jest.fn();
|
||||||
const { container, rerender, unmount } = render(
|
const { container, rerender, unmount } = render(
|
||||||
<Base ellipsis={{ onEllipsis }} component="p" editable ref={ref}>
|
<Base ellipsis={{ onEllipsis }} component="p" editable ref={ref}>
|
||||||
@ -73,7 +73,7 @@ describe('Typography.Ellipsis', () => {
|
|||||||
</Base>,
|
</Base>,
|
||||||
);
|
);
|
||||||
|
|
||||||
triggerResize(ref.current);
|
triggerResize(ref.current!);
|
||||||
await waitFakeTimer();
|
await waitFakeTimer();
|
||||||
|
|
||||||
expect(container.firstChild?.textContent).toEqual('Bamboo is Little ...');
|
expect(container.firstChild?.textContent).toEqual('Bamboo is Little ...');
|
||||||
@ -128,7 +128,7 @@ describe('Typography.Ellipsis', () => {
|
|||||||
design language for background applications, is refined by Ant UED Team.
|
design language for background applications, is refined by Ant UED Team.
|
||||||
Ant Design, a design language for background applications, is refined by
|
Ant Design, a design language for background applications, is refined by
|
||||||
Ant UED Team.`;
|
Ant UED Team.`;
|
||||||
const ref = React.createRef<any>();
|
const ref = React.createRef<HTMLElement>();
|
||||||
const onEllipsis = jest.fn();
|
const onEllipsis = jest.fn();
|
||||||
const { container: wrapper, unmount } = render(
|
const { container: wrapper, unmount } = render(
|
||||||
<Base ellipsis={{ onEllipsis }} component="p" editable ref={ref}>
|
<Base ellipsis={{ onEllipsis }} component="p" editable ref={ref}>
|
||||||
@ -136,7 +136,7 @@ describe('Typography.Ellipsis', () => {
|
|||||||
</Base>,
|
</Base>,
|
||||||
);
|
);
|
||||||
|
|
||||||
triggerResize(ref.current);
|
triggerResize(ref.current!);
|
||||||
await waitFakeTimer();
|
await waitFakeTimer();
|
||||||
|
|
||||||
expect(wrapper.firstChild?.textContent).toEqual('Ant Design, a des...');
|
expect(wrapper.firstChild?.textContent).toEqual('Ant Design, a des...');
|
||||||
@ -149,14 +149,14 @@ describe('Typography.Ellipsis', () => {
|
|||||||
|
|
||||||
it('should middle ellipsis', async () => {
|
it('should middle ellipsis', async () => {
|
||||||
const suffix = '--suffix';
|
const suffix = '--suffix';
|
||||||
const ref = React.createRef<any>();
|
const ref = React.createRef<HTMLElement>();
|
||||||
const { container: wrapper, unmount } = render(
|
const { container: wrapper, unmount } = render(
|
||||||
<Base ellipsis={{ rows: 1, suffix }} component="p" ref={ref}>
|
<Base ellipsis={{ rows: 1, suffix }} component="p" ref={ref}>
|
||||||
{fullStr}
|
{fullStr}
|
||||||
</Base>,
|
</Base>,
|
||||||
);
|
);
|
||||||
|
|
||||||
triggerResize(ref.current);
|
triggerResize(ref.current!);
|
||||||
await waitFakeTimer();
|
await waitFakeTimer();
|
||||||
|
|
||||||
expect(wrapper.querySelector('p')?.textContent).toEqual('Bamboo is...--suffix');
|
expect(wrapper.querySelector('p')?.textContent).toEqual('Bamboo is...--suffix');
|
||||||
@ -165,7 +165,7 @@ describe('Typography.Ellipsis', () => {
|
|||||||
|
|
||||||
it('should front or middle ellipsis', async () => {
|
it('should front or middle ellipsis', async () => {
|
||||||
const suffix = '--The information is very important';
|
const suffix = '--The information is very important';
|
||||||
const ref = React.createRef<any>();
|
const ref = React.createRef<HTMLElement>();
|
||||||
const {
|
const {
|
||||||
container: wrapper,
|
container: wrapper,
|
||||||
rerender,
|
rerender,
|
||||||
@ -176,7 +176,7 @@ describe('Typography.Ellipsis', () => {
|
|||||||
</Base>,
|
</Base>,
|
||||||
);
|
);
|
||||||
|
|
||||||
triggerResize(ref.current);
|
triggerResize(ref.current!);
|
||||||
await waitFakeTimer();
|
await waitFakeTimer();
|
||||||
|
|
||||||
expect(wrapper.querySelector('p')?.textContent).toEqual(
|
expect(wrapper.querySelector('p')?.textContent).toEqual(
|
||||||
@ -206,7 +206,7 @@ describe('Typography.Ellipsis', () => {
|
|||||||
const bamboo = 'Bamboo';
|
const bamboo = 'Bamboo';
|
||||||
const is = ' is ';
|
const is = ' is ';
|
||||||
|
|
||||||
const ref = React.createRef<any>();
|
const ref = React.createRef<HTMLElement>();
|
||||||
const { container: wrapper } = render(
|
const { container: wrapper } = render(
|
||||||
<Base ellipsis component="p" editable ref={ref}>
|
<Base ellipsis component="p" editable ref={ref}>
|
||||||
{bamboo}
|
{bamboo}
|
||||||
@ -216,7 +216,7 @@ describe('Typography.Ellipsis', () => {
|
|||||||
</Base>,
|
</Base>,
|
||||||
);
|
);
|
||||||
|
|
||||||
triggerResize(ref.current);
|
triggerResize(ref.current!);
|
||||||
await waitFakeTimer();
|
await waitFakeTimer();
|
||||||
|
|
||||||
expect(wrapper.textContent).toEqual('Bamboo is Little...');
|
expect(wrapper.textContent).toEqual('Bamboo is Little...');
|
||||||
@ -322,13 +322,13 @@ describe('Typography.Ellipsis', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
async function getWrapper(tooltip?: EllipsisConfig['tooltip']) {
|
async function getWrapper(tooltip?: EllipsisConfig['tooltip']) {
|
||||||
const ref = React.createRef<any>();
|
const ref = React.createRef<HTMLElement>();
|
||||||
const wrapper = render(
|
const wrapper = render(
|
||||||
<Base ellipsis={{ tooltip }} component="p" ref={ref}>
|
<Base ellipsis={{ tooltip }} component="p" ref={ref}>
|
||||||
{fullStr}
|
{fullStr}
|
||||||
</Base>,
|
</Base>,
|
||||||
);
|
);
|
||||||
triggerResize(ref.current);
|
triggerResize(ref.current!);
|
||||||
await waitFakeTimer();
|
await waitFakeTimer();
|
||||||
return wrapper;
|
return wrapper;
|
||||||
}
|
}
|
||||||
@ -419,13 +419,13 @@ describe('Typography.Ellipsis', () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const ref = React.createRef<any>();
|
const ref = React.createRef<HTMLElement>();
|
||||||
const { container, baseElement } = render(
|
const { container, baseElement } = render(
|
||||||
<Base component={undefined} ellipsis={{ tooltip: 'This is tooltip', rows: 2 }} ref={ref}>
|
<Base component={undefined} ellipsis={{ tooltip: 'This is tooltip', rows: 2 }} ref={ref}>
|
||||||
Ant Design, a design language for background applications, is refined by Ant UED Team.
|
Ant Design, a design language for background applications, is refined by Ant UED Team.
|
||||||
</Base>,
|
</Base>,
|
||||||
);
|
);
|
||||||
triggerResize(ref.current);
|
triggerResize(ref.current!);
|
||||||
await waitFakeTimer();
|
await waitFakeTimer();
|
||||||
|
|
||||||
fireEvent.mouseEnter(container.firstChild!);
|
fireEvent.mouseEnter(container.firstChild!);
|
||||||
|
@ -956,7 +956,7 @@ describe('Upload List', () => {
|
|||||||
originFileObj: renderInstance(),
|
originFileObj: renderInstance(),
|
||||||
};
|
};
|
||||||
delete file.thumbUrl;
|
delete file.thumbUrl;
|
||||||
const ref = React.createRef();
|
const ref = React.createRef<any>();
|
||||||
const { container: wrapper, unmount } = render(
|
const { container: wrapper, unmount } = render(
|
||||||
<Upload
|
<Upload
|
||||||
ref={ref}
|
ref={ref}
|
||||||
|
@ -50,7 +50,7 @@ const ComponentOverview = ({
|
|||||||
const [search, setSearch] = useState('');
|
const [search, setSearch] = useState('');
|
||||||
|
|
||||||
// keydown.enter goto first component
|
// keydown.enter goto first component
|
||||||
const sectionRef = React.createRef();
|
const sectionRef = React.useRef(null);
|
||||||
const onKeyDown = event => {
|
const onKeyDown = event => {
|
||||||
if (event.keyCode === 13 && search.trim().length) {
|
if (event.keyCode === 13 && search.trim().length) {
|
||||||
sectionRef.current?.querySelector('.components-overview-card')?.click();
|
sectionRef.current?.querySelector('.components-overview-card')?.click();
|
||||||
|
Loading…
Reference in New Issue
Block a user