import { describe, it } from '@ephox/bedrock-client';
import { TinyAssertions, TinyHooks, TinySelections, TinyUiActions } from '@ephox/wrap-mcagar';
import Plugin from 'tinymce/plugins/directionality/Plugin';
describe('browser.tinymce.plugins.directionality.DirectionalitySanityTest', () => {
const hook = TinyHooks.bddSetupLight({
plugins: 'directionality',
toolbar: 'ltr rtl',
base_url: '/project/tinymce/js/tinymce',
indent: false
}, [ Plugin ]);
it('TBA: Set and select content, click on the Right to left toolbar button and assert direction is right to left', () => {
const editor = hook.editor();
editor.setContent('a');
TinySelections.setSelection(editor, [ 0, 0 ], 0, [ 0, 0 ], 1);
TinyUiActions.clickOnToolbar(editor, 'button[title="Right to left"]');
TinyAssertions.assertContent(editor, '
a
');
});
it('TBA: Set and select content, click on the Left to right toolbar button and assert direction is left to right', () => {
const editor = hook.editor();
editor.setContent('a
');
TinySelections.setSelection(editor, [ 0, 0 ], 0, [ 0, 0 ], 1);
TinyUiActions.clickOnToolbar(editor, 'button[title="Left to right"]');
TinyAssertions.assertContent(editor, 'a
'); // as the default dir is ltr it just removes the dir attr
});
it('TINY-4589: should set two paragraphs to rtl and ltl', () => {
const editor = hook.editor();
editor.setContent('foo
bar
');
TinySelections.setSelection(editor, [ 0 ], 0, [ 1 ], 1);
TinyUiActions.clickOnToolbar(editor, 'button[title="Right to left"]');
TinyAssertions.assertContent(editor, 'foo
bar
');
TinyUiActions.clickOnToolbar(editor, 'button[title="Left to right"]');
TinyAssertions.assertContent(editor, 'foo
bar
');
});
it('TINY-4589: should set parent dir when element is a list item', () => {
const editor = hook.editor();
editor.setContent('');
TinySelections.setSelection(editor, [ 0, 0 ], 0, [ 0, 0 ], 1);
TinyUiActions.clickOnToolbar(editor, 'button[title="Right to left"]');
TinyAssertions.assertContent(editor, '');
TinyUiActions.clickOnToolbar(editor, 'button[title="Left to right"]');
TinyAssertions.assertContent(editor, '');
});
it('TINY-4589: should remove dir from selected list item and children', () => {
const editor = hook.editor();
editor.setContent(
'' +
'- foo' +
'' +
'
' +
'- bar
' +
'
'
);
TinySelections.setSelection(editor, [ 0, 0 ], 0, [ 0, 0 ], 1);
TinyUiActions.clickOnToolbar(editor, 'button[title="Right to left"]');
TinyAssertions.assertContent(editor,
'' +
'- foo' +
'' +
'
' +
'- bar
' +
'
'
);
});
it('TINY-4589: applying the same dir makes no changes', () => {
const editor = hook.editor();
const editorContent =
'';
editor.setContent(editorContent);
TinySelections.setSelection(editor, [ 0, 0, 1, 0 ], 0, [ 0, 0, 1, 0 ], 1); // foo
TinyUiActions.clickOnToolbar(editor, 'button[title="Left to right"]');
TinyAssertions.assertContent(editor, editorContent);
});
it('TINY-4589: should consider list item dir', () => {
const editor = hook.editor();
editor.setContent(
''
);
TinySelections.setSelection(editor, [ 0, 0, 1, 0 ], 0, [ 0, 0, 1, 0 ], 1); // foo
TinyUiActions.clickOnToolbar(editor, 'button[title="Right to left"]');
TinyAssertions.assertContent(editor,
''
);
});
it('TINY-4589: should remove dir attr if parent has same dir', () => {
const editor = hook.editor();
editor.setContent('');
TinySelections.setSelection(editor, [ 0, 0 ], 0, [ 0, 0 ], 1);
TinyUiActions.clickOnToolbar(editor, 'button[title="Right to left"]');
TinyAssertions.assertContent(editor, '');
TinyUiActions.clickOnToolbar(editor, 'button[title="Left to right"]');
TinyAssertions.assertContent(editor, '');
});
it('TINY-4589: should get computed dir from #target-elm', () => {
const editor = hook.editor();
editor.setContent(
''
);
TinySelections.setSelection(editor, [ 0, 0, 0, 0 ], 0, [ 0, 0, 0, 0 ], 1); // foo
TinyUiActions.clickOnToolbar(editor, 'button[title="Right to left"]');
TinyAssertions.assertContent(editor,
''
);
TinyUiActions.clickOnToolbar(editor, 'button[title="Left to right"]');
TinyAssertions.assertContent(editor,
''
);
});
});