|
| 1 | +import { Assertions } from '@ephox/agar'; |
| 2 | +import '../alien/InitTestEnvironment'; |
| 3 | + |
| 4 | +import { EditorComponent } from '../../../main/ts/public_api'; |
| 5 | +import { describe, it } from '@ephox/bedrock-client'; |
| 6 | +import { eachVersionContext, editorHook } from '../alien/TestHooks'; |
| 7 | +import { Editor } from 'tinymce'; |
| 8 | + |
| 9 | +describe('DisabledPropertyTest', () => { |
| 10 | + const getMode = (editor: Editor) => { |
| 11 | + if (typeof editor.mode?.get === 'function') { |
| 12 | + return editor.mode.get(); |
| 13 | + } |
| 14 | + return editor.readonly ? 'readonly' : 'design'; |
| 15 | + }; |
| 16 | + const assertDesignMode = (editor: Editor) => Assertions.assertEq('TinyMCE should be in design mode', 'design', getMode(editor)); |
| 17 | + const assertReadonlyMode = (editor: Editor) => Assertions.assertEq('TinyMCE should be in readonly mode', 'readonly', getMode(editor)); |
| 18 | + const assertDisabledOption = (editor: Editor, expected: boolean) => |
| 19 | + Assertions.assertEq(`TinyMCE should have disabled option set to ${expected}`, expected, editor.options.get('disabled')); |
| 20 | + |
| 21 | + eachVersionContext([ '7.5.0' ], () => { |
| 22 | + const createFixture = editorHook(EditorComponent); |
| 23 | + |
| 24 | + it(`Component 'disabled' property is mapped to editor 'readonly' property`, async () => { |
| 25 | + const { editor } = await createFixture({ disabled: true }); |
| 26 | + assertReadonlyMode(editor); |
| 27 | + }); |
| 28 | + |
| 29 | + it(`Toggling component's 'disabled' property is mapped to editor 'readonly' property`, async () => { |
| 30 | + const fixture = await createFixture(); |
| 31 | + const { editor } = fixture; |
| 32 | + |
| 33 | + assertDesignMode(editor); |
| 34 | + |
| 35 | + fixture.componentRef.setInput('disabled', true); |
| 36 | + fixture.detectChanges(); |
| 37 | + assertReadonlyMode(editor); |
| 38 | + |
| 39 | + fixture.componentRef.setInput('disabled', false); |
| 40 | + fixture.detectChanges(); |
| 41 | + assertDesignMode(editor); |
| 42 | + }); |
| 43 | + |
| 44 | + it(`[disabled]=true [readonly]=false triggers readonly mode`, async () => { |
| 45 | + const { editor } = await createFixture({ disabled: true, readonly: false }); |
| 46 | + assertReadonlyMode(editor); |
| 47 | + }); |
| 48 | + |
| 49 | + it(`[disabled]=false [readonly]=true triggers readonly mode`, async () => { |
| 50 | + const { editor } = await createFixture({ disabled: false, readonly: true }); |
| 51 | + assertReadonlyMode(editor); |
| 52 | + }); |
| 53 | + }); |
| 54 | + |
| 55 | + eachVersionContext([ '7' ], () => { |
| 56 | + const createFixture = editorHook(EditorComponent); |
| 57 | + |
| 58 | + it(`Component 'disabled' property is mapped to editor 'disabled' property`, async () => { |
| 59 | + const { editor } = await createFixture({ disabled: true }); |
| 60 | + |
| 61 | + Assertions.assertEq('TinyMCE should have disabled option set to true', true, editor.options.get('disabled')); |
| 62 | + assertDesignMode(editor); |
| 63 | + }); |
| 64 | + |
| 65 | + it(`Toggling component's 'disabled' property is mapped to editor 'disabled' property`, async () => { |
| 66 | + const fixture = await createFixture(); |
| 67 | + const { editor } = fixture; |
| 68 | + |
| 69 | + assertDesignMode(editor); |
| 70 | + assertDisabledOption(editor, false); |
| 71 | + |
| 72 | + fixture.componentRef.setInput('disabled', true); |
| 73 | + fixture.detectChanges(); |
| 74 | + assertDesignMode(editor); |
| 75 | + assertDisabledOption(editor, true); |
| 76 | + |
| 77 | + fixture.componentRef.setInput('disabled', false); |
| 78 | + fixture.detectChanges(); |
| 79 | + assertDesignMode(editor); |
| 80 | + assertDisabledOption(editor, false); |
| 81 | + }); |
| 82 | + }); |
| 83 | + |
| 84 | + eachVersionContext([ '4', '5', '6', '7' ], () => { |
| 85 | + const createFixture = editorHook(EditorComponent); |
| 86 | + |
| 87 | + it(`Setting the 'readonly' property causing readonly mode`, async () => { |
| 88 | + const { editor } = await createFixture({ readonly: true }); |
| 89 | + assertReadonlyMode(editor); |
| 90 | + }); |
| 91 | + |
| 92 | + it(`Toggling component's 'readonly' property is mapped to editor 'readonly' mode`, async () => { |
| 93 | + const fixture = await createFixture(); |
| 94 | + const { editor } = fixture; |
| 95 | + |
| 96 | + assertDesignMode(editor); |
| 97 | + |
| 98 | + fixture.componentRef.setInput('readonly', true); |
| 99 | + fixture.detectChanges(); |
| 100 | + assertReadonlyMode(editor); |
| 101 | + |
| 102 | + fixture.componentRef.setInput('readonly', false); |
| 103 | + fixture.detectChanges(); |
| 104 | + assertDesignMode(editor); |
| 105 | + }); |
| 106 | + }); |
| 107 | +}); |
0 commit comments