mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-02 03:59:01 +08:00
test: add test codecov & fix demo ts (#38398)
* test: add codecov * type: optimization type * fix: fix type * fix: fix type * fix: fix type * fix: fix type
This commit is contained in:
parent
3579f44f50
commit
7cba2904dd
@ -16,7 +16,7 @@ Implement resizable column by integrate with [react-resizable](https://github.co
|
||||
|
||||
```tsx
|
||||
import { Table } from 'antd';
|
||||
import type { ColumnsType, ColumnType } from 'antd/es/table';
|
||||
import type { ColumnsType } from 'antd/es/table';
|
||||
import React, { useState } from 'react';
|
||||
import type { ResizeCallbackData } from 'react-resizable';
|
||||
import { Resizable } from 'react-resizable';
|
||||
@ -127,9 +127,9 @@ const App: React.FC = () => {
|
||||
|
||||
const mergeColumns: ColumnsType<DataType> = columns.map((col, index) => ({
|
||||
...col,
|
||||
onHeaderCell: column => ({
|
||||
width: (column as ColumnType<DataType>).width,
|
||||
onResize: handleResize(index),
|
||||
onHeaderCell: (column: ColumnsType<DataType>[number]) => ({
|
||||
width: column.width,
|
||||
onResize: handleResize(index) as React.ReactEventHandler<any>,
|
||||
}),
|
||||
}));
|
||||
|
||||
|
@ -8,7 +8,7 @@ import useStyle from './style';
|
||||
|
||||
export interface PurePanelProps extends TourStepProps {}
|
||||
|
||||
export default function PurePanel(props: PurePanelProps) {
|
||||
const PurePanel: React.FC<PurePanelProps> = props => {
|
||||
const {
|
||||
prefixCls: customizePrefixCls,
|
||||
current = 0,
|
||||
@ -46,4 +46,6 @@ export default function PurePanel(props: PurePanelProps) {
|
||||
);
|
||||
|
||||
// return node as React.ReactElement;
|
||||
}
|
||||
};
|
||||
|
||||
export default PurePanel;
|
||||
|
@ -3,6 +3,7 @@ import Tour from '..';
|
||||
import mountTest from '../../../tests/shared/mountTest';
|
||||
import rtlTest from '../../../tests/shared/rtlTest';
|
||||
import { fireEvent, render, screen } from '../../../tests/utils';
|
||||
import panelRender from '../panelRender';
|
||||
|
||||
describe('Tour', () => {
|
||||
mountTest(Tour);
|
||||
@ -10,19 +11,18 @@ describe('Tour', () => {
|
||||
|
||||
it('single', () => {
|
||||
const App: React.FC = () => {
|
||||
const coverBtnRef = useRef<any>();
|
||||
const coverBtnRef = useRef<HTMLButtonElement>(null);
|
||||
return (
|
||||
<>
|
||||
<button disabled ref={coverBtnRef} type="button">
|
||||
Cover
|
||||
</button>
|
||||
|
||||
<Tour
|
||||
steps={[
|
||||
{
|
||||
title: 'cover title',
|
||||
description: 'cover description.',
|
||||
target: () => coverBtnRef.current,
|
||||
target: () => coverBtnRef.current!,
|
||||
},
|
||||
]}
|
||||
/>
|
||||
@ -37,7 +37,7 @@ describe('Tour', () => {
|
||||
|
||||
it('steps is empty', () => {
|
||||
const App: React.FC = () => {
|
||||
const coverBtnRef = useRef<any>();
|
||||
const coverBtnRef = useRef<HTMLButtonElement>(null);
|
||||
return (
|
||||
<>
|
||||
<button disabled ref={coverBtnRef} type="button">
|
||||
@ -56,7 +56,7 @@ describe('Tour', () => {
|
||||
const onClickMock = jest.fn();
|
||||
const stepRenderMock = jest.fn();
|
||||
const App: React.FC = () => {
|
||||
const coverBtnRef = useRef<any>();
|
||||
const coverBtnRef = useRef<HTMLButtonElement>(null);
|
||||
return (
|
||||
<>
|
||||
<button disabled ref={coverBtnRef} type="button">
|
||||
@ -107,7 +107,7 @@ describe('Tour', () => {
|
||||
|
||||
it('button props onClick', () => {
|
||||
const App: React.FC = () => {
|
||||
const coverBtnRef = useRef<any>();
|
||||
const coverBtnRef = useRef<HTMLButtonElement>(null);
|
||||
const [btnName, steBtnName] = React.useState<string>('defaultBtn');
|
||||
return (
|
||||
<>
|
||||
@ -121,14 +121,14 @@ describe('Tour', () => {
|
||||
{
|
||||
title: '',
|
||||
description: '',
|
||||
target: () => coverBtnRef.current,
|
||||
target: () => coverBtnRef.current!,
|
||||
nextButtonProps: {
|
||||
onClick: () => steBtnName('nextButton'),
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '',
|
||||
target: () => coverBtnRef.current,
|
||||
target: () => coverBtnRef.current!,
|
||||
prevButtonProps: {
|
||||
onClick: () => steBtnName('prevButton'),
|
||||
},
|
||||
@ -154,7 +154,7 @@ describe('Tour', () => {
|
||||
|
||||
it('Primary', () => {
|
||||
const App: React.FC = () => {
|
||||
const coverBtnRef = useRef<any>();
|
||||
const coverBtnRef = useRef<HTMLButtonElement>(null);
|
||||
return (
|
||||
<>
|
||||
<button disabled ref={coverBtnRef} type="button">
|
||||
@ -167,7 +167,7 @@ describe('Tour', () => {
|
||||
{
|
||||
title: 'primary title',
|
||||
description: 'primary description.',
|
||||
target: () => coverBtnRef.current,
|
||||
target: () => coverBtnRef.current!,
|
||||
},
|
||||
]}
|
||||
/>
|
||||
@ -182,10 +182,10 @@ describe('Tour', () => {
|
||||
|
||||
it('basic', () => {
|
||||
const App: React.FC = () => {
|
||||
const coverBtnRef = useRef<any>(null);
|
||||
const placementBtnRef = useRef<any>(null);
|
||||
const coverBtnRef = useRef<HTMLButtonElement>(null);
|
||||
const placementBtnRef = useRef<HTMLButtonElement>(null);
|
||||
|
||||
const [show, setShow] = React.useState<boolean | undefined>();
|
||||
const [show, setShow] = React.useState<boolean>();
|
||||
|
||||
useEffect(() => {
|
||||
if (show === false) {
|
||||
@ -223,7 +223,7 @@ describe('Tour', () => {
|
||||
{
|
||||
title: 'With Cover',
|
||||
description: 'Here is the content of Tour.',
|
||||
target: () => coverBtnRef.current,
|
||||
target: () => coverBtnRef.current!,
|
||||
cover: (
|
||||
<img
|
||||
alt="tour.png"
|
||||
@ -235,7 +235,7 @@ describe('Tour', () => {
|
||||
title: 'Adjust Placement',
|
||||
description: 'Here is the content of Tour which show on the right.',
|
||||
placement: 'right',
|
||||
target: () => placementBtnRef.current,
|
||||
target: () => placementBtnRef.current!,
|
||||
},
|
||||
]}
|
||||
/>
|
||||
@ -254,4 +254,9 @@ describe('Tour', () => {
|
||||
expect(container.querySelector('.ant-tour')).toBeFalsy();
|
||||
expect(container.firstChild).toMatchSnapshot();
|
||||
});
|
||||
it('panelRender should correct render when total is undefined', () => {
|
||||
expect(() => {
|
||||
panelRender({ total: undefined, title: <div>test</div> }, 0, 'default');
|
||||
}).not.toThrow();
|
||||
});
|
||||
});
|
||||
|
@ -8,11 +8,11 @@ import Button from '../button';
|
||||
import type { ButtonProps } from '../button';
|
||||
import defaultLocale from '../locale/en_US';
|
||||
|
||||
const panelRender: (
|
||||
step: TourStepProps,
|
||||
const panelRender = (
|
||||
props: TourStepProps,
|
||||
current: number,
|
||||
type: TourStepProps['type'],
|
||||
) => ReactNode = (props: TourStepProps, current: number, type) => {
|
||||
): ReactNode => {
|
||||
const {
|
||||
prefixCls,
|
||||
total = 1,
|
||||
|
Loading…
Reference in New Issue
Block a user