mirror of
https://github.com/ant-design/ant-design.git
synced 2025-01-18 22:36:31 +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', () => {
|
||||
mountTest(Calendar);
|
||||
rtlTest(Calendar, true);
|
||||
rtlTest(Calendar, { mockDate: true });
|
||||
|
||||
function openSelect(wrapper, className) {
|
||||
wrapper.find(className).find('.ant-select-selector').simulate('mousedown');
|
||||
|
@ -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')!);
|
||||
|
@ -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"
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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"
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user