From 81bedca4ff7d8a12bd1256a824f65845a83e547c Mon Sep 17 00:00:00 2001 From: Novout Date: Fri, 1 Oct 2021 17:25:38 -0300 Subject: [PATCH] test: raw converter --- jest.config.js | 2 +- .../editor/pdf/PDFConfiguration.vue | 4 +- src/use/raw.ts | 4 +- test/raw.test.ts | 188 +++++++++++++++++- 4 files changed, 190 insertions(+), 8 deletions(-) diff --git a/jest.config.js b/jest.config.js index fee1b6667..3a0a1fd6c 100644 --- a/jest.config.js +++ b/jest.config.js @@ -4,7 +4,7 @@ module.exports = { setupFilesAfterEnv: ['./jest.setup.ts'], collectCoverage: true, collectCoverageFrom: [ - '**/use/*.ts', + '**/use/raw.ts', '!**/node_modules/**' ], }; \ No newline at end of file diff --git a/src/components/editor/pdf/PDFConfiguration.vue b/src/components/editor/pdf/PDFConfiguration.vue index cd145140c..475398259 100644 --- a/src/components/editor/pdf/PDFConfiguration.vue +++ b/src/components/editor/pdf/PDFConfiguration.vue @@ -33,9 +33,7 @@ " >
- + = () => { +export const bold: Callback = () => { const open = () => { return '' } @@ -13,7 +13,7 @@ const bold: Callback = () => { return { open, close } } -const italic: Callback = () => { +export const italic: Callback = () => { const open = () => { return '' } diff --git a/test/raw.test.ts b/test/raw.test.ts index 1406b957f..9562c3001 100644 --- a/test/raw.test.ts +++ b/test/raw.test.ts @@ -3,9 +3,9 @@ */ import { useFormat } from '../src/use/format'; -import { useRaw } from '../src/use/raw'; +import { bold, italic, useRaw } from '../src/use/raw'; -describe('Raw', () => { +describe('Raw - Editor Convert', () => { beforeEach(() => {}); it('should not convert unnecessary paragraph', () => { @@ -21,4 +21,188 @@ describe('Raw', () => { expect(entity.raw).toEqual(raw); }) + + it('should not convert unnecessary heading one', () => { + const entity = { + id: 0, + type: 'heading-one', + raw: 'Untitled', + createdAt: useFormat().actually(), + updatedAt: useFormat().actually(), + }; + + const raw = useRaw().convert(entity); + + expect(entity.raw).toEqual(raw); + }) + + it('should not convert unnecessary heading two', () => { + const entity = { + id: 0, + type: 'heading-two', + raw: 'Untitled', + createdAt: useFormat().actually(), + updatedAt: useFormat().actually(), + }; + + const raw = useRaw().convert(entity); + + expect(entity.raw).toEqual(raw); + }) + + it('should not convert unnecessary heading three', () => { + const entity = { + id: 0, + type: 'heading-three', + raw: 'Untitled', + createdAt: useFormat().actually(), + updatedAt: useFormat().actually(), + }; + + const raw = useRaw().convert(entity); + + expect(entity.raw).toEqual(raw); + }) + + // italic + it('should not convert italic in heading one', () => { + const entity = { + id: 0, + type: 'heading-one', + raw: 'Untitled *test* Untitled', + createdAt: useFormat().actually(), + updatedAt: useFormat().actually(), + }; + + const raw = useRaw().convert(entity); + + expect(entity.raw).toEqual(raw); + }) + + it('should not convert italic in heading two', () => { + const entity = { + id: 0, + type: 'heading-two', + raw: 'Untitled *test* Untitled', + createdAt: useFormat().actually(), + updatedAt: useFormat().actually(), + }; + + const raw = useRaw().convert(entity); + + expect(entity.raw).toEqual(raw); + }) + + it('should not convert italic in heading three', () => { + const entity = { + id: 0, + type: 'heading-three', + raw: 'Untitled *test* Untitled', + createdAt: useFormat().actually(), + updatedAt: useFormat().actually(), + }; + + const raw = useRaw().convert(entity); + + expect(entity.raw).toEqual(raw); + }) + + it('should correct bold convert', () => { + const entity = { + id: 0, + type: 'paragraph', + raw: 'Untitled *test* Untitled', + createdAt: useFormat().actually(), + updatedAt: useFormat().actually(), + }; + + const raw = useRaw().convert(entity); + + expect(`Untitled ${italic().open()}test${italic().close()} Untitled`).toEqual(raw); + }) + + it('should not convert break italic insert', () => { + const entity = { + id: 0, + type: 'paragraph', + raw: 'Untitled *test Untitled', + createdAt: useFormat().actually(), + updatedAt: useFormat().actually(), + }; + + const raw = useRaw().convert(entity); + + expect(`Untitled ${italic().open()}test Untitled`).toEqual(raw); + }) + + // bold + it('should not convert bold in heading one', () => { + const entity = { + id: 0, + type: 'heading-one', + raw: 'Untitled &test& Untitled', + createdAt: useFormat().actually(), + updatedAt: useFormat().actually(), + }; + + const raw = useRaw().convert(entity); + + expect(entity.raw).toEqual(raw); + }) + + it('should not convert bold in heading two', () => { + const entity = { + id: 0, + type: 'heading-two', + raw: 'Untitled &test& Untitled', + createdAt: useFormat().actually(), + updatedAt: useFormat().actually(), + }; + + const raw = useRaw().convert(entity); + + expect(entity.raw).toEqual(raw); + }) + + it('should not convert bold in heading three', () => { + const entity = { + id: 0, + type: 'heading-three', + raw: 'Untitled &test& Untitled', + createdAt: useFormat().actually(), + updatedAt: useFormat().actually(), + }; + + const raw = useRaw().convert(entity); + + expect(entity.raw).toEqual(raw); + }) + + it('should correct bold convert', () => { + const entity = { + id: 0, + type: 'paragraph', + raw: 'Untitled &test& Untitled', + createdAt: useFormat().actually(), + updatedAt: useFormat().actually(), + }; + + const raw = useRaw().convert(entity); + + expect(`Untitled ${bold().open()}test${bold().close()} Untitled`).toEqual(raw); + }) + + it('should not convert break bold insert', () => { + const entity = { + id: 0, + type: 'paragraph', + raw: 'Untitled &test Untitled', + createdAt: useFormat().actually(), + updatedAt: useFormat().actually(), + }; + + const raw = useRaw().convert(entity); + + expect(`Untitled ${bold().open()}test Untitled`).toEqual(raw); + }) }) \ No newline at end of file