-
Notifications
You must be signed in to change notification settings - Fork 264
Expand file tree
/
Copy pathSanitizedHtml.test.jsx
More file actions
36 lines (31 loc) · 1.32 KB
/
SanitizedHtml.test.jsx
File metadata and controls
36 lines (31 loc) · 1.32 KB
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
import { render, screen } from '@tests/utils/test-utils';
import { SanitizedHtml } from '../../../src/components/SanitizedHtml';
describe('SanitizedHtml', () => {
beforeEach(() => {
render(
<SanitizedHtml
data-testid="subject"
htmlString="
<b>Don't worry!</b>
<a>Some link</a>
<script data-testid='script' type='module'></script>"
ruleSet="iiif"
/>,
);
});
it('should render needed elements', () => {
expect(screen.getByTestId('subject')).toHaveProperty('tagName', 'SPAN');
});
it('should pass correct class name to root element', () => {
expect(screen.getByTestId('subject')).toHaveClass('mirador-third-party-html');
});
it('should pass sanitized html string to dangerouslySetInnerHTML attribute', () => {
expect(screen.getByTestId('subject').querySelector('script')).not.toBeInTheDocument(); // eslint-disable-line testing-library/no-node-access, testing-library/prefer-presence-queries
expect(screen.getByText('Don\'t worry!')).toBeInTheDocument();
expect(screen.getByText('Some link')).toHaveAttribute('target', '_blank');
expect(screen.getByText('Some link')).toHaveAttribute('rel', 'noopener noreferrer');
});
it('removes script tags', () => {
expect(screen.queryByTestId('script')).not.toBeInTheDocument();
});
});