import React, { useRef, useEffect } from 'react'; 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); rtlTest(Tour); it('single', () => { const App: React.FC = () => { const coverBtnRef = useRef(null); return ( <> coverBtnRef.current!, }, ]} /> ); }; const { getByText, container } = render(); expect(getByText('cover title')).toBeTruthy(); expect(getByText('cover description.')).toBeTruthy(); expect(container.firstChild).toMatchSnapshot(); }); it('steps is empty', () => { const App: React.FC = () => { const coverBtnRef = useRef(null); return ( <> ); }; const { container } = render(); expect(container.firstChild).toMatchSnapshot(); }); it('steps props stepRender', () => { const onClickMock = jest.fn(); const stepRenderMock = jest.fn(); const App: React.FC = () => { const coverBtnRef = useRef(null); return ( <> ); }; const { container } = render(); fireEvent.click(screen.getByRole('button', { name: 'Next' })); fireEvent.click(screen.getByRole('button', { name: 'Previous' })); fireEvent.click(screen.getByRole('button', { name: 'Next' })); fireEvent.click(screen.getByRole('button', { name: 'Next' })); fireEvent.click(screen.getByRole('button', { name: 'Finish' })); expect(onClickMock).toHaveBeenCalledTimes(5); expect(container.firstChild).toMatchSnapshot(); }); it('button props onClick', () => { const App: React.FC = () => { const coverBtnRef = useRef(null); const [btnName, steBtnName] = React.useState('defaultBtn'); return ( <> {btnName} coverBtnRef.current!, nextButtonProps: { onClick: () => steBtnName('nextButton'), }, }, { title: '', target: () => coverBtnRef.current!, prevButtonProps: { onClick: () => steBtnName('prevButton'), }, nextButtonProps: { onClick: () => steBtnName('finishButton'), }, }, ]} /> ); }; const { container } = render(); expect(container.querySelector('#btnName')).toHaveTextContent('defaultBtn'); fireEvent.click(screen.getByRole('button', { name: 'Next' })); expect(container.querySelector('#btnName')).toHaveTextContent('nextButton'); fireEvent.click(screen.getByRole('button', { name: 'Previous' })); expect(container.querySelector('#btnName')).toHaveTextContent('prevButton'); fireEvent.click(screen.getByRole('button', { name: 'Next' })); fireEvent.click(screen.getByRole('button', { name: 'Finish' })); expect(container.querySelector('#btnName')).toHaveTextContent('finishButton'); }); it('Primary', () => { const App: React.FC = () => { const coverBtnRef = useRef(null); return ( <> coverBtnRef.current!, }, ]} /> ); }; const { getByText, container } = render(); expect(getByText('primary description.')).toBeTruthy(); expect(container.querySelector('.ant-tour')).toHaveClass('ant-tour-primary'); expect(container.firstChild).toMatchSnapshot(); }); it('basic', () => { const App: React.FC = () => { const coverBtnRef = useRef(null); const placementBtnRef = useRef(null); const [show, setShow] = React.useState(); useEffect(() => { if (show === false) { setShow(true); } }, [show]); return ( <>
{show && ( coverBtnRef.current!, cover: ( tour.png ), }, { title: 'Adjust Placement', description: 'Here is the content of Tour which show on the right.', placement: 'right', target: () => placementBtnRef.current!, }, ]} /> )} ); }; const { getByText, container } = render(); fireEvent.click(screen.getByRole('button', { name: 'Show' })); expect(getByText('Show in Center')).toBeTruthy(); fireEvent.click(screen.getByRole('button', { name: 'Next' })); expect(getByText('Here is the content of Tour.')).toBeTruthy(); fireEvent.click(screen.getByRole('button', { name: 'Next' })); expect(getByText('Adjust Placement')).toBeTruthy(); fireEvent.click(screen.getByRole('button', { name: 'Finish' })); expect(container.querySelector('.ant-tour')).toBeFalsy(); expect(container.firstChild).toMatchSnapshot(); }); it('panelRender should correct render when total is undefined', () => { expect(() => { panelRender({ total: undefined, title:
test
}, 0, 'default'); }).not.toThrow(); }); });