test: move test cases to @testing/library for Image (#35806)

This commit is contained in:
yykoypj 2022-05-30 13:47:13 +08:00 committed by GitHub
parent b535068590
commit 8281c064cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,5 +1,5 @@
import React from 'react';
import { mount } from 'enzyme';
import { render, fireEvent } from '../../../tests/utils';
import Image from '..';
import mountTest from '../../../tests/shared/mountTest';
import rtlTest from '../../../tests/shared/rtlTest';
@ -10,49 +10,60 @@ describe('Image', () => {
mountTest(Image);
rtlTest(Image);
it('Image preview props set false', () => {
const wrapper = mount(<Image src={src} preview={false} />);
const { container: wrapper } = render(<Image src={src} preview={false} />);
expect(wrapper.find('Image').at(0).prop('preview')).toBe(false);
expect(wrapper.find('Image').at(1).prop('preview')).toBe(false);
fireEvent.click(wrapper.querySelector('.ant-image'));
expect(wrapper.querySelector('.ant-image-preview-root')).toBe(null);
});
it('Group preview props set false', () => {
const wrapper = mount(
const { container: wrapper } = render(
<Image.PreviewGroup preview={false}>
<Image src={src} />
</Image.PreviewGroup>,
);
expect(wrapper.find('Group').prop('preview')).toBe(false);
fireEvent.click(wrapper.querySelector('.ant-image'));
expect(wrapper.querySelector('.ant-image-preview-root')).toBe(null);
});
it('Default preview props', () => {
const wrapper = mount(<Image src={src} preview={{ visible: true }} />);
const { container: wrapper, baseElement } = render(
<Image src={src} preview={{ visible: true }} />,
);
expect(wrapper.find('Preview').prop('transitionName')).toBe('ant-zoom');
expect(wrapper.find('Preview').prop('maskTransitionName')).toBe('ant-fade');
fireEvent.click(wrapper.querySelector('.ant-image'));
expect(baseElement.querySelector('.ant-image-preview-mask')).toHaveClass('ant-fade');
expect(baseElement.querySelector('.ant-image-preview')).toHaveClass('ant-zoom');
});
it('Default Group preview props', () => {
const wrapper = mount(
const { container: wrapper, baseElement } = render(
<Image.PreviewGroup preview={{ visible: true }}>
<Image src={src} />
</Image.PreviewGroup>,
);
expect(wrapper.find('Preview').prop('transitionName')).toBe('ant-zoom');
expect(wrapper.find('Preview').prop('maskTransitionName')).toBe('ant-fade');
fireEvent.click(wrapper.querySelector('.ant-image'));
expect(baseElement.querySelector('.ant-image-preview-mask')).toHaveClass('ant-fade');
expect(baseElement.querySelector('.ant-image-preview')).toHaveClass('ant-zoom');
});
it('Customize preview props', () => {
const wrapper = mount(
const { container: wrapper, baseElement } = render(
<Image
src={src}
preview={{ visible: true, transitionName: 'abc', maskTransitionName: 'def' }}
/>,
);
expect(wrapper.find('Preview').prop('transitionName')).toBe('abc');
expect(wrapper.find('Preview').prop('maskTransitionName')).toBe('def');
fireEvent.click(wrapper.querySelector('.ant-image'));
expect(baseElement.querySelector('.ant-image-preview')).toHaveClass('abc');
expect(baseElement.querySelector('.ant-image-preview-mask')).toHaveClass('def');
});
it('Customize Group preview props', () => {
const wrapper = mount(
const { container: wrapper, baseElement } = render(
<Image.PreviewGroup
preview={{ visible: true, transitionName: 'abc', maskTransitionName: 'def' }}
>
@ -60,7 +71,9 @@ describe('Image', () => {
</Image.PreviewGroup>,
);
expect(wrapper.find('Preview').prop('transitionName')).toBe('abc');
expect(wrapper.find('Preview').prop('maskTransitionName')).toBe('def');
fireEvent.click(wrapper.querySelector('.ant-image'));
expect(baseElement.querySelector('.ant-image-preview')).toHaveClass('abc');
expect(baseElement.querySelector('.ant-image-preview-mask')).toHaveClass('def');
});
});