Skip to content

Commit be2e19d

Browse files
committed
Cover cleanDocs with tests
1 parent 785a633 commit be2e19d

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

common/tests/unit/.keep

Whitespace-only changes.

common/tests/unit/cleanDoc.test.ts

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import {cleanDoc} from "../../src/util/parse";
2+
3+
describe('cleanDoc', () => {
4+
it('no change', () => {
5+
const doc = {
6+
"type": "doc",
7+
"content": [{
8+
"type": "paragraph",
9+
"content": [{"type": "text", "text": "Good morning Sir"}, {"type": "hardBreak"}]
10+
}, {
11+
"type": "paragraph",
12+
"content": [{
13+
"type": "text",
14+
"text": "Hello World"
15+
}]
16+
}]
17+
}
18+
const cleanedDoc = cleanDoc(doc)
19+
expect(cleanedDoc).toEqual(doc)
20+
})
21+
it('trims start hard breaks', () => {
22+
const doc = {
23+
"type": "doc",
24+
"content": [{
25+
"type": "paragraph",
26+
"content": [{"type": "hardBreak"}, {"type": "hardBreak"}, {"type": "text", "text": "Good morning Sir"}, {"type": "hardBreak"}]
27+
}, {
28+
"type": "paragraph",
29+
"content": [{
30+
"type": "text",
31+
"text": "Hello World"
32+
}]
33+
}]
34+
}
35+
const cleanedDoc = cleanDoc(doc)
36+
expect(cleanedDoc).toEqual({
37+
"type": "doc",
38+
"content": [{
39+
"type": "paragraph",
40+
"content": [{"type": "text", "text": "Good morning Sir"}, {"type": "hardBreak"}]
41+
}, {
42+
"type": "paragraph",
43+
"content": [{
44+
"type": "text",
45+
"text": "Hello World"
46+
}]
47+
}]
48+
})
49+
})
50+
it('trims end hard breaks', () => {
51+
const doc = {
52+
"type": "doc",
53+
"content": [{
54+
"type": "paragraph",
55+
"content": [{"type": "text", "text": "Good morning Sir"}, {"type": "hardBreak"}]
56+
}, {
57+
"type": "paragraph",
58+
"content": [{"type": "text", "text": "Hello World"}, {"type": "hardBreak"}, {"type": "hardBreak"}]
59+
}]
60+
}
61+
const cleanedDoc = cleanDoc(doc)
62+
expect(cleanedDoc).toEqual({
63+
"type": "doc",
64+
"content": [{
65+
"type": "paragraph",
66+
"content": [{"type": "text", "text": "Good morning Sir"}, {"type": "hardBreak"}]
67+
}, {
68+
"type": "paragraph",
69+
"content": [{
70+
"type": "text",
71+
"text": "Hello World"
72+
}]
73+
}]
74+
})
75+
})
76+
})

0 commit comments

Comments
 (0)