2021-02-20 22:24:44 +08:00
|
|
|
import React from 'react';
|
2022-05-30 13:47:13 +08:00
|
|
|
import { render, fireEvent } from '../../../tests/utils';
|
2020-08-22 22:02:20 +08:00
|
|
|
import Image from '..';
|
|
|
|
import mountTest from '../../../tests/shared/mountTest';
|
|
|
|
import rtlTest from '../../../tests/shared/rtlTest';
|
|
|
|
|
2021-02-20 22:24:44 +08:00
|
|
|
const src = 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png';
|
|
|
|
|
2020-08-22 22:02:20 +08:00
|
|
|
describe('Image', () => {
|
|
|
|
mountTest(Image);
|
|
|
|
rtlTest(Image);
|
2021-02-22 16:03:04 +08:00
|
|
|
it('Image preview props set false', () => {
|
2022-05-30 13:47:13 +08:00
|
|
|
const { container: wrapper } = render(<Image src={src} preview={false} />);
|
2021-02-22 16:03:04 +08:00
|
|
|
|
2022-05-30 13:47:13 +08:00
|
|
|
fireEvent.click(wrapper.querySelector('.ant-image'));
|
|
|
|
expect(wrapper.querySelector('.ant-image-preview-root')).toBe(null);
|
2021-02-22 16:03:04 +08:00
|
|
|
});
|
|
|
|
it('Group preview props set false', () => {
|
2022-05-30 13:47:13 +08:00
|
|
|
const { container: wrapper } = render(
|
2021-02-22 16:03:04 +08:00
|
|
|
<Image.PreviewGroup preview={false}>
|
|
|
|
<Image src={src} />
|
|
|
|
</Image.PreviewGroup>,
|
|
|
|
);
|
2022-05-30 13:47:13 +08:00
|
|
|
|
|
|
|
fireEvent.click(wrapper.querySelector('.ant-image'));
|
|
|
|
|
|
|
|
expect(wrapper.querySelector('.ant-image-preview-root')).toBe(null);
|
2021-02-22 16:03:04 +08:00
|
|
|
});
|
|
|
|
|
2021-02-20 22:24:44 +08:00
|
|
|
it('Default preview props', () => {
|
2022-05-30 13:47:13 +08:00
|
|
|
const { container: wrapper, baseElement } = render(
|
|
|
|
<Image src={src} preview={{ visible: true }} />,
|
|
|
|
);
|
|
|
|
|
|
|
|
fireEvent.click(wrapper.querySelector('.ant-image'));
|
2021-02-20 22:24:44 +08:00
|
|
|
|
2022-05-30 13:47:13 +08:00
|
|
|
expect(baseElement.querySelector('.ant-image-preview-mask')).toHaveClass('ant-fade');
|
|
|
|
expect(baseElement.querySelector('.ant-image-preview')).toHaveClass('ant-zoom');
|
2021-02-20 22:24:44 +08:00
|
|
|
});
|
|
|
|
it('Default Group preview props', () => {
|
2022-05-30 13:47:13 +08:00
|
|
|
const { container: wrapper, baseElement } = render(
|
2021-02-20 22:24:44 +08:00
|
|
|
<Image.PreviewGroup preview={{ visible: true }}>
|
|
|
|
<Image src={src} />
|
|
|
|
</Image.PreviewGroup>,
|
|
|
|
);
|
|
|
|
|
2022-05-30 13:47:13 +08:00
|
|
|
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');
|
2021-02-20 22:24:44 +08:00
|
|
|
});
|
|
|
|
it('Customize preview props', () => {
|
2022-05-30 13:47:13 +08:00
|
|
|
const { container: wrapper, baseElement } = render(
|
2021-02-20 22:24:44 +08:00
|
|
|
<Image
|
|
|
|
src={src}
|
|
|
|
preview={{ visible: true, transitionName: 'abc', maskTransitionName: 'def' }}
|
|
|
|
/>,
|
|
|
|
);
|
|
|
|
|
2022-05-30 13:47:13 +08:00
|
|
|
fireEvent.click(wrapper.querySelector('.ant-image'));
|
|
|
|
|
|
|
|
expect(baseElement.querySelector('.ant-image-preview')).toHaveClass('abc');
|
|
|
|
expect(baseElement.querySelector('.ant-image-preview-mask')).toHaveClass('def');
|
2021-02-20 22:24:44 +08:00
|
|
|
});
|
|
|
|
it('Customize Group preview props', () => {
|
2022-05-30 13:47:13 +08:00
|
|
|
const { container: wrapper, baseElement } = render(
|
2021-02-20 22:24:44 +08:00
|
|
|
<Image.PreviewGroup
|
|
|
|
preview={{ visible: true, transitionName: 'abc', maskTransitionName: 'def' }}
|
|
|
|
>
|
|
|
|
<Image src={src} />
|
|
|
|
</Image.PreviewGroup>,
|
|
|
|
);
|
|
|
|
|
2022-05-30 13:47:13 +08:00
|
|
|
fireEvent.click(wrapper.querySelector('.ant-image'));
|
|
|
|
|
|
|
|
expect(baseElement.querySelector('.ant-image-preview')).toHaveClass('abc');
|
|
|
|
expect(baseElement.querySelector('.ant-image-preview-mask')).toHaveClass('def');
|
2021-02-20 22:24:44 +08:00
|
|
|
});
|
2020-08-22 22:02:20 +08:00
|
|
|
});
|