-
-
Notifications
You must be signed in to change notification settings - Fork 46.8k
/
index.test.tsx
70 lines (61 loc) · 2.27 KB
/
index.test.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import React from 'react';
import Watermark from '..';
import mountTest from '../../../tests/shared/mountTest';
import rtlTest from '../../../tests/shared/rtlTest';
import { render } from '../../../tests/utils';
describe('Watermark', () => {
mountTest(Watermark);
rtlTest(Watermark);
const mockSrcSet = jest.spyOn(Image.prototype, 'src', 'set');
beforeAll(() => {
mockSrcSet.mockImplementation(function fn() {
if (this.onload) {
this.onload();
}
});
});
afterAll(() => {
mockSrcSet.mockRestore();
});
it('The watermark should render successfully', () => {
const { container } = render(<Watermark className="watermark" content="Ant Design" />);
expect(container.querySelector('.watermark div')).toBeTruthy();
expect(container).toMatchSnapshot();
});
it('The offset should be correct', () => {
const { container } = render(
<Watermark
className="watermark"
offset={[200, 200]}
content={['Ant Design', 'Ant Design Pro']}
/>,
);
const target = container.querySelector('.watermark div') as HTMLDivElement;
expect(target.style.left).toBe('100px');
expect(target.style.top).toBe('100px');
expect(target.style.width).toBe('calc(100% - 100px)');
expect(target.style.height).toBe('calc(100% - 100px)');
expect(container).toMatchSnapshot();
});
it('Image watermark snapshot', () => {
const { container } = render(
<Watermark image="https://gw.alipayobjects.com/zos/bmw-prod/59a18171-ae17-4fc5-93a0-2645f64a3aca.svg" />,
);
expect(container).toMatchSnapshot();
});
it('MutationObserver should work properly', () => {
const { container } = render(<Watermark className="watermark" content="MutationObserver" />);
const target = container.querySelector('.watermark div') as HTMLDivElement;
target.style.zIndex = '0';
target.remove();
expect(container).toMatchSnapshot();
});
it('Observe the modification of data-watermark-id', () => {
const { container } = render(
<Watermark offset={[-200, -200]} className="watermark" content="MutationObserver" />,
);
const target = container.querySelector('.watermark div') as HTMLDivElement;
target.setAttribute('data-watermark-id', 'jfei');
expect(container).toMatchSnapshot();
});
});