import { Assertions } from '@ephox/agar'; import { describe, it } from '@ephox/bedrock-client'; import { Html, SugarElement } from '@ephox/sugar'; import { assert } from 'chai'; import * as PaddingBr from 'tinymce/core/dom/PaddingBr'; describe('browser.tinymce.core.dom.PaddingBrTest', () => { const testRemoveTrailingBr = (label: string, inputHtml: string, expectedHtml: string) => { const elm = SugarElement.fromHtml(inputHtml); PaddingBr.removeTrailingBr(elm); Assertions.assertHtml(label, expectedHtml, Html.getOuter(elm)); }; const testTrimBlockTrailingBr = (label: string, inputHtml: string, expectedHtml: string) => { const elm = SugarElement.fromHtml(inputHtml); PaddingBr.trimBlockTrailingBr(elm); Assertions.assertHtml(label, expectedHtml, Html.getOuter(elm)); }; it('removeTrailingBrs', () => { testRemoveTrailingBr('Should be untouched since it has no brs', '

a

', '

a

'); testRemoveTrailingBr('Should be untouched since the br not at the edge of the tree', '

a
b

', '

a
b

'); testRemoveTrailingBr('Should be untouched since the br not at the edge of the tree', '

a
b

', '

a
b

'); testRemoveTrailingBr('Should remove trailing br 1', '

a

', '

a

'); testRemoveTrailingBr('Should remove trailing br 2', '

a

', '

a

'); testRemoveTrailingBr('Should remove trailing br 3', '

a

', '

a

'); testRemoveTrailingBr('Should remove trailing br 4', '

a

', '

a

'); testRemoveTrailingBr('Should be untouched since there is more than one br', '

a

', '

a

'); testRemoveTrailingBr('Should be untouched since there is more than one br', '

a

', '

a

'); }); it('fillWithPaddingBr', () => { const elm = SugarElement.fromHtml('

a

'); PaddingBr.fillWithPaddingBr(elm); Assertions.assertHtml('Should be padded with bogus br', '


', Html.getOuter(elm)); }); it('isPaddedElement', () => { assert.isFalse(PaddingBr.isPaddedElement(SugarElement.fromHtml('

a

')), 'Should not be padded'); assert.isFalse(PaddingBr.isPaddedElement(SugarElement.fromHtml('

\u00a0\u00a0

')), 'Should not be padded'); assert.isFalse(PaddingBr.isPaddedElement(SugarElement.fromHtml('



')), 'Should not be padded'); assert.isFalse(PaddingBr.isPaddedElement(SugarElement.fromHtml('

')), 'Should not be padded'); assert.isTrue(PaddingBr.isPaddedElement(SugarElement.fromHtml('

\u00a0

')), 'Should be padded nbsp'); assert.isTrue(PaddingBr.isPaddedElement(SugarElement.fromHtml('


')), 'Should be padded br'); }); it('trimPaddingBrs', () => { testTrimBlockTrailingBr('Should be untouched since it has no brs', '
', '
'); testTrimBlockTrailingBr('Should be untouched since it has no brs', '

a

', '

a

'); testTrimBlockTrailingBr('Should be without br since it is after a block', '

a


', '

a

'); testTrimBlockTrailingBr('Should be untouched since it is multiple brs', '

a



', '

a



'); testTrimBlockTrailingBr('Should be untouched since it is a br after an inline', '
a
', '
a
'); testTrimBlockTrailingBr('Should be untouched since it is a br inside an inline', 'a
', 'a
'); }); });