import { Pipeline } from '@ephox/agar';
import { UnitTest } from '@ephox/bedrock';
import { LegacyUnit, TinyLoader } from '@ephox/mcagar';
import Env from 'tinymce/core/api/Env';
import Plugin from 'tinymce/plugins/lists/Plugin';
import Theme from 'tinymce/themes/modern/Theme';
UnitTest.asynctest('tinymce.lists.browser.RemoveTest', function () {
const success = arguments[arguments.length - 2];
const failure = arguments[arguments.length - 1];
const suite = LegacyUnit.createSuite();
Plugin();
Theme();
suite.test('Remove UL at single LI', function (editor) {
editor.getBody().innerHTML = LegacyUnit.trimBrs(
'
'
);
editor.focus();
LegacyUnit.setSelection(editor, 'li', 0);
LegacyUnit.execCommand(editor, 'InsertUnorderedList');
LegacyUnit.equal(editor.getContent(),
'a
'
);
LegacyUnit.equal(editor.selection.getStart().nodeName, 'P');
});
suite.test('Remove UL at start LI', function (editor) {
editor.getBody().innerHTML = LegacyUnit.trimBrs(
''
);
editor.focus();
LegacyUnit.setSelection(editor, 'li', 0);
LegacyUnit.execCommand(editor, 'InsertUnorderedList');
LegacyUnit.equal(editor.getContent(),
'a
' +
''
);
LegacyUnit.equal(editor.selection.getStart().nodeName, 'P');
});
suite.test('Remove UL at start empty LI', function (editor) {
editor.getBody().innerHTML = LegacyUnit.trimBrs(
''
);
editor.focus();
LegacyUnit.setSelection(editor, 'li', 0);
LegacyUnit.execCommand(editor, 'InsertUnorderedList');
LegacyUnit.equal(editor.getContent(),
'\u00a0
' +
''
);
LegacyUnit.equal(editor.selection.getNode().nodeName, 'P');
});
suite.test('Remove UL at middle LI', function (editor) {
editor.getBody().innerHTML = LegacyUnit.trimBrs(
''
);
editor.focus();
LegacyUnit.setSelection(editor, 'li:nth-child(2)', 1);
LegacyUnit.execCommand(editor, 'InsertUnorderedList');
LegacyUnit.equal(editor.getContent(),
'' +
'b
' +
''
);
LegacyUnit.equal(editor.selection.getStart().nodeName, 'P');
});
suite.test('Remove UL at middle empty LI', function (editor) {
editor.getBody().innerHTML = LegacyUnit.trimBrs(
''
);
editor.focus();
LegacyUnit.setSelection(editor, 'li:nth-child(2)', 0);
LegacyUnit.execCommand(editor, 'InsertUnorderedList');
LegacyUnit.equal(editor.getContent(),
'' +
'\u00a0
' +
''
);
LegacyUnit.equal(editor.selection.getNode().nodeName, 'P');
});
suite.test('Remove UL at end LI', function (editor) {
editor.getBody().innerHTML = LegacyUnit.trimBrs(
''
);
editor.focus();
LegacyUnit.setSelection(editor, 'li:last', 1);
LegacyUnit.execCommand(editor, 'InsertUnorderedList');
LegacyUnit.equal(editor.getContent(),
'' +
'c
'
);
LegacyUnit.equal(editor.selection.getStart().nodeName, 'P');
});
suite.test('Remove UL at end empty LI', function (editor) {
editor.getBody().innerHTML = LegacyUnit.trimBrs(
''
);
editor.focus();
LegacyUnit.setSelection(editor, 'li:last', 0);
LegacyUnit.execCommand(editor, 'InsertUnorderedList');
LegacyUnit.equal(editor.getContent(),
'' +
'\u00a0
'
);
LegacyUnit.equal(editor.selection.getNode().nodeName, 'P');
});
suite.test('Remove UL at middle LI inside parent OL', function (editor) {
editor.getBody().innerHTML = LegacyUnit.trimBrs(
'' +
'- a
' +
'' +
'- e
' +
'
'
);
editor.focus();
LegacyUnit.setSelection(editor, 'ul li:nth-child(2)', 1);
LegacyUnit.execCommand(editor, 'InsertUnorderedList');
LegacyUnit.equal(editor.getContent(),
'' +
'- a
' +
'' +
'
' +
'c
' +
'' +
'' +
'- e
' +
'
'
);
LegacyUnit.equal(editor.selection.getStart().nodeName, 'P');
});
suite.test('Remove UL at middle LI inside parent OL (html5)', function (editor) {
editor.getBody().innerHTML = LegacyUnit.trimBrs(
'' +
'- a' +
'' +
'
' +
'- e
' +
'
'
);
editor.focus();
LegacyUnit.setSelection(editor, 'ul li:nth-child(2)', 1);
LegacyUnit.execCommand(editor, 'InsertUnorderedList');
LegacyUnit.equal(editor.getContent(),
'' +
'- a' +
'' +
'
' +
'
' +
'c
' +
'' +
'- ' +
'' +
'
' +
'- e
' +
'
'
);
LegacyUnit.equal(editor.selection.getStart().nodeName, 'P');
});
suite.test('Remove OL on a deep nested LI', function (editor) {
editor.getBody().innerHTML = LegacyUnit.trimBrs(
'' +
'- a' +
'
' +
'- b
' +
'- c' +
'
' +
'- d
' +
'- e
' +
'- f
' +
'
' +
' ' +
'- g
' +
'- h
' +
'
' +
' ' +
'- i
' +
'
'
);
editor.focus();
LegacyUnit.setSelection(editor, 'ol ol ol li:nth-child(2)', 1);
LegacyUnit.execCommand(editor, 'InsertOrderedList');
LegacyUnit.equal(editor.getContent(),
'' +
'- a' +
'
' +
'- b
' +
'- c' +
'
' +
'- d
' +
'
' +
' ' +
'
' +
' ' +
'
' +
'e
' +
'' +
'- ' +
'
' +
'- ' +
'
' +
'- f
' +
'
' +
' ' +
'- g
' +
'- h
' +
'
' +
' ' +
'- i
' +
'
'
);
LegacyUnit.equal(editor.selection.getStart().nodeName, 'P');
});
suite.test('Remove UL with single LI in BR mode', function (editor) {
editor.settings.forced_root_block = false;
editor.getBody().innerHTML = LegacyUnit.trimBrs(
''
);
editor.focus();
LegacyUnit.setSelection(editor, 'li', 1);
LegacyUnit.execCommand(editor, 'InsertUnorderedList');
LegacyUnit.equal(editor.getContent(),
'a'
);
LegacyUnit.equal(editor.selection.getStart().nodeName, 'BODY');
editor.settings.forced_root_block = 'p';
});
suite.test('Remove UL with multiple LI in BR mode', function (editor) {
editor.settings.forced_root_block = false;
editor.getBody().innerHTML = LegacyUnit.trimBrs(
''
);
editor.focus();
LegacyUnit.setSelection(editor, 'li:first', 1, 'li:last', 1);
LegacyUnit.execCommand(editor, 'InsertUnorderedList');
LegacyUnit.equal(editor.getContent(),
'a
' +
'b'
);
LegacyUnit.equal(editor.selection.getStart().nodeName, 'BODY');
editor.settings.forced_root_block = 'p';
});
suite.test('Remove empty UL between two textblocks', function (editor) {
editor.getBody().innerHTML = LegacyUnit.trimBrs(
'a
' +
'' +
'b
'
);
editor.focus();
LegacyUnit.setSelection(editor, 'li:first', 0);
LegacyUnit.execCommand(editor, 'InsertUnorderedList');
LegacyUnit.equal(editor.getContent(),
'a
' +
'\u00a0
' +
'b
'
);
LegacyUnit.equal(editor.selection.getNode().nodeName, 'P');
});
suite.test('Remove indented list with single item', function (editor) {
editor.getBody().innerHTML = LegacyUnit.trimBrs(
'' +
'- a' +
'' +
'
' +
'- c
' +
'
'
);
editor.focus();
LegacyUnit.setSelection(editor, 'li li', 0, 'li li', 1);
LegacyUnit.execCommand(editor, 'InsertUnorderedList');
LegacyUnit.equal(editor.getContent(),
'' +
'b
' +
''
);
LegacyUnit.equal(editor.selection.getNode().nodeName, 'P');
});
suite.test('Remove indented list with multiple items', function (editor) {
editor.getBody().innerHTML = LegacyUnit.trimBrs(
'' +
'- a' +
'' +
'
' +
'- d
' +
'
'
);
editor.focus();
LegacyUnit.setSelection(editor, 'li li:first', 0, 'li li:last', 1);
LegacyUnit.execCommand(editor, 'InsertUnorderedList');
LegacyUnit.equal(editor.getContent(),
'' +
'b
' +
'c
' +
''
);
LegacyUnit.equal(editor.selection.getStart().firstChild.data, 'b');
LegacyUnit.equal(editor.selection.getEnd().firstChild.data, 'c');
});
suite.test('Remove indented list with multiple items', function (editor) {
editor.getBody().innerHTML = LegacyUnit.trimBrs(
''
);
editor.focus();
LegacyUnit.setSelection(editor, 'p', 0);
LegacyUnit.execCommand(editor, 'InsertUnorderedList');
LegacyUnit.equal(editor.getContent(),
'' +
'b
' +
''
);
});
// Ignore on IE 7, 8 this is a known bug not worth fixing
if (!Env.ie || Env.ie > 8) {
suite.test('Remove empty UL between two textblocks in BR mode', function (editor) {
editor.settings.forced_root_block = false;
editor.getBody().innerHTML = LegacyUnit.trimBrs(
'a
' +
'' +
'b
'
);
editor.focus();
LegacyUnit.setSelection(editor, 'li:first', 0);
LegacyUnit.execCommand(editor, 'InsertUnorderedList');
LegacyUnit.equal(editor.getContent(),
'a
' +
'
' +
'b
'
);
LegacyUnit.equal(editor.selection.getStart().nodeName, 'BR');
editor.settings.forced_root_block = 'p';
});
}
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);
});