import { Assertions, GeneralSteps, Logger, Pipeline, Step } from '@ephox/agar'; import { Element, Html } from '@ephox/sugar'; import PaddingBr from 'tinymce/core/dom/PaddingBr'; import { UnitTest } from '@ephox/bedrock'; UnitTest.asynctest('browser.tinymce.core.dom.PaddingBrTest', function () { const success = arguments[arguments.length - 2]; const failure = arguments[arguments.length - 1]; const sTestRemoveTrailingBr = function (label, inputHtml, expectedHtml) { return Step.sync(function () { const elm = Element.fromHtml(inputHtml); PaddingBr.removeTrailingBr(elm); Assertions.assertHtml(label, expectedHtml, Html.getOuter(elm)); }); }; const sTestTrimBlockTrailingBr = function (label, inputHtml, expectedHtml) { return Step.sync(function () { const elm = Element.fromHtml(inputHtml); PaddingBr.trimBlockTrailingBr(elm); Assertions.assertHtml(label, expectedHtml, Html.getOuter(elm)); }); }; Pipeline.async({}, [ Logger.t('removeTrailingBrs', GeneralSteps.sequence([ sTestRemoveTrailingBr('Should be untouched since it has no brs', '

a

', '

a

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

a
b

', '

a
b

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

a
b

', '

a
b

'), sTestRemoveTrailingBr('Should remove trailing br 1', '

a

', '

a

'), sTestRemoveTrailingBr('Should remove trailing br 2', '

a

', '

a

'), sTestRemoveTrailingBr('Should remove trailing br 3', '

a

', '

a

'), sTestRemoveTrailingBr('Should remove trailing br 4', '

a

', '

a

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

a

', '

a

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

a

', '

a

') ])), Logger.t('fillWithPaddingBr', GeneralSteps.sequence([ Step.sync(function () { const elm = Element.fromHtml('

a

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


', Html.getOuter(elm)); }) ])), Logger.t('isPaddedElement', Step.sync(function () { Assertions.assertEq('Should not be padded', false, PaddingBr.isPaddedElement(Element.fromHtml('

a

'))); Assertions.assertEq('Should not be padded', false, PaddingBr.isPaddedElement(Element.fromHtml('

\u00a0\u00a0

'))); Assertions.assertEq('Should not be padded', false, PaddingBr.isPaddedElement(Element.fromHtml('



'))); Assertions.assertEq('Should not be padded', false, PaddingBr.isPaddedElement(Element.fromHtml('

'))); Assertions.assertEq('Should be padded nbsp', true, PaddingBr.isPaddedElement(Element.fromHtml('

\u00a0

'))); Assertions.assertEq('Should be padded br', true, PaddingBr.isPaddedElement(Element.fromHtml('


'))); })), Logger.t('trimPaddingBrs', GeneralSteps.sequence([ sTestTrimBlockTrailingBr('Should be untouched since it has no brs', '
', '
'), sTestTrimBlockTrailingBr('Should be untouched since it has no brs', '

a

', '

a

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

a


', '

a

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

a



', '

a



'), sTestTrimBlockTrailingBr('Should be untouched since it is br after a inline', '
a
', '
a
'), sTestTrimBlockTrailingBr('Should be untouched since it is br after inlide inline', 'a
', 'a
') ])) ], function () { success(); }, failure); });