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( '
    ' + '
  1. a' + '
      ' + '
    1. b
    2. ' + '
    3. c
    4. ' + '
    ' + '
  2. ' + '
' ); editor.focus(); LegacyUnit.setSelection(editor, 'li li', 1); LegacyUnit.execCommand(editor, 'Outdent'); LegacyUnit.equal(editor.getContent(), '
    ' + '
  1. a
  2. ' + '
  3. b' + '
      ' + '
    1. c
    2. ' + '
    ' + '
  4. ' + '
' ); 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( '
    ' + '
  1. a' + '
      ' + '
    1. b
    2. ' + '
    3. c
    4. ' + '
    5. d
    6. ' + '
    ' + '
  2. ' + '
' ); editor.focus(); LegacyUnit.setSelection(editor, 'li li:nth-child(2)', 1); LegacyUnit.execCommand(editor, 'Outdent'); LegacyUnit.equal(editor.getContent(), '
    ' + '
  1. a' + '
      ' + '
    1. b
    2. ' + '
    ' + '
  2. ' + '
  3. c' + '
      ' + '
    1. d
    2. ' + '
    ' + '
  4. ' + '
' ); 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( '
    ' + '
  1. a' + '
      ' + '
    1. b
    2. ' + '
    3. c
    4. ' + '
    ' + '
  2. ' + '
' ); editor.focus(); LegacyUnit.setSelection(editor, 'li li:last', 1); LegacyUnit.execCommand(editor, 'Outdent'); LegacyUnit.equal(editor.getContent(), '
    ' + '
  1. a' + '
      ' + '
    1. b
    2. ' + '
    ' + '
  2. ' + '
  3. c
  4. ' + '
' ); 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( '
    ' + '
  1. a
  2. ' + '
      ' + '
    1. b
    2. ' + '
    3. c
    4. ' + '
    ' + '
' ); editor.focus(); LegacyUnit.setSelection(editor, 'ol ol li', 1); LegacyUnit.execCommand(editor, 'Outdent'); LegacyUnit.equal(editor.getContent(), '
    ' + '
  1. a
  2. ' + '
  3. b
  4. ' + '
      ' + '
    1. c
    2. ' + '
    ' + '
' ); 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( '
    ' + '
  1. a
  2. ' + '
      ' + '
    1. b
    2. ' + '
    3. c
    4. ' + '
    5. d
    6. ' + '
    ' + '
' ); editor.focus(); LegacyUnit.setSelection(editor, 'ol ol li:nth-child(2)', 1); LegacyUnit.execCommand(editor, 'Outdent'); LegacyUnit.equal(editor.getContent(), '
    ' + '
  1. a
  2. ' + '
      ' + '
    1. b
    2. ' + '
    ' + '
  3. c
  4. ' + '
      ' + '
    1. d
    2. ' + '
    ' + '
' ); 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. 1' + '
      ' + '
    1. 2
    2. ' + '
    3. 3
    4. ' + '
    ' + '
  2. ' + '
  3. 4
  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. 1
  2. ' + '
  3. 2
  4. ' + '
  5. 3
  6. ' + '
  7. 4
  8. ' + '
' ); 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( '
    ' + '
  1. a
  2. ' + '
  3. ' + '
      ' + '
    1. b
    2. ' + '
    3. c
    4. ' + '
    ' + '
  4. ' + '
' ); editor.focus(); LegacyUnit.setSelection(editor, 'ol ol li:first', 0); LegacyUnit.execCommand(editor, 'Outdent'); LegacyUnit.equal(editor.getContent(), '
    ' + '
  1. a
  2. ' + '
  3. b' + '
      ' + '
    1. c
    2. ' + '
    ' + '
  4. ' + '
' ); 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( '
    ' + '
  1. a
  2. ' + '
      ' + '
    1. b
    2. ' + '
    3. c
    4. ' + '
    ' + '
' ); editor.focus(); LegacyUnit.setSelection(editor, 'ol ol li:last', 1); LegacyUnit.execCommand(editor, 'Outdent'); LegacyUnit.equal(editor.getContent(), '
    ' + '
  1. a
  2. ' + '
      ' + '
    1. b
    2. ' + '
    ' + '
  3. c
  4. ' + '
' ); 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( '
    ' + '
  1. a' + '
      ' + '
    1. b
    2. ' + '
    ' + '
  2. ' + '
' ); editor.focus(); LegacyUnit.setSelection(editor, 'ol ol li', 0); LegacyUnit.execCommand(editor, 'Outdent'); LegacyUnit.equal(editor.getContent(), '
    ' + '
  1. a
  2. ' + '
  3. b
  4. ' + '
' ); LegacyUnit.equal(editor.selection.getNode().nodeName, 'LI'); }); suite.test('Outdent multiple LI in OL and nested OL', function (editor) { editor.getBody().innerHTML = LegacyUnit.trimBrs( '
    ' + '
  1. a' + '
      ' + '
    1. b
    2. ' + '
    ' + '
  2. ' + '
' ); editor.focus(); LegacyUnit.setSelection(editor, 'li', 0, 'li li', 1); LegacyUnit.execCommand(editor, 'Outdent'); LegacyUnit.equal(editor.getContent(), '

a

' + '
    ' + '
  1. b
  2. ' + '
' ); }); 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( '' ); 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); });