Skip to content

Commit

Permalink
test(elementmap): add table test (#168)
Browse files Browse the repository at this point in the history
  • Loading branch information
thompsonsj authored Oct 23, 2024
1 parent 600017c commit d194eca
Showing 1 changed file with 100 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,104 @@ describe("slateToHtml elementMap", () => {
}
expect(slateToHtml(slate, config)).toEqual(html)
})

it('processes element map values for a table', () => {
const html = '<table><thead><tr><th>Heading Column 1</th><th>Heading Column 2</th></tr></thead><tbody><tr><td>Cell Row 1 Column 1</td><td>Cell Row 1 Column 2</td></tr><tbody><tr><td>Cell Row 2 Column 1</td><td>Cell Row 2 Column 2</td></tr></tbody></tbody></table>'
const slate = [{
"type": "table",
"children": [
{
"type": "thead",
"children": [
{
"type": "tr",
"children": [
{
"type": "th",
"children": [
{
"text": "Heading Column 1"
}
]
},
{
"type": "th",
"children": [
{
"text": "Heading Column 2"
}
]
},
]
}
]
},
{
"type": "tbody",
"children": [
{
"type": "tr",
"children": [
{
"type": "td",
"children": [
{
"text": "Cell Row 1 Column 1"
}
]
},
{
"type": "td",
"children": [
{
"text": "Cell Row 1 Column 2"
}
]
},
]
},
{
"type": "tbody",
"children": [
{
"type": "tr",
"children": [
{
"type": "td",
"children": [
{
"text": "Cell Row 2 Column 1"
}
]
},
{
"type": "td",
"children": [
{
"text": "Cell Row 2 Column 2"
}
]
},
]
},
],
},
],
},
],
}]
const config = {
...slateToHtmlConfig,
elementMap: {
...slateToHtmlConfig.elementMap,
table: "table",
tr: "tr",
td: "td",
thead: "thead",
th: "th",
tbody: "tbody",
},
}
expect(slateToHtml(slate, config)).toEqual(html)
})
})

0 comments on commit d194eca

Please sign in to comment.