Skip to content

Commit 1a04c20

Browse files
committed
add tests for some individual functions and comment others
1 parent f866627 commit 1a04c20

File tree

2 files changed

+133
-15
lines changed

2 files changed

+133
-15
lines changed

packages/render/src/shared/utils/__snapshots__/pretty.spec.ts.snap

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,66 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3+
exports[`lenientParse() > should parse base doucment correctly 1`] = `
4+
[
5+
{
6+
"content": "<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">",
7+
"type": "declaration",
8+
},
9+
{
10+
"children": [
11+
{
12+
"children": [],
13+
"name": "head",
14+
"properties": [],
15+
"type": "tag",
16+
"void": false,
17+
},
18+
{
19+
"children": [
20+
{
21+
"children": [
22+
{
23+
"content": "whatever",
24+
"type": "text",
25+
},
26+
],
27+
"name": "h1",
28+
"properties": [],
29+
"type": "tag",
30+
"void": false,
31+
},
32+
{
33+
"children": [],
34+
"name": "input",
35+
"properties": [
36+
{
37+
"name": "placeholder",
38+
"value": ""hello world"",
39+
},
40+
],
41+
"type": "tag",
42+
"void": true,
43+
},
44+
],
45+
"name": "body",
46+
"properties": [
47+
{
48+
"name": "style",
49+
"value": ""background-color:#fff;"",
50+
},
51+
],
52+
"type": "tag",
53+
"void": false,
54+
},
55+
],
56+
"name": "html",
57+
"properties": [],
58+
"type": "tag",
59+
"void": false,
60+
},
61+
]
62+
`;
63+
364
exports[`pretty > if mso syntax does not wrap 1`] = `
465
"<span
566
><!--[if mso]><i style="mso-font-width:100%;mso-text-raise:12" hidden>&#8202;&#8202;</i><![endif]--></span
@@ -161,3 +222,24 @@ exports[`pretty > should prettify Preview component's complex characters correct
161222
<!--/$-->
162223
"
163224
`;
225+
226+
exports[`wrapText() 1`] = `
227+
"Lorem
228+
ipsum
229+
dolor sit
230+
amet,
231+
consectetur
232+
adipiscing
233+
elit.
234+
Vestibulum
235+
tristique."
236+
`;
237+
238+
exports[`wrapText() 2`] = `
239+
" Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis laoreet
240+
tortor in orci ultricies, at fermentum nisl aliquam. Mauris ornare ut eros
241+
non vulputate. Aliquam quam massa, sagittis et nunc at, tincidunt vestibulum
242+
justo. Sed semper lectus a urna finibus congue. Aliquam erat volutpat. Lorem
243+
ipsum dolor sit amet, consectetur adipiscing elit. Proin molestie enim sed
244+
mauris ultrices interdum."
245+
`;
Lines changed: 51 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,58 @@
1-
import { promises as fs } from 'node:fs';
1+
import fs from 'node:fs';
22
import path from 'node:path';
3-
import { pretty } from './pretty';
3+
import { lenientParse, pretty, wrapText } from './pretty';
44

5-
describe('pretty', () => {
6-
it("should prettify Preview component's complex characters correctly", async () => {
7-
const stripeHTML = await fs.readFile(
8-
path.resolve(__dirname, './stripe-email.html'),
9-
'utf8',
10-
);
5+
const stripeHTML = fs.readFileSync(
6+
path.resolve(__dirname, './stripe-email.html'),
7+
'utf8',
8+
);
119

12-
expect(await pretty(stripeHTML)).toMatchSnapshot();
10+
describe('lenientParse()', () => {
11+
it('should parse base doucment correctly', () => {
12+
const document = `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html><head></head><body style="background-color:#fff;"><h1>whatever</h1><input placeholder="hello world"/></body></html>`;
13+
expect(lenientParse(document)).toMatchSnapshot();
1314
});
15+
});
1416

15-
test('if mso syntax does not wrap', async () => {
16-
expect(
17-
await pretty(
18-
`<span><!--[if mso]><i style="mso-font-width:100%;mso-text-raise:12" hidden>&#8202;&#8202;</i><![endif]--></span>`,
19-
),
20-
).toMatchSnapshot();
17+
describe('pretty', () => {
18+
it('should prettify base doucment correctly', () => {
19+
const document = `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html><head></head><body style="background-color:#fff;"><h1>whatever</h1><input placeholder="hello world"/></body></html>`;
20+
expect(pretty(document, { lineBreak: '\n' })).toBe('');
2121
});
22+
23+
// it("should prettify Preview component's complex characters correctly", async () => {
24+
// const stripeHTML = await fs.readFile(
25+
// path.resolve(__dirname, './stripe-email.html'),
26+
// 'utf8',
27+
// );
28+
//
29+
// expect(await pretty(stripeHTML)).toMatchSnapshot();
30+
// });
31+
//
32+
// test('if mso syntax does not wrap', async () => {
33+
// expect(
34+
// await pretty(
35+
// `<span><!--[if mso]><i style="mso-font-width:100%;mso-text-raise:12" hidden>&#8202;&#8202;</i><![endif]--></span>`,
36+
// ),
37+
// ).toMatchSnapshot();
38+
// });
39+
});
40+
41+
test('wrapText()', () => {
42+
expect(
43+
wrapText(
44+
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum tristique.',
45+
'',
46+
10,
47+
'\n',
48+
),
49+
).toMatchSnapshot();
50+
expect(
51+
wrapText(
52+
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis laoreet tortor in orci ultricies, at fermentum nisl aliquam. Mauris ornare ut eros non vulputate. Aliquam quam massa, sagittis et nunc at, tincidunt vestibulum justo. Sed semper lectus a urna finibus congue. Aliquam erat volutpat. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin molestie enim sed mauris ultrices interdum.',
53+
' ',
54+
78,
55+
'\n',
56+
),
57+
).toMatchSnapshot();
2258
});

0 commit comments

Comments
 (0)