Skip to content

Commit 060e979

Browse files
test: added test case for duplicate <br> tag
1 parent b5675ef commit 060e979

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

test/expectedJson.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1869,5 +1869,46 @@ export default {
18691869
`,
18701870
expectedJson: {"type":"doc","uid":"uid","attrs":{},"children":[{"type":"table","attrs":{"style":{},"redactor-attributes":{"border":"1"},"rows":5,"cols":4,"colWidths":[250,250,250,250],"disabledCols":[1,2,3]},"uid":"uid","children":[{"type":"thead","attrs":{},"uid":"uid","children":[{"type":"tr","attrs":{},"uid":"uid","children":[{"type":"th","attrs":{},"uid":"uid","children":[{"text":"Header 1"}]},{"type":"th","attrs":{"colSpan":3,"style":{},"redactor-attributes":{"colspan":"3"}},"uid":"uid","children":[{"text":"Header 2"}]},{"type":"th","attrs":{"void":true},"children":[{"text":""}]},{"type":"th","attrs":{"void":true},"children":[{"text":""}]},{"type":"th","attrs":{},"uid":"uid","children":[{"text":"Header 3"}]}]}]},{"type":"tbody","attrs":{},"uid":"uid","children":[{"type":"trgrp","children":[{"type":"tr","attrs":{},"uid":"uid","children":[{"type":"td","attrs":{"rowSpan":2,"style":{},"redactor-attributes":{"rowspan":"2"}},"uid":"uid","children":[{"text":"Row 1, Col 1"}]},{"type":"td","attrs":{"colSpan":2,"style":{},"redactor-attributes":{"colspan":"2"}},"uid":"uid","children":[{"text":"Row 1, Col 2"}]},{"type":"td","attrs":{"void":true},"children":[{"text":""}]},{"type":"td","attrs":{},"uid":"uid","children":[{"text":"Row 1, Col 3"}]},{"type":"td","attrs":{"rowSpan":2,"style":{},"redactor-attributes":{"rowspan":"2"}},"uid":"uid","children":[{"text":"Row 1, Col 4"}]}]},{"type":"tr","attrs":{},"uid":"uid","children":[{"type":"td","attrs":{"void":true},"children":[{"text":""}]},{"type":"td","attrs":{},"uid":"uid","children":[{"text":"Row 2, Col 2"}]},{"type":"td","attrs":{},"uid":"uid","children":[{"text":"Row 2, Col 3"}]},{"type":"td","attrs":{},"uid":"uid","children":[{"text":"Row 2, Col 4"}]},{"type":"td","attrs":{"void":true},"children":[{"text":""}]}]}]},{"type":"trgrp","children":[{"type":"tr","attrs":{},"uid":"uid","children":[{"type":"td","attrs":{},"uid":"uid","children":[{"text":"Row 3, Col 1"}]},{"type":"td","attrs":{"rowSpan":2,"colSpan":3,"style":{},"redactor-attributes":{"colspan":"3","rowspan":"2"}},"uid":"uid","children":[{"text":"Row 3, Col 2"}]},{"type":"td","attrs":{"void":true},"children":[{"text":""}]},{"type":"td","attrs":{"void":true},"children":[{"text":""}]},{"type":"td","attrs":{},"uid":"uid","children":[{"text":"Row 3, Col 5"}]}]},{"type":"tr","attrs":{},"uid":"uid","children":[{"type":"td","attrs":{},"uid":"uid","children":[{"text":"Row 4, Col 1"}]},{"type":"td","attrs":{"void":true},"children":[{"text":""}]},{"type":"td","attrs":{"void":true},"children":[{"text":""}]},{"type":"td","attrs":{"void":true},"children":[{"text":""}]},{"type":"td","attrs":{},"uid":"uid","children":[{"text":"Row 4, Col 5"}]}]}]}]}]}]}
18711871
},
1872+
'fix_EB-745' : {
1873+
html: `<ul><li dir="ltr">Vehicle
1874+
<br/>This is test</li></ul>`,
1875+
expectedJson: {
1876+
"uid": "uid",
1877+
"type": "doc",
1878+
"attrs": {},
1879+
"children": [
1880+
{
1881+
"uid": "uid",
1882+
"type": "ul",
1883+
"children": [
1884+
{
1885+
"type": "li",
1886+
"uid": "uid",
1887+
"attrs": {
1888+
"style": {},
1889+
"redactor-attributes": {},
1890+
"dir": "ltr"
1891+
},
1892+
"children": [
1893+
{
1894+
"text": "Vehicle"
1895+
},
1896+
{
1897+
"text": "\n",
1898+
"break": true
1899+
},
1900+
{
1901+
"text": "This is test"
1902+
}
1903+
]
1904+
}
1905+
],
1906+
"attrs": {
1907+
"style": {}
1908+
}
1909+
}
1910+
]
1911+
}
1912+
}
18721913

18731914
}

test/toRedactor.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,4 +237,15 @@ describe("Testing json to html conversion", () => {
237237
expect(html).toStrictEqual(expectedHtml)
238238
})
239239

240+
test("should not add duplicate <br/> when we have both break and \n together", () => {
241+
let jsonValue = expectedValue["fix_EB-745"].expectedJson
242+
243+
let htmlValue = toRedactor(jsonValue)
244+
console.log("🚀 ~ test ~ htmlValue:", htmlValue)
245+
console.log(expectedValue["fix_EB-745"].html);
246+
247+
let testResult = isEqual(htmlValue, expectedValue["fix_EB-745"].html)
248+
expect(testResult).toBe(true)
249+
})
250+
240251
})

0 commit comments

Comments
 (0)