mirror of
https://github.com/ant-design/ant-design.git
synced 2025-08-06 16:06:28 +08:00
test: migrate part of rtlTest tests (#37315)
* test: migrate part of rtlTest tests * style: performance optimize * fix: add type * fix: fallback
This commit is contained in:
parent
6c9a022ea7
commit
f47535a153
@ -14,7 +14,7 @@ import Header from '../Header';
|
|||||||
|
|
||||||
describe('Calendar', () => {
|
describe('Calendar', () => {
|
||||||
mountTest(Calendar);
|
mountTest(Calendar);
|
||||||
rtlTest(Calendar, true);
|
rtlTest(Calendar, { mockDate: true });
|
||||||
|
|
||||||
function openSelect(wrapper, className) {
|
function openSelect(wrapper, className) {
|
||||||
wrapper.find(className).find('.ant-select-selector').simulate('mousedown');
|
wrapper.find(className).find('.ant-select-selector').simulate('mousedown');
|
||||||
|
@ -15,7 +15,7 @@ import Header from '../Header';
|
|||||||
|
|
||||||
describe('Calendar', () => {
|
describe('Calendar', () => {
|
||||||
mountTest(Calendar);
|
mountTest(Calendar);
|
||||||
rtlTest(Calendar, true);
|
rtlTest(Calendar, { mockDate: true });
|
||||||
|
|
||||||
function openSelect(wrapper: HTMLElement, className: string) {
|
function openSelect(wrapper: HTMLElement, className: string) {
|
||||||
fireEvent.mouseDown(wrapper.querySelector(className)!.querySelector('.ant-select-selector')!);
|
fireEvent.mouseDown(wrapper.querySelector(className)!.querySelector('.ant-select-selector')!);
|
||||||
|
@ -324,7 +324,7 @@ exports[`Menu all types must be available in the "items" syntax 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`Menu rtl render component should be rendered correctly in RTL direction 1`] = `
|
exports[`Menu rtl render component should be rendered correctly in RTL direction 1`] = `
|
||||||
Array [
|
HTMLCollection [
|
||||||
<ul
|
<ul
|
||||||
class="ant-menu ant-menu-root ant-menu-vertical ant-menu-light ant-menu-rtl"
|
class="ant-menu ant-menu-root ant-menu-vertical ant-menu-light ant-menu-rtl"
|
||||||
data-menu-list="true"
|
data-menu-list="true"
|
||||||
|
@ -126,13 +126,15 @@ describe('Menu', () => {
|
|||||||
</Menu>
|
</Menu>
|
||||||
));
|
));
|
||||||
|
|
||||||
rtlTest(() => (
|
const RtlDemo: React.FC = () => (
|
||||||
<Menu>
|
<Menu>
|
||||||
<Menu.Item />
|
<Menu.Item />
|
||||||
<Menu.ItemGroup />
|
<Menu.ItemGroup />
|
||||||
<Menu.SubMenu />
|
<Menu.SubMenu />
|
||||||
</Menu>
|
</Menu>
|
||||||
));
|
);
|
||||||
|
|
||||||
|
rtlTest(RtlDemo, { componentName: 'menu' });
|
||||||
|
|
||||||
let div: HTMLDivElement;
|
let div: HTMLDivElement;
|
||||||
|
|
||||||
|
@ -48,7 +48,8 @@ exports[`Transfer rtl render component should be rendered correctly in RTL direc
|
|||||||
<span
|
<span
|
||||||
class="ant-transfer-list-header-selected"
|
class="ant-transfer-list-header-selected"
|
||||||
>
|
>
|
||||||
0 item
|
0
|
||||||
|
item
|
||||||
</span>
|
</span>
|
||||||
<span
|
<span
|
||||||
class="ant-transfer-list-header-title"
|
class="ant-transfer-list-header-title"
|
||||||
@ -207,7 +208,8 @@ exports[`Transfer rtl render component should be rendered correctly in RTL direc
|
|||||||
<span
|
<span
|
||||||
class="ant-transfer-list-header-selected"
|
class="ant-transfer-list-header-selected"
|
||||||
>
|
>
|
||||||
0 item
|
0
|
||||||
|
item
|
||||||
</span>
|
</span>
|
||||||
<span
|
<span
|
||||||
class="ant-transfer-list-header-title"
|
class="ant-transfer-list-header-title"
|
||||||
|
@ -20,7 +20,7 @@ export default function imageTest(component: React.ReactElement) {
|
|||||||
await jestPuppeteer.resetPage();
|
await jestPuppeteer.resetPage();
|
||||||
await page.setRequestInterception(true);
|
await page.setRequestInterception(true);
|
||||||
const onRequestHandle = (request: any) => {
|
const onRequestHandle = (request: any) => {
|
||||||
if (['image'].indexOf(request.resourceType()) !== -1) {
|
if (['image'].includes(request.resourceType())) {
|
||||||
request.abort();
|
request.abort();
|
||||||
} else {
|
} else {
|
||||||
request.continue();
|
request.continue();
|
||||||
|
@ -1,25 +1,33 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import Moment from 'moment';
|
import Moment from 'moment';
|
||||||
import MockDate from 'mockdate';
|
import MockDate from 'mockdate';
|
||||||
import { mount } from 'enzyme';
|
import { render } from '../utils';
|
||||||
import ConfigProvider from '../../components/config-provider';
|
import ConfigProvider from '../../components/config-provider';
|
||||||
|
|
||||||
// eslint-disable-next-line jest/no-export
|
interface TestOptions {
|
||||||
export default function rtlTest(Component: React.ComponentType, mockDate?: boolean) {
|
mockDate?: boolean;
|
||||||
|
componentName?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
function rtlTest(Component: React.ComponentType, { mockDate, componentName }: TestOptions = {}) {
|
||||||
describe(`rtl render`, () => {
|
describe(`rtl render`, () => {
|
||||||
it(`component should be rendered correctly in RTL direction`, () => {
|
it(`component should be rendered correctly in RTL direction`, () => {
|
||||||
|
const isArray = componentName && ['menu'].includes(componentName);
|
||||||
if (mockDate) {
|
if (mockDate) {
|
||||||
MockDate.set(Moment('2000-09-28').valueOf());
|
MockDate.set(Moment('2000-09-28').valueOf());
|
||||||
}
|
}
|
||||||
const wrapper = mount(
|
const { container } = render(
|
||||||
<ConfigProvider direction="rtl">
|
<ConfigProvider direction="rtl">
|
||||||
<Component />
|
<Component />
|
||||||
</ConfigProvider>,
|
</ConfigProvider>,
|
||||||
);
|
);
|
||||||
expect(wrapper.render()).toMatchSnapshot();
|
expect(isArray ? container.children : container.firstChild).toMatchSnapshot();
|
||||||
if (mockDate) {
|
if (mockDate) {
|
||||||
MockDate.reset();
|
MockDate.reset();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line jest/no-export
|
||||||
|
export default rtlTest;
|
||||||
|
Loading…
Reference in New Issue
Block a user