import { describe, it } from '@ephox/bedrock-client'; import { TinyAssertions, TinyHooks, TinySelections } from '@ephox/wrap-mcagar'; import { assert } from 'chai'; import Editor from 'tinymce/core/api/Editor'; describe('browser.tinymce.core.commands.OutdentCommandTest', () => { const hook = TinyHooks.bddSetupLight({ base_url: '/project/tinymce/js/tinymce', indent: false }, [], true); const assertOutdentCommandState = (editor: Editor, expectedState: boolean) => { assert.equal(editor.queryCommandState('outdent'), expectedState); }; const setReadOnly = (editor: Editor, state: boolean) => { editor.mode.set(state ? 'readonly' : 'design'); }; it('Outdent on single paragraph without margin/padding', () => { const editor = hook.editor(); editor.setContent('

a

'); assertOutdentCommandState(editor, false); editor.execCommand('outdent'); TinyAssertions.assertContent(editor, '

a

'); }); it('Outdent on multiple paragraphs without margin/padding', () => { const editor = hook.editor(); editor.setContent('

a

b

'); TinySelections.setSelection(editor, [ 0, 0 ], 0, [ 1, 0 ], 1); assertOutdentCommandState(editor, true); editor.execCommand('outdent'); TinyAssertions.assertContent(editor, '

a

b

'); }); it('Outdent on single paragraph with margin', () => { const editor = hook.editor(); editor.options.set('indent_use_margin', true); editor.setContent('

a

'); assertOutdentCommandState(editor, true); editor.execCommand('outdent'); TinyAssertions.assertContent(editor, '

a

'); }); it('Outdent on single paragraph with padding', () => { const editor = hook.editor(); editor.options.set('indent_use_margin', false); editor.setContent('

a

'); assertOutdentCommandState(editor, true); editor.execCommand('outdent'); TinyAssertions.assertContent(editor, '

a

'); }); it('Outdent on single paragraph with margin x 2', () => { const editor = hook.editor(); editor.options.set('indent_use_margin', false); editor.setContent('

a

'); assertOutdentCommandState(editor, true); editor.execCommand('outdent'); TinyAssertions.assertContent(editor, '

a

'); }); it('Outdent on single paragraph with padding x 2', () => { const editor = hook.editor(); editor.options.set('indent_use_margin', true); editor.setContent('

a

'); assertOutdentCommandState(editor, true); editor.execCommand('outdent'); TinyAssertions.assertContent(editor, '

a

'); }); it('Outdent on mutiple paragraphs with margin', () => { const editor = hook.editor(); editor.options.set('indent_use_margin', true); editor.setContent('

a

b

'); TinySelections.setSelection(editor, [ 0, 0 ], 0, [ 1, 0 ], 1); assertOutdentCommandState(editor, true); editor.execCommand('outdent'); TinyAssertions.assertContent(editor, '

a

b

'); }); it('Outdent on multiple paragraphs with padding', () => { const editor = hook.editor(); editor.options.set('indent_use_margin', false); editor.setContent('

a

b

'); TinySelections.setSelection(editor, [ 0, 0 ], 0, [ 1, 0 ], 1); assertOutdentCommandState(editor, true); editor.execCommand('outdent'); TinyAssertions.assertContent(editor, '

a

b

'); }); it('Outdent on single paragraph with padding and rtl', () => { const editor = hook.editor(); editor.options.set('indent_use_margin', false); editor.setContent('

a

'); assertOutdentCommandState(editor, true); editor.execCommand('outdent'); TinyAssertions.assertContent(editor, '

a

'); }); it('Outdent on single paragraph with margin and rtl', () => { const editor = hook.editor(); editor.options.set('indent_use_margin', true); editor.setContent('

a

'); assertOutdentCommandState(editor, true); editor.execCommand('outdent'); TinyAssertions.assertContent(editor, '

a

'); }); it('Outdent on single paragraph with margin in readonly mode', () => { const editor = hook.editor(); setReadOnly(editor, true); editor.options.set('indent_use_margin', true); editor.setContent('

a

'); assertOutdentCommandState(editor, false); editor.execCommand('outdent'); TinyAssertions.assertContent(editor, '

a

'); setReadOnly(editor, false); }); it('Outdent on selected table using margin', () => { const editor = hook.editor(); editor.options.set('indent_use_margin', true); editor.setContent('
a
'); editor.execCommand('SelectAll'); assertOutdentCommandState(editor, true); editor.execCommand('outdent'); TinyAssertions.assertContent(editor, '
a
'); }); it('Outdent on selected table always using margin', () => { const editor = hook.editor(); editor.options.set('indent_use_margin', false); editor.setContent('
a
'); editor.execCommand('SelectAll'); assertOutdentCommandState(editor, true); editor.execCommand('outdent'); TinyAssertions.assertContent(editor, '
a
'); }); it('Outdent on contentEditable=false', () => { const editor = hook.editor(); editor.options.set('indent_use_margin', true); editor.setContent('

a

'); TinySelections.setCursor(editor, [ 1, 0, 0 ], 0); editor.execCommand('outdent'); TinyAssertions.assertContent(editor, '

a

'); }); });