@@ -7,8 +7,14 @@ import { eachVersionContext, editorHook } from '../alien/TestHooks';
77import { Editor } from 'tinymce' ;
88
99describe ( 'DisabledPropertyTest' , ( ) => {
10- const assertDesignMode = ( editor : Editor ) => Assertions . assertEq ( 'TinyMCE should be in design mode' , 'design' , editor . mode . get ( ) ) ;
11- const assertReadonlyMode = ( editor : Editor ) => Assertions . assertEq ( 'TinyMCE should be in readonly mode' , 'readonly' , editor . mode . get ( ) ) ;
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 ) ) ;
1218 const assertDisabledOption = ( editor : Editor , expected : boolean ) =>
1319 Assertions . assertEq ( `TinyMCE should have disabled option set to ${ expected } ` , expected , editor . options . get ( 'disabled' ) ) ;
1420
@@ -34,13 +40,23 @@ describe('DisabledPropertyTest', () => {
3440 fixture . detectChanges ( ) ;
3541 assertDesignMode ( editor ) ;
3642 } ) ;
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+ } ) ;
3753 } ) ;
3854
3955 eachVersionContext ( [ '7.6.0' ] , ( ) => {
4056 const createFixture = editorHook ( EditorComponent ) ;
4157
4258 it ( `Component 'disabled' property is mapped to editor 'disabled' property` , async ( ) => {
43- const { editor } = await createFixture ( { cloudChannel : '7.6.0' , disabled : true } ) ;
59+ const { editor } = await createFixture ( { disabled : true } ) ;
4460
4561 Assertions . assertEq ( 'TinyMCE should have disabled option set to true' , true , editor . options . get ( 'disabled' ) ) ;
4662 assertDesignMode ( editor ) ;
@@ -64,4 +80,28 @@ describe('DisabledPropertyTest', () => {
6480 assertDisabledOption ( editor , false ) ;
6581 } ) ;
6682 } ) ;
67- } ) ;
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