-
-
Notifications
You must be signed in to change notification settings - Fork 755
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e6ec801
commit b9cade8
Showing
5 changed files
with
123 additions
and
185 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
File renamed without changes.
This file was deleted.
Oops, something went wrong.
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,81 @@ | ||
import React from 'react'; | ||
|
||
import { createSlateEditor } from '../../editor'; | ||
import { createTSlatePlugin } from '../../plugin'; | ||
import { serializePlateStatic } from '../serializedHtml'; | ||
import { createStaticEditor, staticComponents } from './create-static-editor'; | ||
|
||
describe('serializePlateStatic nodes', () => { | ||
it('should serialize render below nodes', async () => { | ||
const renderBelowPlugin = createTSlatePlugin({ | ||
key: 'test-list', | ||
render: { | ||
belowNodes: (injectProps: any) => { | ||
const { element } = injectProps; | ||
|
||
return function Component({ | ||
children, | ||
}: { | ||
children: React.ReactNode; | ||
}) { | ||
return ( | ||
<ul> | ||
<li>{children}</li> | ||
</ul> | ||
); | ||
}; | ||
}, | ||
}, | ||
}); | ||
|
||
const editor = createSlateEditor({ | ||
plugins: [renderBelowPlugin], | ||
value: [ | ||
{ | ||
children: [{ text: 'test render below' }], | ||
type: 'p', | ||
}, | ||
], | ||
}); | ||
|
||
const html = await serializePlateStatic(editor, staticComponents, { | ||
preserveClassNames: [], | ||
stripClassNames: true, | ||
stripDataAttributes: true, | ||
}); | ||
|
||
expect(html).toEqual( | ||
'<div><ul><li><span><span><span>test render below</span></span></span></li></ul></div>' | ||
); | ||
}); | ||
|
||
it('should serialize string with %', async () => { | ||
const editor = createStaticEditor([ | ||
{ | ||
children: [ | ||
{ | ||
text: 'None encoded string 100%', | ||
}, | ||
], | ||
type: 'p', | ||
}, | ||
{ | ||
children: [{ text: 'Encoded string 100%25' }], | ||
type: 'p', | ||
}, | ||
]); | ||
|
||
const html = await serializePlateStatic(editor, staticComponents, { | ||
preserveClassNames: [], | ||
stripClassNames: true, | ||
// stripDataAttributes: true, | ||
}); | ||
|
||
expect(html).toContain( | ||
'<span data-slate-string="true">None encoded string 100%</span>' | ||
); | ||
expect(html).toContain( | ||
'<span data-slate-string="true">Encoded string 100%25</span>' | ||
); | ||
}); | ||
}); |
22 changes: 22 additions & 0 deletions
22
packages/core/src/lib/static/__tests__/with-attributes.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,22 @@ | ||
import { serializePlateStatic } from '../serializedHtml'; | ||
import { createStaticEditor, staticComponents } from './create-static-editor'; | ||
|
||
describe('serializePlateStatic with attributes', () => { | ||
it('should serialize elements with right slate attributes', async () => { | ||
const editor = createStaticEditor([ | ||
{ | ||
children: [{ bold: true, text: 'Right Aligned Heading' }], | ||
type: 'p', | ||
}, | ||
]); | ||
|
||
const html = await serializePlateStatic(editor, staticComponents, { | ||
preserveClassNames: [], | ||
stripClassNames: true, | ||
}); | ||
|
||
expect(html).toEqual( | ||
'<div data-slate-node="element"><span data-slate-node="text"><span data-slate-leaf="true"><strong data-slate-leaf="true"><span data-slate-string="true">Right Aligned Heading</span></strong></span></span></div>' | ||
); | ||
}); | ||
}); |