Skip to content

Commit

Permalink
test(elementtransforms): add test for #120 (#135)
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
thompsonsj authored Dec 12, 2023
1 parent ec85935 commit ee3bc73
Showing 1 changed file with 88 additions and 0 deletions.
88 changes: 88 additions & 0 deletions packages/html/src/lib/serializers/snapshots/elementTags.spec.ts
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",
},
]
`);
});
});

0 comments on commit ee3bc73

Please sign in to comment.