import { describe, it } from '@ephox/bedrock-client'; import { LegacyUnit, TinyAssertions, TinySelections, TinyHooks } 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.RemoveTest', () => { 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],' + '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' }, base_url: '/project/tinymce/js/tinymce' }, [ Plugin ], true); it('TBA: Remove UL at single LI', () => { const editor = hook.editor(); editor.setContent( '' ); LegacyUnit.setSelection(editor, 'li', 0); editor.execCommand('InsertUnorderedList'); TinyAssertions.assertContent(editor, '

a

'); assert.equal(editor.selection.getStart().nodeName, 'P'); }); it('TBA: Remove UL at start LI', () => { const editor = hook.editor(); editor.setContent( '' ); LegacyUnit.setSelection(editor, 'li', 0); editor.execCommand('InsertUnorderedList'); TinyAssertions.assertContent(editor, '

a

' + '' ); assert.equal(editor.selection.getStart().nodeName, 'P'); }); it('TBA: Remove UL at start empty LI', () => { const editor = hook.editor(); editor.setContent( '' ); LegacyUnit.setSelection(editor, 'li', 0); editor.execCommand('InsertUnorderedList'); TinyAssertions.assertContent(editor, '

\u00a0

' + '' ); assert.equal(editor.selection.getNode().nodeName, 'P'); }); it('TBA: Remove UL at middle LI', () => { const editor = hook.editor(); editor.setContent( '' ); LegacyUnit.setSelection(editor, 'li:nth-child(2)', 1); editor.execCommand('InsertUnorderedList'); TinyAssertions.assertContent(editor, '' + '

b

' + '' ); assert.equal(editor.selection.getStart().nodeName, 'P'); }); it('TBA: Remove UL at middle empty LI', () => { const editor = hook.editor(); editor.setContent( '' ); LegacyUnit.setSelection(editor, 'li:nth-child(2)', 0); editor.execCommand('InsertUnorderedList'); TinyAssertions.assertContent(editor, '' + '

\u00a0

' + '' ); assert.equal(editor.selection.getNode().nodeName, 'P'); }); it('TBA: Remove UL at end LI', () => { const editor = hook.editor(); editor.setContent( '' ); LegacyUnit.setSelection(editor, 'li:last-of-type', 1); editor.execCommand('InsertUnorderedList'); TinyAssertions.assertContent(editor, '' + '

c

' ); assert.equal(editor.selection.getStart().nodeName, 'P'); }); it('TBA: Remove UL at end empty LI', () => { const editor = hook.editor(); editor.setContent( '' ); LegacyUnit.setSelection(editor, 'li:last-of-type', 0); editor.execCommand('InsertUnorderedList'); TinyAssertions.assertContent(editor, '' + '

\u00a0

' ); assert.equal(editor.selection.getNode().nodeName, 'P'); }); it('TBA: Remove UL at middle LI inside parent OL', () => { const editor = hook.editor(); editor.setContent( '
    ' + '
  1. a
  2. ' + '' + '
  3. e
  4. ' + '
' ); LegacyUnit.setSelection(editor, 'ul li:nth-child(2)', 1); editor.execCommand('InsertUnorderedList'); TinyAssertions.assertContent(editor, '
    ' + '
  1. a' + '
      ' + '
    • b
    • ' + '
    ' + '
  2. ' + '
' + '

c

' + '
    ' + '
  1. ' + '
      ' + '
    • d
    • ' + '
    ' + '
  2. ' + '
  3. e
  4. ' + '
' ); assert.equal(editor.selection.getStart().nodeName, 'P'); }); it('TBA: Remove UL at middle LI inside parent OL (html5)', () => { const editor = hook.editor(); editor.setContent( '
    ' + '
  1. a' + '
      ' + '
    • b
    • ' + '
    • c
    • ' + '
    • d
    • ' + '
    ' + '
  2. ' + '
  3. e
  4. ' + '
' ); LegacyUnit.setSelection(editor, 'ul li:nth-child(2)', 1); editor.execCommand('InsertUnorderedList'); TinyAssertions.assertContent(editor, '
    ' + '
  1. a' + '
      ' + '
    • b
    • ' + '
    ' + '
  2. ' + '
' + '

c

' + '
    ' + '
  1. ' + '
      ' + '
    • d
    • ' + '
    ' + '
  2. ' + '
  3. e
  4. ' + '
' ); assert.equal(editor.selection.getStart().nodeName, 'P'); }); it('TBA: Remove OL on a deep nested LI', () => { const editor = hook.editor(); editor.setContent( '
    ' + '
  1. a' + '
      ' + '
    1. b
    2. ' + '
    3. c' + '
        ' + '
      1. d
      2. ' + '
      3. e
      4. ' + '
      5. f
      6. ' + '
      ' + '
    4. ' + '
    5. g
    6. ' + '
    7. h
    8. ' + '
    ' + '
  2. ' + '
  3. i
  4. ' + '
' ); LegacyUnit.setSelection(editor, 'ol ol ol li:nth-child(2)', 1); editor.execCommand('InsertOrderedList'); TinyAssertions.assertContent(editor, '
    ' + '
  1. a' + '
      ' + '
    1. b
    2. ' + '
    3. c' + '
        ' + '
      1. d
      2. ' + '
      ' + '
    4. ' + '
    ' + '
  2. ' + '
' + '

e

' + '
    ' + '
  1. ' + '
      ' + '
    1. ' + '
        ' + '
      1. f
      2. ' + '
      ' + '
    2. ' + '
    3. g
    4. ' + '
    5. h
    6. ' + '
    ' + '
  2. ' + '
  3. i
  4. ' + '
' ); assert.equal(editor.selection.getStart().nodeName, 'P'); }); it('TBA: Remove empty UL between two textblocks', () => { const editor = hook.editor(); editor.setContent( '
a
' + '' + '
b
' ); LegacyUnit.setSelection(editor, 'li:first-of-type', 0); editor.execCommand('InsertUnorderedList'); TinyAssertions.assertContent(editor, '
a
' + '

\u00a0

' + '
b
' ); assert.equal(editor.selection.getNode().nodeName, 'P'); }); it('TBA: Remove indented list with single item', () => { const editor = hook.editor(); editor.setContent( '' ); LegacyUnit.setSelection(editor, 'li li', 0, 'li li', 1); editor.execCommand('InsertUnorderedList'); TinyAssertions.assertContent(editor, '' + '

b

' + '' ); assert.equal(editor.selection.getNode().nodeName, 'P'); }); it('TBA: Remove indented list with multiple items', () => { const editor = hook.editor(); editor.setContent( '' ); LegacyUnit.setSelection(editor, 'li li:first-of-type', 0, 'li li:last-of-type', 1); editor.execCommand('InsertUnorderedList'); TinyAssertions.assertContent(editor, '' + '

b

' + '

c

' + '' ); assert.equal((editor.selection.getStart().firstChild as Text).data, 'b'); assert.equal((editor.selection.getEnd().firstChild as Text).data, 'c'); }); it('TBA: Remove indented list with multiple items and paragraph', () => { const editor = hook.editor(); editor.setContent( '' ); LegacyUnit.setSelection(editor, 'p', 0); editor.execCommand('InsertUnorderedList'); TinyAssertions.assertContent(editor, '' + '

b

' + '' ); }); it('TINY-8068: Remove list inside a div inside a list item should only remove the nested list', () => { const editor = hook.editor(); editor.setContent(''); TinySelections.setCursor(editor, [ 0, 0, 0, 0, 0, 0 ], 0); editor.execCommand('InsertUnorderedList'); TinyAssertions.assertContent(editor, ''); }); });