ant-design/components/locale-provider/__tests__/config.test.tsx
lijianan e084de38e8
refactor: CC => FC (#37886)
* fix: fix

* fix: fix

* fix: fix

* fix: fix

* fix: fix

* fix: fix

* fix: fix

* fix: fix

* fix: fix

* test: fix test

* fix: fix

* fix: fix

* fix: fix

* test: add test

* fix: fix test
2022-10-10 14:15:08 +08:00

65 lines
1.8 KiB
TypeScript

import React, { useEffect } from 'react';
import { act } from 'react-dom/test-utils';
import { Modal } from '../..';
import { sleep, render, fireEvent } from '../../../tests/utils';
import ConfigProvider from '../../config-provider';
import zhCN from '../zh_CN';
const Demo: React.FC<{ type: string }> = ({ type }) => {
useEffect(() => {
if (type === 'dashboard') {
Modal.confirm({ title: 'Hello World!' });
}
}, []);
return null;
};
describe('Locale Provider demo', () => {
it('change type', async () => {
jest.useFakeTimers();
const BasicExample: React.FC = () => {
const [type, setType] = React.useState<string>('');
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>
);
};
const { container } = render(<BasicExample />);
fireEvent.click(container.querySelector('.about')!);
await act(async () => {
jest.runAllTimers();
await sleep();
});
fireEvent.click(container.querySelector('.dashboard')!);
await act(async () => {
jest.runAllTimers();
await sleep();
});
expect(document.body.querySelectorAll('.ant-btn-primary span')[0]?.textContent).toBe('确 定');
Modal.destroyAll();
jest.useRealTimers();
});
});