import React from 'react';
import Watermark from '..';
import mountTest from '../../../tests/shared/mountTest';
import rtlTest from '../../../tests/shared/rtlTest';
import { render, waitFor } from '../../../tests/utils';
describe('Watermark', () => {
mountTest(Watermark);
rtlTest(Watermark);
const mockSrcSet = jest.spyOn(Image.prototype, 'src', 'set');
beforeAll(() => {
mockSrcSet.mockImplementation(function fn() {
this.onload?.();
});
});
afterAll(() => {
mockSrcSet.mockRestore();
});
it('The watermark should render successfully', () => {
const { container } = render();
expect(container.querySelector('.watermark div')).toBeTruthy();
expect(container).toMatchSnapshot();
});
it('The offset should be correct', () => {
const { container } = render(
,
);
const target = container.querySelector('.watermark div');
expect(target?.style.left).toBe('150px');
expect(target?.style.top).toBe('150px');
expect(target?.style.width).toBe('calc(100% - 150px)');
expect(target?.style.height).toBe('calc(100% - 150px)');
expect(container).toMatchSnapshot();
});
it('Interleaved watermark backgroundSize is correct', () => {
const { container } = render(
,
);
const target = container.querySelector('.watermark div');
expect(target?.style.backgroundSize).toBe('600px');
expect(container).toMatchSnapshot();
});
it('Image watermark snapshot', () => {
const { container } = render(
,
);
expect(container).toMatchSnapshot();
});
it('MutationObserver should work properly', async () => {
const { container } = render();
const target = container.querySelector('.watermark div');
target?.remove();
await waitFor(() => expect(target).toBeTruthy());
expect(container).toMatchSnapshot();
});
it('Observe the modification of style', async () => {
const { container } = render(
,
);
const target = container.querySelector('.watermark div');
target?.setAttribute('style', '');
await waitFor(() => expect(target).toBeTruthy());
expect(container).toMatchSnapshot();
});
});