-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(slatetohtml): reorganise (#166)
Reorganise for thompsonsj/slate-serializers-demo#32
- Loading branch information
1 parent
26f75ae
commit 17f44f4
Showing
7 changed files
with
297 additions
and
274 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
packages/html/src/lib/tests/slateToHtml/configuration/elementMap.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { slateToHtml, slateToHtmlConfig } from '@slate-serializers/html' | ||
|
||
describe("slateToHtml elementMap", () => { | ||
it('processes an element map value', () => { | ||
const html = '<h1>Heading 1</h1>' | ||
const slate = [ | ||
{ | ||
type: 'heading-one', | ||
children: [ | ||
{ | ||
text: 'Heading 1', | ||
}, | ||
], | ||
}, | ||
] | ||
const config = { | ||
...slateToHtmlConfig, | ||
elementMap: { | ||
['heading-one']: 'h1', | ||
}, | ||
} | ||
expect(slateToHtml(slate, config)).toEqual(html) | ||
}) | ||
}) |
34 changes: 34 additions & 0 deletions
34
packages/html/src/lib/tests/slateToHtml/configuration/elementTransforms.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Element } from 'domhandler' | ||
import { slateToHtml, slateToHtmlConfig } from "@slate-serializers/html" | ||
|
||
describe("slateToHtml elementTransforms", () => { | ||
it('processes an element transform', () => { | ||
const html = '<p>Paragraph</p><img src="https://picsum.photos/id/237/200/300">' | ||
const slate = [ | ||
{ | ||
type: 'p', | ||
children: [ | ||
{ | ||
text: 'Paragraph', | ||
}, | ||
], | ||
}, | ||
{ | ||
type: 'image', | ||
url: 'https://picsum.photos/id/237/200/300', | ||
}, | ||
] | ||
const config = { | ||
...slateToHtmlConfig, | ||
elementTransforms: { | ||
...slateToHtmlConfig.elementTransforms, | ||
image: ({ node }: { node?: any }) => { | ||
return new Element('img', { | ||
src: node.url, | ||
}) | ||
}, | ||
}, | ||
} | ||
expect(slateToHtml(slate, config)).toEqual(html) | ||
}) | ||
}) |
Oops, something went wrong.