import { Assert, UnitTest } from '@ephox/bedrock-client'; import { Arr } from '@ephox/katamari'; import { Html, Insert, Remove, SugarBody, SugarElement } from '@ephox/sugar'; import * as TableContent from 'ephox/snooker/api/TableContent'; UnitTest.test('TableMergeContentTest', () => { const mergeContentTest = (specs: { label: string; html: string; expected: string }[]) => { const table = SugarElement.fromTag('table'); const row = SugarElement.fromTag('tr'); Insert.append(table, row); const cells = Arr.map(specs, (item) => { const cell = SugarElement.fromTag('td'); cell.dom.innerHTML = item.html; Insert.append(row, cell); return cell; }); Insert.append(SugarBody.body(), table); TableContent.merge(cells); Arr.each(specs, (spec, i) => { Assert.eq(() => spec.label + ' expected:\n' + spec.expected + '\n got: \n' + Html.get(cells[i]), spec.expected, Html.get(cells[i])); }); Remove.remove(table); }; /* Todo: - feff chars should not breaketh - add \r \n chars after block tags ? */ const spec1 = [ { label: 'just a P block tag, there should NOT be a br proceeding it', html: '

There should not be a br after.

', expected: '

There should not be a br after.

Standard paragraph

' + ' I am a textnode and should have a br after the period.
' + '
' + '
Nested div

deep para

' + 'nested spanthere SHOULD be a br proceeding the span

' }, { label: 'P tag, with a textnode after, there SHOULD be a br proceeding it', html: '

Standard paragraph

I am a textnode and should have a br after the period.', expected: '' }, { label: 'img tag, with a textnode after, there SHOULD be a br proceeding it', html: '', expected: '' }, { label: 'nested, with a textnode after, there SHOULD be a br proceeding it', html: '
Nested div

deep para

nested spanthere SHOULD be a br proceeding the span
', expected: '' } ]; const spec2 = [ { label: 'textnode followed by a block tag, there should NOT be a br proceeding the p', html: 'standard issue textnode

There should not be a br after.

', expected: 'standard issue textnode

There should not be a br after.

I am inline textnode
textnode with empty block tag
' }, { label: 'Img wrapped in an Anchor tag with text, there should be a BR after', html: ' I am inline textnode', expected: '' }, { label: ' = Gotach test = tricky textnode with an empty block tag', html: 'textnode with empty block tag
', expected: '' }, { label: 'brs should NOT have more br appended', html: '


', expected: '


' } ]; const spec3 = [ { label: 'There should not be a br after the hr', html: 'standard issue textnode followed by a hr
', expected: 'standard issue textnode followed by a hr
' }, { label: 'Empty cell should remain empty', html: '', expected: '' }, { label: `lists should not have BR's after`, html: '', expected: '' }, { label: 'complexed Lists, nested list with inline elements should not have a BR because its part of a list structure', html: '', expected: '' } ]; const spec4 = [ { label: 'A cell containing only a br should be maintained 0', html: '
', expected: '
' }, { label: 'A cell containing only a br should be maintained 1', html: '
', expected: '
' }, { label: 'A cell containing only a br should be maintained 3', html: '
', expected: '
' } ]; const spec5 = [ { label: 'A cell containing only a br should be maintained 0', html: '
', expected: '
' }, { label: 'A cell containing only a br should be maintained 1', html: '
', expected: '
' }, { label: 'A cell containing only an inline hr should not be kept', html: '
', expected: '' } ]; const spec6 = [ { label: 'A cell containing an image and an hr should maintain both', html: '', expected: '

' }, { label: 'A cell containing an image and an hr should maintain both', html: '
', expected: '' } ]; mergeContentTest(spec1); mergeContentTest(spec2); mergeContentTest(spec3); mergeContentTest(spec4); mergeContentTest(spec5); mergeContentTest(spec6); });