-
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.
Browse files
Browse the repository at this point in the history
* test(elementtransforms): add test for #120 * test(elementtags): rename test file
- Loading branch information
1 parent
ec85935
commit ee3bc73
Showing
1 changed file
with
88 additions
and
0 deletions.
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
packages/html/src/lib/serializers/snapshots/elementTags.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,88 @@ | ||
import { getAttributeValue } from 'domutils'; | ||
import { | ||
htmlToSlate, | ||
htmlToSlateConfig, | ||
slateToHtml, | ||
type HtmlToSlateConfig, | ||
SlateToHtmlConfig, | ||
slateToHtmlConfig, | ||
} from '../../html'; | ||
import { | ||
transformStyleObjectToString, | ||
transformStyleStringToObject, | ||
} from '@slate-serializers/utilities'; | ||
|
||
const fixture = | ||
'<h2 style="text-align: center;"><span style="font-size: 14pt;"><b>Introduce MacBook Air 2017 MQD42</b></span></h2>\n<p><img class="aligncenter wp-image-3372" src="https://example.com/media/macbook-air-2017-mqd42-1.jpg" alt="" width="900" height="577" /></p>\n'; | ||
|
||
describe('issue #120', () => { | ||
it('generates expected htmlToSlate output', () => { | ||
const slate = htmlToSlate(fixture); | ||
expect(slate).toMatchInlineSnapshot(` | ||
[ | ||
{ | ||
"align": "center", | ||
"children": [ | ||
{ | ||
"text": "Introduce MacBook Air 2017 MQD42", | ||
}, | ||
], | ||
"type": "h2", | ||
}, | ||
{ | ||
"children": [ | ||
{ | ||
"text": "", | ||
}, | ||
], | ||
"type": "p", | ||
}, | ||
] | ||
`); | ||
}); | ||
|
||
it('generates expected htmlToSlate output with an elementTransform', () => { | ||
const config: HtmlToSlateConfig = { | ||
...htmlToSlateConfig, | ||
elementTags: { | ||
...htmlToSlateConfig.elementTags, | ||
img: (el) => ({ | ||
type: 'image', | ||
src: el && getAttributeValue(el, 'src'), | ||
width: el && getAttributeValue(el, 'width'), | ||
height: el && getAttributeValue(el, 'height'), | ||
}), | ||
}, | ||
}; | ||
const slate = htmlToSlate(fixture, config); | ||
expect(slate).toMatchInlineSnapshot(` | ||
[ | ||
{ | ||
"align": "center", | ||
"children": [ | ||
{ | ||
"text": "Introduce MacBook Air 2017 MQD42", | ||
}, | ||
], | ||
"type": "h2", | ||
}, | ||
{ | ||
"children": [ | ||
{ | ||
"children": [ | ||
{ | ||
"text": "", | ||
}, | ||
], | ||
"height": "577", | ||
"src": "https://example.com/media/macbook-air-2017-mqd42-1.jpg", | ||
"type": "image", | ||
"width": "900", | ||
}, | ||
], | ||
"type": "p", | ||
}, | ||
] | ||
`); | ||
}); | ||
}); |