A free and open-source block-based email template builder.
TypeScript amazonsesdeveloper-toolsemailemail-editoremail-marketingemail-templateemail-template-builderemailapiemailjshtml-email-editorno-codenocode-email-editoropen-source-email-buildersendgridtransactional-emailswysiwyg-email-editorwysiwyg-html-editor
import React from 'react';
import { describe, expect, it } from '@jest/globals';
import { render } from '@testing-library/react';
import { Text } from '.';
describe('block-text', () => {
it('renders with default values', () => {
expect(render(<Text />).asFragment()).toMatchSnapshot();
});
it('sanitizes HTML', () => {
expect(
render(
<Text
props={{
markdown: true,
text: `
<script>alert(1)</script>
<img src=x onerror=alert(1) />
[a](javascript:prompt(document.cookie))
[Basic](javascript:alert('Basic'))
[Local Storage](javascript:alert(JSON.stringify(localStorage)))
[CaseInsensitive](JaVaScRiPt:alert('CaseInsensitive'))
[URL](javascript://www.google.com%0Aalert('URL'))
[In Quotes]('javascript:alert("InQuotes")')
[a](j a v a s c r i p t:prompt(document.cookie))
[a](data:text/html;base64,PHNjcmlwdD5hbGVydCgnWFNTJyk8L3NjcmlwdD4K)
[a](javascript:window.onerror=alert;throw%201)
)
)
)
)
<div>
<img src />
<a>link 1</a>
<a href>link 2</a>
<a href="">link 3</a>
<a title>link 4</a>
<a title="">link 5</a>
<a href="ftp://domain.name">link 6</a>
<a href="javascript:alert('hello world')">link 7</a>
</div>
`,
}}
/>
).asFragment()
).toMatchSnapshot();
});
it('renders with safe markdown', () => {
expect(
render(
<Text
props={{
text: `This <span onClick="alert('!')">text</span> block has the **Markdown** option *turned on*.
- One
- Two
- Three
Powered by [Waypoint](https://usewaypoint.com)`,
markdown: true,
}}
/>
).asFragment()
).toMatchSnapshot();
});
it('renders without markdown', () => {
expect(
render(
<Text
props={{
text: `## This is not <span>markdown</span>`,
}}
/>
).asFragment()
).toMatchSnapshot();
});
});