import { GeneralSteps, Logger, Pipeline, Step } from '@ephox/agar';
import { TinyApis, TinyLoader } from '@ephox/mcagar';
import InsertBr from 'tinymce/core/newline/InsertBr';
import Theme from 'tinymce/themes/modern/Theme';
import { UnitTest } from '@ephox/bedrock';
UnitTest.asynctest('browser.tinymce.core.newline.InsertBrTest', function () {
const success = arguments[arguments.length - 2];
const failure = arguments[arguments.length - 1];
Theme();
const sInsertBr = function (editor) {
return Step.sync(function () {
InsertBr.insert(editor);
});
};
TinyLoader.setup(function (editor, onSuccess, onFailure) {
const tinyApis = TinyApis(editor);
Pipeline.async({}, [
Logger.t('Enter inside inline boundary link', GeneralSteps.sequence([
Logger.t('Insert br at beginning of inline boundary link', GeneralSteps.sequence([
tinyApis.sFocus,
tinyApis.sSetContent('
abc
'),
tinyApis.sSetCursor([0, 1, 0], 0),
tinyApis.sNodeChanged,
sInsertBr(editor),
tinyApis.sAssertSelection([0, 2, 0], 1, [0, 2, 0], 1),
tinyApis.sAssertContent('a
bc
')
])),
Logger.t('Insert br in middle inline boundary link', GeneralSteps.sequence([
tinyApis.sFocus,
tinyApis.sSetContent('abcd
'),
tinyApis.sSetCursor([0, 1, 0], 1),
tinyApis.sNodeChanged,
sInsertBr(editor),
tinyApis.sAssertSelection([0, 1], 2, [0, 1], 2),
tinyApis.sAssertContent('ab
cd
')
])),
Logger.t('Insert br at end of inline boundary link', GeneralSteps.sequence([
tinyApis.sFocus,
tinyApis.sSetContent('abc
'),
tinyApis.sSetCursor([0, 1, 0], 1),
tinyApis.sNodeChanged,
sInsertBr(editor),
tinyApis.sAssertSelection([0], 3, [0], 3),
tinyApis.sAssertContent('ab
c
')
])),
Logger.t('Insert br at end of inline boundary link with trailing br', GeneralSteps.sequence([
tinyApis.sFocus,
tinyApis.sSetRawContent('ab
'),
tinyApis.sSetCursor([0, 1, 0], 1),
tinyApis.sNodeChanged,
sInsertBr(editor),
tinyApis.sAssertSelection([0], 3, [0], 3),
tinyApis.sAssertContent('ab
')
]))
])),
Logger.t('Enter inside inline boundary code', GeneralSteps.sequence([
Logger.t('Insert br at beginning of boundary code', GeneralSteps.sequence([
tinyApis.sFocus,
tinyApis.sSetContent('abc
'),
tinyApis.sSetCursor([0, 1, 0], 0),
tinyApis.sNodeChanged,
sInsertBr(editor),
tinyApis.sAssertSelection([0, 1], 2, [0, 1], 2),
tinyApis.sAssertContent('a
bc
')
])),
Logger.t('Insert br at middle of boundary code', GeneralSteps.sequence([
tinyApis.sFocus,
tinyApis.sSetContent('abcd
'),
tinyApis.sSetCursor([0, 1, 0], 1),
tinyApis.sNodeChanged,
sInsertBr(editor),
tinyApis.sAssertSelection([0, 1], 2, [0, 1], 2),
tinyApis.sAssertContent('ab
cd
')
])),
Logger.t('Insert br at end of boundary code', GeneralSteps.sequence([
tinyApis.sFocus,
tinyApis.sSetContent('abc
'),
tinyApis.sSetCursor([0, 1, 0], 1),
tinyApis.sNodeChanged,
sInsertBr(editor),
tinyApis.sAssertSelection([0, 1, 2], 0, [0, 1, 2], 0),
tinyApis.sAssertContent('ab
c
')
]))
]))
], onSuccess, onFailure);
}, {
indent: false,
skin_url: '/project/js/tinymce/skins/lightgray'
}, success, failure);
});