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:
lijianan 2022-09-07 14:18:32 +08:00 committed by GitHub
parent 6c9a022ea7
commit f47535a153
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 25 additions and 13 deletions

View File

@ -14,7 +14,7 @@ import Header from '../Header';
describe('Calendar', () => {
mountTest(Calendar);
rtlTest(Calendar, true);
rtlTest(Calendar, { mockDate: true });
function openSelect(wrapper, className) {
wrapper.find(className).find('.ant-select-selector').simulate('mousedown');

View File

@ -15,7 +15,7 @@ import Header from '../Header';
describe('Calendar', () => {
mountTest(Calendar);
rtlTest(Calendar, true);
rtlTest(Calendar, { mockDate: true });
function openSelect(wrapper: HTMLElement, className: string) {
fireEvent.mouseDown(wrapper.querySelector(className)!.querySelector('.ant-select-selector')!);

View File

@ -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`] = `
Array [
HTMLCollection [
<ul
class="ant-menu ant-menu-root ant-menu-vertical ant-menu-light ant-menu-rtl"
data-menu-list="true"

View File

@ -126,13 +126,15 @@ describe('Menu', () => {
</Menu>
));
rtlTest(() => (
const RtlDemo: React.FC = () => (
<Menu>
<Menu.Item />
<Menu.ItemGroup />
<Menu.SubMenu />
</Menu>
));
);
rtlTest(RtlDemo, { componentName: 'menu' });
let div: HTMLDivElement;

View File

@ -48,7 +48,8 @@ exports[`Transfer rtl render component should be rendered correctly in RTL direc
<span
class="ant-transfer-list-header-selected"
>
0 item
0
item
</span>
<span
class="ant-transfer-list-header-title"
@ -207,7 +208,8 @@ exports[`Transfer rtl render component should be rendered correctly in RTL direc
<span
class="ant-transfer-list-header-selected"
>
0 item
0
item
</span>
<span
class="ant-transfer-list-header-title"

View File

@ -20,7 +20,7 @@ export default function imageTest(component: React.ReactElement) {
await jestPuppeteer.resetPage();
await page.setRequestInterception(true);
const onRequestHandle = (request: any) => {
if (['image'].indexOf(request.resourceType()) !== -1) {
if (['image'].includes(request.resourceType())) {
request.abort();
} else {
request.continue();

View File

@ -1,25 +1,33 @@
import React from 'react';
import Moment from 'moment';
import MockDate from 'mockdate';
import { mount } from 'enzyme';
import { render } from '../utils';
import ConfigProvider from '../../components/config-provider';
// eslint-disable-next-line jest/no-export
export default function rtlTest(Component: React.ComponentType, mockDate?: boolean) {
interface TestOptions {
mockDate?: boolean;
componentName?: string;
}
function rtlTest(Component: React.ComponentType, { mockDate, componentName }: TestOptions = {}) {
describe(`rtl render`, () => {
it(`component should be rendered correctly in RTL direction`, () => {
const isArray = componentName && ['menu'].includes(componentName);
if (mockDate) {
MockDate.set(Moment('2000-09-28').valueOf());
}
const wrapper = mount(
const { container } = render(
<ConfigProvider direction="rtl">
<Component />
</ConfigProvider>,
);
expect(wrapper.render()).toMatchSnapshot();
expect(isArray ? container.children : container.firstChild).toMatchSnapshot();
if (mockDate) {
MockDate.reset();
}
});
});
}
// eslint-disable-next-line jest/no-export
export default rtlTest;