import postprocessEditorOutput from './postprocessEditorOutput'; const normalizeHtmlString = (html: string) => { return html.replace(/\s+/g, ' ').trim(); }; const processListHtml = (inputHtml: string) => { const doc = new DOMParser().parseFromString(`${inputHtml}`, 'text/html'); const output = postprocessEditorOutput(doc.body); return normalizeHtmlString(output.querySelector('ul').outerHTML); }; describe('postprocessEditorOutput', () => { test.each([ [ 'should remove extra paragraphs from around list items', ``, ``, ], [ 'should remove wrapper paragraph from list items with nested lists', ``, ``, ], [ 'should preserve multiple paragraphs in list items with nested lists', ``, ``, ], [ 'should preserve non-consecutive paragraphs separated by nested lists', ``, ``, ], [ 'should preserve text nodes before paragraphs in list items', ``, ``, ], [ 'should remove wrapper paragraph from checklist items with nested lists', ``, ``, ], [ 'should remove wrapper paragraphs from around checklist items', ``, ``, ], ])('%s', (_name, input, expected) => { expect(processListHtml(input)).toBe(normalizeHtmlString(expected)); }); });