import { Pipeline } from '@ephox/agar';
import { UnitTest } from '@ephox/bedrock';
import { LegacyUnit, TinyLoader } from '@ephox/mcagar';
import Plugin from 'tinymce/plugins/lists/Plugin';
import Theme from 'tinymce/themes/modern/Theme';
UnitTest.asynctest('tinymce.lists.browser.OutdentTest', function () {
const success = arguments[arguments.length - 2];
const failure = arguments[arguments.length - 1];
const suite = LegacyUnit.createSuite();
Plugin();
Theme();
suite.test('Outdent inside LI in beginning of OL in LI', function (editor) {
editor.getBody().innerHTML = LegacyUnit.trimBrs(
'
' +
'- a' +
'
' +
'- b
' +
'- c
' +
'
' +
' ' +
'
'
);
editor.focus();
LegacyUnit.setSelection(editor, 'li li', 1);
LegacyUnit.execCommand(editor, 'Outdent');
LegacyUnit.equal(editor.getContent(),
'' +
'- a
' +
'- b' +
'
' +
'- c
' +
'
' +
' ' +
'
'
);
LegacyUnit.equal(editor.selection.getNode().nodeName, 'LI');
});
suite.test('Outdent inside LI in middle of OL in LI', function (editor) {
editor.getBody().innerHTML = LegacyUnit.trimBrs(
'' +
'- a' +
'
' +
'- b
' +
'- c
' +
'- d
' +
'
' +
' ' +
'
'
);
editor.focus();
LegacyUnit.setSelection(editor, 'li li:nth-child(2)', 1);
LegacyUnit.execCommand(editor, 'Outdent');
LegacyUnit.equal(editor.getContent(),
'' +
'- a' +
'
' +
'- b
' +
'
' +
' ' +
'- c' +
'
' +
'- d
' +
'
' +
' ' +
'
'
);
LegacyUnit.equal(editor.selection.getNode().nodeName, 'LI');
});
suite.test('Outdent inside LI in end of OL in LI', function (editor) {
editor.getBody().innerHTML = LegacyUnit.trimBrs(
'' +
'- a' +
'
' +
'- b
' +
'- c
' +
'
' +
' ' +
'
'
);
editor.focus();
LegacyUnit.setSelection(editor, 'li li:last', 1);
LegacyUnit.execCommand(editor, 'Outdent');
LegacyUnit.equal(editor.getContent(),
'' +
'- a' +
'
' +
'- b
' +
'
' +
' ' +
'- c
' +
'
'
);
LegacyUnit.equal(editor.selection.getNode().nodeName, 'LI');
});
// Nested lists in OL elements
suite.test('Outdent inside LI in beginning of OL in OL', function (editor) {
editor.getBody().innerHTML = LegacyUnit.trimBrs(
'' +
'- a
' +
'' +
'- b
' +
'- c
' +
'
' +
'
'
);
editor.focus();
LegacyUnit.setSelection(editor, 'ol ol li', 1);
LegacyUnit.execCommand(editor, 'Outdent');
LegacyUnit.equal(editor.getContent(),
'' +
'- a
' +
'- b
' +
'' +
'- c
' +
'
' +
'
'
);
LegacyUnit.equal(editor.selection.getNode().nodeName, 'LI');
});
suite.test('Outdent inside LI in middle of OL in OL', function (editor) {
editor.getBody().innerHTML = LegacyUnit.trimBrs(
'' +
'- a
' +
'' +
'- b
' +
'- c
' +
'- d
' +
'
' +
'
'
);
editor.focus();
LegacyUnit.setSelection(editor, 'ol ol li:nth-child(2)', 1);
LegacyUnit.execCommand(editor, 'Outdent');
LegacyUnit.equal(editor.getContent(),
'' +
'- a
' +
'' +
'- b
' +
'
' +
'- c
' +
'' +
'- d
' +
'
' +
'
'
);
LegacyUnit.equal(editor.selection.getNode().nodeName, 'LI');
});
suite.test('Outdent inside first/last LI in inner OL', function (editor) {
editor.getBody().innerHTML = LegacyUnit.trimBrs(
'' +
'- 1' +
'
' +
'- 2
' +
'- 3
' +
'
' +
' ' +
'- 4
' +
'
'
);
editor.focus();
LegacyUnit.setSelection(editor, 'ol ol li:nth-child(1)', 0, 'ol ol li:nth-child(2)', 1);
LegacyUnit.execCommand(editor, 'Outdent');
LegacyUnit.equal(editor.getContent(),
'' +
'- 1
' +
'- 2
' +
'- 3
' +
'- 4
' +
'
'
);
LegacyUnit.equal(editor.selection.getRng(true).startContainer.nodeValue, '2');
LegacyUnit.equal(editor.selection.getRng(true).endContainer.nodeValue, '3');
});
suite.test('Outdent inside first LI in inner OL where OL is single child of parent LI', function (editor) {
editor.getBody().innerHTML = LegacyUnit.trimBrs(
'' +
'- a
' +
'- ' +
'
' +
'- b
' +
'- c
' +
'
' +
' ' +
'
'
);
editor.focus();
LegacyUnit.setSelection(editor, 'ol ol li:first', 0);
LegacyUnit.execCommand(editor, 'Outdent');
LegacyUnit.equal(editor.getContent(),
'' +
'- a
' +
'- b' +
'
' +
'- c
' +
'
' +
' ' +
'
'
);
LegacyUnit.equal(editor.selection.getNode().nodeName, 'LI');
});
suite.test('Outdent inside LI in end of OL in OL', function (editor) {
editor.getBody().innerHTML = LegacyUnit.trimBrs(
'' +
'- a
' +
'' +
'- b
' +
'- c
' +
'
' +
'
'
);
editor.focus();
LegacyUnit.setSelection(editor, 'ol ol li:last', 1);
LegacyUnit.execCommand(editor, 'Outdent');
LegacyUnit.equal(editor.getContent(),
'' +
'- a
' +
'' +
'- b
' +
'
' +
'- c
' +
'
'
);
LegacyUnit.equal(editor.selection.getNode().nodeName, 'LI');
});
suite.test('Outdent inside only child LI in OL in OL', function (editor) {
editor.getBody().innerHTML = LegacyUnit.trimBrs(
'' +
'- a' +
'
' +
'- b
' +
'
' +
' ' +
'
'
);
editor.focus();
LegacyUnit.setSelection(editor, 'ol ol li', 0);
LegacyUnit.execCommand(editor, 'Outdent');
LegacyUnit.equal(editor.getContent(),
'' +
'- a
' +
'- b
' +
'
'
);
LegacyUnit.equal(editor.selection.getNode().nodeName, 'LI');
});
suite.test('Outdent multiple LI in OL and nested OL', function (editor) {
editor.getBody().innerHTML = LegacyUnit.trimBrs(
'' +
'- a' +
'
' +
'- b
' +
'
' +
' ' +
'
'
);
editor.focus();
LegacyUnit.setSelection(editor, 'li', 0, 'li li', 1);
LegacyUnit.execCommand(editor, 'Outdent');
LegacyUnit.equal(editor.getContent(),
'a
' +
'' +
'- b
' +
'
'
);
});
suite.test('Outdent on li with inner block element', function (editor) {
editor.getBody().innerHTML = LegacyUnit.trimBrs(
''
);
editor.focus();
LegacyUnit.setSelection(editor, 'ul li:nth-child(2) p', 0);
LegacyUnit.execCommand(editor, 'Outdent');
LegacyUnit.equal(editor.getContent(),
'' +
'b
' +
''
);
});
suite.test('Outdent on nested li with inner block element', function (editor) {
editor.getBody().innerHTML = LegacyUnit.trimBrs(
'' +
'- ' +
'
a
' +
'' +
' ' +
'c
' +
'
'
);
editor.focus();
LegacyUnit.setSelection(editor, 'ul li:nth-child(1) li p', 0);
LegacyUnit.execCommand(editor, 'Outdent');
LegacyUnit.equal(editor.getContent(),
''
);
});
TinyLoader.setup(function (editor, onSuccess, onFailure) {
Pipeline.async({}, suite.toSteps(editor), onSuccess, onFailure);
}, {
plugins: 'lists',
add_unload_trigger: false,
disable_nodechange: true,
indent: false,
entities: 'raw',
valid_elements:
'li[style|class|data-custom],ol[style|class|data-custom],' +
'ul[style|class|data-custom],dl,dt,dd,em,strong,span,#p,div,br',
valid_styles: {
'*': 'color,font-size,font-family,background-color,font-weight,' +
'font-style,text-decoration,float,margin,margin-top,margin-right,' +
'margin-bottom,margin-left,display,position,top,left,list-style-type'
},
skin_url: '/project/js/tinymce/skins/lightgray'
}, success, failure);
});