diff --git a/common/tests/unit/.keep b/common/tests/unit/.keep deleted file mode 100644 index e69de29b..00000000 diff --git a/common/tests/unit/cleanDoc.test.ts b/common/tests/unit/cleanDoc.test.ts new file mode 100644 index 00000000..546ffd28 --- /dev/null +++ b/common/tests/unit/cleanDoc.test.ts @@ -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" + }] + }] + }) + }) +}) \ No newline at end of file