2022-10-10 14:15:08 +08:00
|
|
|
import React, { useEffect } from 'react';
|
2021-03-02 18:05:20 +08:00
|
|
|
import { Modal } from '../..';
|
2022-10-31 10:20:14 +08:00
|
|
|
import { waitFakeTimer, render, fireEvent } from '../../../tests/utils';
|
2022-06-22 14:57:09 +08:00
|
|
|
import ConfigProvider from '../../config-provider';
|
2022-12-09 15:04:08 +08:00
|
|
|
import zhCN from '../../locale/zh_CN';
|
2021-03-02 18:05:20 +08:00
|
|
|
|
2022-10-10 14:15:08 +08:00
|
|
|
const Demo: React.FC<{ type: string }> = ({ type }) => {
|
|
|
|
useEffect(() => {
|
|
|
|
if (type === 'dashboard') {
|
2021-03-02 18:05:20 +08:00
|
|
|
Modal.confirm({ title: 'Hello World!' });
|
|
|
|
}
|
2022-10-10 14:15:08 +08:00
|
|
|
}, []);
|
|
|
|
return null;
|
|
|
|
};
|
2021-03-02 18:05:20 +08:00
|
|
|
|
|
|
|
describe('Locale Provider demo', () => {
|
2022-04-06 11:07:15 +08:00
|
|
|
it('change type', async () => {
|
2021-03-02 18:05:20 +08:00
|
|
|
jest.useFakeTimers();
|
|
|
|
|
2022-08-23 21:50:45 +08:00
|
|
|
const BasicExample: React.FC = () => {
|
|
|
|
const [type, setType] = React.useState<string>('');
|
2021-03-02 18:05:20 +08:00
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<a className="about" onClick={() => setType('about')}>
|
|
|
|
about
|
|
|
|
</a>
|
|
|
|
<a className="dashboard" onClick={() => setType('dashboard')}>
|
|
|
|
dashboard
|
|
|
|
</a>
|
|
|
|
<div>
|
|
|
|
{type === 'about' && (
|
|
|
|
<ConfigProvider locale={zhCN}>
|
|
|
|
<Demo type="about" />
|
|
|
|
</ConfigProvider>
|
|
|
|
)}
|
|
|
|
{type === 'dashboard' && (
|
|
|
|
<ConfigProvider locale={zhCN}>
|
|
|
|
<Demo type="dashboard" />
|
|
|
|
</ConfigProvider>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
2022-08-23 21:50:45 +08:00
|
|
|
const { container } = render(<BasicExample />);
|
2022-04-06 11:07:15 +08:00
|
|
|
|
2022-08-23 21:50:45 +08:00
|
|
|
fireEvent.click(container.querySelector('.about')!);
|
2022-10-31 10:20:14 +08:00
|
|
|
await waitFakeTimer();
|
2022-04-06 11:07:15 +08:00
|
|
|
|
2022-08-23 21:50:45 +08:00
|
|
|
fireEvent.click(container.querySelector('.dashboard')!);
|
2022-10-31 10:20:14 +08:00
|
|
|
await waitFakeTimer();
|
2022-04-06 11:07:15 +08:00
|
|
|
|
2022-08-23 21:50:45 +08:00
|
|
|
expect(document.body.querySelectorAll('.ant-btn-primary span')[0]?.textContent).toBe('确 定');
|
2021-03-02 18:05:20 +08:00
|
|
|
Modal.destroyAll();
|
|
|
|
jest.useRealTimers();
|
|
|
|
});
|
|
|
|
});
|