mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-03 00:09:39 +08:00
c34caad24c
* test: js => ts * test: add test * fix: fix eslint error * test: add test case * fix: fix test error * fix: fix eslint error * fix: fix eslint error * fix: eslint error fix * fix: fallback eslint config & add test case * test: add all test case * fix: bugfix * fix: bugFix * fix: bugFix * fix: bugFix * fix: lint * fix: add React.createRef * fix: add breadcrumbName in Routes * fix: any commit for restart ci/cd * fix: remove type * fix: test fix * fix: test fix * fix: add ts-ignore for id * test: add Icon test case * test: remove ts-ignore * test: add Icon test case
91 lines
3.2 KiB
TypeScript
91 lines
3.2 KiB
TypeScript
import React from 'react';
|
|
import Image from '..';
|
|
import mountTest from '../../../tests/shared/mountTest';
|
|
import rtlTest from '../../../tests/shared/rtlTest';
|
|
import { fireEvent, render } from '../../../tests/utils';
|
|
import ConfigProvider from '../../config-provider';
|
|
|
|
const src = 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png';
|
|
|
|
describe('Image', () => {
|
|
mountTest(Image);
|
|
rtlTest(Image);
|
|
it('Image preview props set false', () => {
|
|
const { container } = render(<Image src={src} preview={false} />);
|
|
|
|
fireEvent.click(container.querySelector('.ant-image')!);
|
|
expect(container.querySelector('.ant-image-preview-root')).toBe(null);
|
|
});
|
|
it('Group preview props set false', () => {
|
|
const { container } = render(
|
|
<Image.PreviewGroup preview={false}>
|
|
<Image src={src} />
|
|
</Image.PreviewGroup>,
|
|
);
|
|
|
|
fireEvent.click(container.querySelector('.ant-image')!);
|
|
|
|
expect(container.querySelector('.ant-image-preview-root')).toBe(null);
|
|
});
|
|
|
|
it('Default preview props', () => {
|
|
const { container, baseElement } = render(<Image src={src} preview={{ visible: true }} />);
|
|
|
|
fireEvent.click(container.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 { container, baseElement } = render(
|
|
<Image.PreviewGroup preview={{ visible: true }}>
|
|
<Image src={src} />
|
|
</Image.PreviewGroup>,
|
|
);
|
|
|
|
fireEvent.click(container.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 { container, baseElement } = render(
|
|
<Image
|
|
src={src}
|
|
preview={{ visible: true, transitionName: 'abc', maskTransitionName: 'def' }}
|
|
/>,
|
|
);
|
|
|
|
fireEvent.click(container.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 { container, baseElement } = render(
|
|
<Image.PreviewGroup
|
|
preview={{ visible: true, transitionName: 'abc', maskTransitionName: 'def' }}
|
|
>
|
|
<Image src={src} />
|
|
</Image.PreviewGroup>,
|
|
);
|
|
|
|
fireEvent.click(container.querySelector('.ant-image')!);
|
|
|
|
expect(baseElement.querySelector('.ant-image-preview')).toHaveClass('abc');
|
|
expect(baseElement.querySelector('.ant-image-preview-mask')).toHaveClass('def');
|
|
});
|
|
it('ConfigProvider getPopupContainer', () => {
|
|
const { container, baseElement } = render(
|
|
<>
|
|
<div className="container" />
|
|
<ConfigProvider getPopupContainer={() => document.querySelector('.container')!}>
|
|
<Image src={src} />
|
|
</ConfigProvider>
|
|
</>,
|
|
);
|
|
fireEvent.click(container.querySelector('.ant-image')!);
|
|
expect(baseElement.querySelector('.container')?.children.length).not.toBe(0);
|
|
});
|
|
});
|