mirror of
https://github.com/CompassConnections/Compass.git
synced 2026-04-29 02:34:17 -04:00
Cover cleanDocs with tests
This commit is contained in:
76
common/tests/unit/cleanDoc.test.ts
Normal file
76
common/tests/unit/cleanDoc.test.ts
Normal file
@@ -0,0 +1,76 @@
|
||||
import {cleanDoc} from "../../src/util/parse";
|
||||
|
||||
describe('cleanDoc', () => {
|
||||
it('no change', () => {
|
||||
const doc = {
|
||||
"type": "doc",
|
||||
"content": [{
|
||||
"type": "paragraph",
|
||||
"content": [{"type": "text", "text": "Good morning Sir"}, {"type": "hardBreak"}]
|
||||
}, {
|
||||
"type": "paragraph",
|
||||
"content": [{
|
||||
"type": "text",
|
||||
"text": "Hello World"
|
||||
}]
|
||||
}]
|
||||
}
|
||||
const cleanedDoc = cleanDoc(doc)
|
||||
expect(cleanedDoc).toEqual(doc)
|
||||
})
|
||||
it('trims start hard breaks', () => {
|
||||
const doc = {
|
||||
"type": "doc",
|
||||
"content": [{
|
||||
"type": "paragraph",
|
||||
"content": [{"type": "hardBreak"}, {"type": "hardBreak"}, {"type": "text", "text": "Good morning Sir"}, {"type": "hardBreak"}]
|
||||
}, {
|
||||
"type": "paragraph",
|
||||
"content": [{
|
||||
"type": "text",
|
||||
"text": "Hello World"
|
||||
}]
|
||||
}]
|
||||
}
|
||||
const cleanedDoc = cleanDoc(doc)
|
||||
expect(cleanedDoc).toEqual({
|
||||
"type": "doc",
|
||||
"content": [{
|
||||
"type": "paragraph",
|
||||
"content": [{"type": "text", "text": "Good morning Sir"}, {"type": "hardBreak"}]
|
||||
}, {
|
||||
"type": "paragraph",
|
||||
"content": [{
|
||||
"type": "text",
|
||||
"text": "Hello World"
|
||||
}]
|
||||
}]
|
||||
})
|
||||
})
|
||||
it('trims end hard breaks', () => {
|
||||
const doc = {
|
||||
"type": "doc",
|
||||
"content": [{
|
||||
"type": "paragraph",
|
||||
"content": [{"type": "text", "text": "Good morning Sir"}, {"type": "hardBreak"}]
|
||||
}, {
|
||||
"type": "paragraph",
|
||||
"content": [{"type": "text", "text": "Hello World"}, {"type": "hardBreak"}, {"type": "hardBreak"}]
|
||||
}]
|
||||
}
|
||||
const cleanedDoc = cleanDoc(doc)
|
||||
expect(cleanedDoc).toEqual({
|
||||
"type": "doc",
|
||||
"content": [{
|
||||
"type": "paragraph",
|
||||
"content": [{"type": "text", "text": "Good morning Sir"}, {"type": "hardBreak"}]
|
||||
}, {
|
||||
"type": "paragraph",
|
||||
"content": [{
|
||||
"type": "text",
|
||||
"text": "Hello World"
|
||||
}]
|
||||
}]
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user