2021-02-20 22:24:44 +08:00
|
|
|
import React from 'react';
|
2023-11-24 16:17:52 +08:00
|
|
|
import { Modal } from 'antd';
|
|
|
|
|
2020-08-22 22:02:20 +08:00
|
|
|
import Image from '..';
|
|
|
|
import mountTest from '../../../tests/shared/mountTest';
|
|
|
|
import rtlTest from '../../../tests/shared/rtlTest';
|
2022-06-11 13:54:50 +08:00
|
|
|
import { fireEvent, render } from '../../../tests/utils';
|
|
|
|
import ConfigProvider from '../../config-provider';
|
2020-08-22 22:02:20 +08:00
|
|
|
|
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-09-05 19:41:32 +08:00
|
|
|
const { container } = render(<Image src={src} preview={false} />);
|
2021-02-22 16:03:04 +08:00
|
|
|
|
2022-09-05 19:41:32 +08:00
|
|
|
fireEvent.click(container.querySelector('.ant-image')!);
|
|
|
|
expect(container.querySelector('.ant-image-preview-root')).toBe(null);
|
2021-02-22 16:03:04 +08:00
|
|
|
});
|
|
|
|
it('Group preview props set false', () => {
|
2022-09-05 19:41:32 +08:00
|
|
|
const { container } = 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
|
|
|
|
2022-09-05 19:41:32 +08:00
|
|
|
fireEvent.click(container.querySelector('.ant-image')!);
|
2022-05-30 13:47:13 +08:00
|
|
|
|
2022-09-05 19:41:32 +08:00
|
|
|
expect(container.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-09-05 19:41:32 +08:00
|
|
|
const { container, baseElement } = render(<Image src={src} preview={{ visible: true }} />);
|
2022-05-30 13:47:13 +08:00
|
|
|
|
2022-09-05 19:41:32 +08:00
|
|
|
fireEvent.click(container.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-09-05 19:41:32 +08:00
|
|
|
const { container, baseElement } = render(
|
2021-02-20 22:24:44 +08:00
|
|
|
<Image.PreviewGroup preview={{ visible: true }}>
|
|
|
|
<Image src={src} />
|
|
|
|
</Image.PreviewGroup>,
|
|
|
|
);
|
|
|
|
|
2022-09-05 19:41:32 +08:00
|
|
|
fireEvent.click(container.querySelector('.ant-image')!);
|
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');
|
2022-11-12 21:05:31 +08:00
|
|
|
expect(baseElement).toMatchSnapshot();
|
2021-02-20 22:24:44 +08:00
|
|
|
});
|
|
|
|
it('Customize preview props', () => {
|
2022-09-05 19:41:32 +08:00
|
|
|
const { container, baseElement } = render(
|
2021-02-20 22:24:44 +08:00
|
|
|
<Image
|
|
|
|
src={src}
|
|
|
|
preview={{ visible: true, transitionName: 'abc', maskTransitionName: 'def' }}
|
|
|
|
/>,
|
|
|
|
);
|
|
|
|
|
2022-09-05 19:41:32 +08:00
|
|
|
fireEvent.click(container.querySelector('.ant-image')!);
|
2022-05-30 13:47:13 +08:00
|
|
|
|
|
|
|
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-09-05 19:41:32 +08:00
|
|
|
const { container, 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-09-05 19:41:32 +08:00
|
|
|
fireEvent.click(container.querySelector('.ant-image')!);
|
2022-05-30 13:47:13 +08:00
|
|
|
|
|
|
|
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
|
|
|
});
|
2022-06-11 13:54:50 +08:00
|
|
|
it('ConfigProvider getPopupContainer', () => {
|
2022-09-05 19:41:32 +08:00
|
|
|
const { container, baseElement } = render(
|
2022-06-11 13:54:50 +08:00
|
|
|
<>
|
|
|
|
<div className="container" />
|
2022-09-05 19:41:32 +08:00
|
|
|
<ConfigProvider getPopupContainer={() => document.querySelector('.container')!}>
|
2022-06-11 13:54:50 +08:00
|
|
|
<Image src={src} />
|
|
|
|
</ConfigProvider>
|
|
|
|
</>,
|
|
|
|
);
|
2022-09-05 19:41:32 +08:00
|
|
|
fireEvent.click(container.querySelector('.ant-image')!);
|
|
|
|
expect(baseElement.querySelector('.container')?.children.length).not.toBe(0);
|
2022-06-11 13:54:50 +08:00
|
|
|
});
|
2022-10-10 12:08:42 +08:00
|
|
|
it('Preview forceRender props', async () => {
|
2023-06-07 21:59:21 +08:00
|
|
|
const onLoadCb = jest.fn();
|
2022-10-10 12:08:42 +08:00
|
|
|
const PreviewImage: React.FC = () => (
|
|
|
|
<Image
|
|
|
|
preview={{
|
|
|
|
visible: false,
|
|
|
|
src,
|
|
|
|
forceRender: true,
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
const { baseElement } = render(<PreviewImage />);
|
|
|
|
expect(baseElement.querySelector('.ant-image-preview-root')).not.toBe(null);
|
|
|
|
baseElement.querySelector('.ant-image-preview-img')?.addEventListener('load', onLoadCb);
|
|
|
|
fireEvent.load(baseElement.querySelector('.ant-image-preview-img')!);
|
|
|
|
expect(onLoadCb).toHaveBeenCalled();
|
|
|
|
});
|
2023-03-16 09:53:57 +08:00
|
|
|
it('Preview should support rootClassName', () => {
|
|
|
|
const { container, baseElement } = render(
|
|
|
|
<Image.PreviewGroup preview={{ visible: true, rootClassName: 'test-root-class' }}>
|
|
|
|
<Image src={src} />
|
|
|
|
</Image.PreviewGroup>,
|
|
|
|
);
|
|
|
|
|
|
|
|
fireEvent.click(container.querySelector('.ant-image')!);
|
|
|
|
|
|
|
|
expect(baseElement.querySelector('.test-root-class')).toBeTruthy();
|
|
|
|
});
|
2023-11-24 16:17:52 +08:00
|
|
|
it('Image.PreviewGroup preview in a nested modal where z-index Settings should be correct', () => {
|
|
|
|
const App = () => (
|
|
|
|
<Modal open>
|
|
|
|
<Modal open>
|
|
|
|
<Modal open>
|
|
|
|
<Image
|
|
|
|
width={200}
|
|
|
|
src="https://gw.alipayobjects.com/zos/rmsportal/KDpgvguMpGfqaHPjicRK.svg"
|
|
|
|
preview={{
|
|
|
|
rootClassName: 'test-image-preview-class',
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
<Image.PreviewGroup
|
|
|
|
preview={{
|
|
|
|
rootClassName: 'test-image-preview-group-class',
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Image
|
|
|
|
width={200}
|
|
|
|
src="https://gw.alipayobjects.com/zos/rmsportal/KDpgvguMpGfqaHPjicRK.svg"
|
|
|
|
/>
|
|
|
|
<Image
|
|
|
|
width={200}
|
|
|
|
src="https://gw.alipayobjects.com/zos/antfincdn/aPkFc8Sj7n/method-draw-image.svg"
|
|
|
|
/>
|
|
|
|
</Image.PreviewGroup>
|
|
|
|
</Modal>
|
|
|
|
</Modal>
|
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
const { baseElement } = render(<App />);
|
|
|
|
|
|
|
|
fireEvent.click(baseElement.querySelector('.ant-image')!);
|
|
|
|
|
|
|
|
expect(
|
|
|
|
(
|
|
|
|
baseElement.querySelector(
|
|
|
|
'.test-image-preview-class .ant-image-preview-wrap',
|
|
|
|
) as HTMLElement
|
|
|
|
).style.zIndex,
|
|
|
|
).toBe('1301');
|
|
|
|
expect(
|
|
|
|
(
|
|
|
|
baseElement.querySelector(
|
|
|
|
'.test-image-preview-class.ant-image-preview-operations-wrapper',
|
|
|
|
) as HTMLElement
|
|
|
|
).style.zIndex,
|
|
|
|
).toBe('1302');
|
|
|
|
|
|
|
|
fireEvent.click(baseElement.querySelectorAll('.ant-image')[1]!);
|
|
|
|
|
|
|
|
expect(
|
|
|
|
(
|
|
|
|
baseElement.querySelector(
|
|
|
|
'.test-image-preview-group-class .ant-image-preview-wrap',
|
|
|
|
) as HTMLElement
|
|
|
|
).style.zIndex,
|
|
|
|
).toBe('1301');
|
|
|
|
expect(
|
|
|
|
(
|
|
|
|
baseElement.querySelector(
|
|
|
|
'.test-image-preview-group-class.ant-image-preview-operations-wrapper',
|
|
|
|
) as HTMLElement
|
|
|
|
).style.zIndex,
|
|
|
|
).toBe('1302');
|
|
|
|
});
|
2020-08-22 22:02:20 +08:00
|
|
|
});
|