Skip to content

Commit

Permalink
test: raw converter
Browse files Browse the repository at this point in the history
  • Loading branch information
Novout committed Oct 1, 2021
1 parent 876203d commit 81bedca
Show file tree
Hide file tree
Showing 4 changed files with 190 additions and 8 deletions.
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = {
setupFilesAfterEnv: ['./jest.setup.ts'],
collectCoverage: true,
collectCoverageFrom: [
'**/use/*.ts',
'**/use/raw.ts',
'!**/node_modules/**'
],
};
4 changes: 1 addition & 3 deletions src/components/editor/pdf/PDFConfiguration.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@
"
>
<div class="wb-input-container justify-start">
<label class="mx-2 text-xs">{{
t('editor.pdf.cover.type')
}}</label>
<label class="mx-2 text-xs">{{ t('editor.pdf.cover.type') }}</label>
<TextBoolean v-model="switcher.cover" />
<InputFile
v-if="switcher.cover"
Expand Down
4 changes: 2 additions & 2 deletions src/use/raw.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ContextStatePageContent } from '@/types/context'
import { Callback } from '@/types/utils'

const bold: Callback<any> = () => {
export const bold: Callback<any> = () => {
const open = () => {
return '<span class="font-bold text-xs">'
}
Expand All @@ -13,7 +13,7 @@ const bold: Callback<any> = () => {
return { open, close }
}

const italic: Callback<any> = () => {
export const italic: Callback<any> = () => {
const open = () => {
return '<span class="italic text-xs">'
}
Expand Down
188 changes: 186 additions & 2 deletions test/raw.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -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);
})
})

0 comments on commit 81bedca

Please sign in to comment.