import { beforeEach, context, describe, it } from '@ephox/bedrock-client'; import { LegacyUnit, TinyAssertions, TinyHooks, TinySelections } from '@ephox/wrap-mcagar'; import { assert } from 'chai'; import Editor from 'tinymce/core/api/Editor'; import Plugin from 'tinymce/plugins/lists/Plugin'; describe('browser.tinymce.plugins.lists.IndentTest', () => { const hook = TinyHooks.bddSetupLight({ 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|start],' + 'ul[style|class|data-custom],dl,dt,dd,em,strong,span,#p,div,br,table,tr,td', 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' }, base_url: '/project/tinymce/js/tinymce' }, [ Plugin ]); beforeEach(() => { hook.editor().focus(); }); it('TBA: Indent single LI in OL', () => { const editor = hook.editor(); editor.setContent( '
    ' + '
  1. a
  2. ' + '
' ); LegacyUnit.setSelection(editor, 'li', 0); editor.execCommand('Indent'); TinyAssertions.assertContent( editor, '
    ' + '
  1. ' + '
      ' + '
    1. a
    2. ' + '
    ' + '
  2. ' + '
' ); assert.equal(editor.selection.getNode().nodeName, 'LI'); }); it('TBA: Indent middle LI in OL', () => { const editor = hook.editor(); editor.setContent( '
    ' + '
  1. a
  2. ' + '
  3. b
  4. ' + '
  5. c
  6. ' + '
' ); LegacyUnit.setSelection(editor, 'li:nth-child(2)', 0); editor.execCommand('Indent'); TinyAssertions.assertContent(editor, '
    ' + '
  1. a' + '
      ' + '
    1. b
    2. ' + '
    ' + '
  2. ' + '
  3. c
  4. ' + '
' ); assert.equal(editor.selection.getNode().nodeName, 'LI'); }); it('TBA: Indent single LI in OL and retain OLs list style in the new OL', () => { const editor = hook.editor(); editor.setContent( '
    ' + '
  1. a
  2. ' + '
  3. b
  4. ' + '
' ); LegacyUnit.setSelection(editor, 'li:nth-child(2)', 0); editor.execCommand('Indent'); TinyAssertions.assertContent(editor, '
    ' + '
  1. a' + '
      ' + '
    1. b
    2. ' + '
    ' + '
  2. ' + '
' ); }); it('TBA: Indent last LI in OL', () => { const editor = hook.editor(); editor.setContent( '
    ' + '
  1. a
  2. ' + '
  3. b
  4. ' + '
' ); LegacyUnit.setSelection(editor, 'li:last-of-type', 0); editor.execCommand('Indent'); TinyAssertions.assertContent(editor, '
    ' + '
  1. a' + '
      ' + '
    1. b
    2. ' + '
    ' + '
  2. ' + '
' ); assert.equal(editor.selection.getNode().nodeName, 'LI'); }); it('TBA: Indent in table cell in table inside of list should not do anything', () => { const editor = hook.editor(); editor.setContent( '
    ' + '
  1. ' + '' + '' + '' + '' + '
    ' + '
  2. ' + '
' ); LegacyUnit.setSelection(editor, 'td', 0); editor.execCommand('Indent'); TinyAssertions.assertContent(editor, '
    ' + '
  1. ' + '' + '' + '' + '' + '
    ' + '
  2. ' + '
' ); assert.equal(editor.selection.getNode().nodeName, 'TD'); }); it('TBA: Indent last LI to same level as middle LI', () => { const editor = hook.editor(); editor.setContent( '
    ' + '
  1. a' + '
      ' + '
    1. b
    2. ' + '
    ' + '
  2. ' + '
  3. c
  4. ' + '
' ); LegacyUnit.setSelection(editor, 'li:nth-child(2)', 1); editor.execCommand('Indent'); TinyAssertions.assertContent(editor, '
    ' + '
  1. a' + '
      ' + '
    1. b
    2. ' + '
    3. c
    4. ' + '
    ' + '
  2. ' + '
' ); assert.equal(editor.selection.getNode().nodeName, 'LI'); }); it('TBA: Indent first LI and nested LI OL', () => { const editor = hook.editor(); editor.setContent( '
    ' + '
  1. a' + '
      ' + '
    1. b
    2. ' + '
    ' + '
  2. ' + '
' ); LegacyUnit.setSelection(editor, 'li', 0, 'li li', 0); editor.execCommand('Indent'); TinyAssertions.assertContent(editor, '
    ' + '
  1. ' + '
      ' + '
    1. a' + '
        ' + '
      1. b
      2. ' + '
      ' + '
    2. ' + '
    ' + '
  2. ' + '
' ); assert.equal(editor.selection.getNode().nodeName, 'LI'); }); it('TBA: Indent second LI to same level as nested LI', () => { const editor = hook.editor(); editor.setContent( '' ); LegacyUnit.setSelection(editor, 'li:nth-child(2)', 0); editor.execCommand('Indent'); TinyAssertions.assertContent(editor, '' ); assert.equal(editor.selection.getNode().nodeName, 'LI'); }); it('TBA: Indent second LI to same level as nested LI 2', () => { const editor = hook.editor(); editor.setContent( '' ); LegacyUnit.setSelection(editor, 'li:nth-child(2)', 1); editor.execCommand('Indent'); TinyAssertions.assertContent(editor, '' ); assert.equal(editor.selection.getNode().nodeName, 'LI'); }); it('TBA: Indent second and third LI', () => { const editor = hook.editor(); editor.setContent( '' ); LegacyUnit.setSelection(editor, 'li:nth-child(2)', 0, 'li:last-of-type', 0); editor.execCommand('Indent'); TinyAssertions.assertContent(editor, '' ); }); it('TBA: Indent second second li with next sibling to nested li', () => { const editor = hook.editor(); editor.setContent( '' ); LegacyUnit.setSelection(editor, 'ul > li:nth-child(2)', 1); editor.execCommand('Indent'); TinyAssertions.assertContent(editor, '' ); }); it('TBA: Indent on second li with inner block element', () => { const editor = hook.editor(); editor.setContent( '' ); LegacyUnit.setSelection(editor, 'ul > li:nth-child(2) > p', 0); editor.execCommand('Indent'); TinyAssertions.assertContent(editor, '' ); }); it('Indent already indented last li, ul in ol', () => { const editor = hook.editor(); editor.setContent( '
    ' + '
  1. a' + '
      ' + '
    • b
    • ' + '
    ' + '
  2. ' + '
' ); LegacyUnit.setSelection(editor, 'ul li', 0); editor.execCommand('Indent'); TinyAssertions.assertContent(editor, '
    ' + '
  1. a' + '
      ' + '
    • ' + '
        ' + '
      • b
      • ' + '
      ' + '
    • ' + '
    ' + '
  2. ' + '
' ); }); it('TBA: Indent single LI in OL with start attribute', () => { const editor = hook.editor(); editor.setContent( '
    ' + '
  1. a
  2. ' + '
' ); LegacyUnit.setSelection(editor, 'li', 0); editor.execCommand('Indent'); TinyAssertions.assertContent(editor, '
    ' + '
  1. ' + '
      ' + '
    1. a
    2. ' + '
    ' + '
  2. ' + '
' ); assert.equal(editor.selection.getNode().nodeName, 'LI'); }); it('TBA: Indent first LI and nested LI OL with start attributes', () => { const editor = hook.editor(); editor.setContent( '
    ' + '
  1. a
  2. ' + '
  3. ' + '
      ' + '
    1. b
    2. ' + '
    ' + '
  4. ' + '
' ); LegacyUnit.setSelection(editor, 'li', 0); editor.execCommand('Indent'); TinyAssertions.assertContent(editor, '
    ' + '
  1. ' + '
      ' + '
    1. a
    2. ' + '
    3. b
    4. ' + '
    ' + '
  2. ' + '
' ); assert.equal(editor.selection.getNode().nodeName, 'LI'); }); context('Parent context', () => { const testCommandAtTextPath = (command: string) => (inputHtml: string, path: number[], expectedHtml: string) => () => { const editor = hook.editor(); editor.setContent(inputHtml); TinySelections.setCursor(editor, path, 0); editor.execCommand(command); TinyAssertions.assertContent(editor, expectedHtml); }; const testIndentAtTextPath = testCommandAtTextPath('Indent'); const testOutdentAtTextPath = testCommandAtTextPath('Outdent'); it('TINY-7209: indent list item inside div inside list item', testIndentAtTextPath( '', [ 0, 0, 1, 0, 0, 0 ], '' )); it('TINY-7209: indent list item with a paragraph inside div inside a list item', testIndentAtTextPath( '', [ 0, 0, 1, 0, 0, 0, 0 ], '' )); it('TINY-7209: outdent list item inside a div inside a list item', testOutdentAtTextPath( '', [ 0, 0, 1, 0, 0, 0 ], '' )); it('TINY-7209: outdent list item with a paragraph inside div inside a list item', testOutdentAtTextPath( '', [ 0, 0, 1, 0, 0, 0 ], '' )); }); });