Skip to content

Commit 25c73ae

Browse files
committed
TINY-11906: Add tests
1 parent 4c821ea commit 25c73ae

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

src/main/ts/components/Editor.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ type EditorOptions = Parameters<TinyMCE['init']>[0];
2121
export type InitOptions = Omit<OmitStringIndexSignature<EditorOptions>, OmittedInitProps> & {
2222
selector?: DoNotUse<'selector prop is handled internally by the component'>;
2323
target?: DoNotUse<'target prop is handled internally by the component'>;
24-
readonly?: DoNotUse<'readonly prop is overridden by the component, use the `disabled` prop instead'>;
24+
readonly?: DoNotUse<'readonly prop is overridden by the component'>;
25+
disabled?: DoNotUse<'disabled prop is overridden by the component'>;
2526
license_key?: DoNotUse<'license_key prop is overridden by the integration, use the `licenseKey` prop instead'>;
2627
} & { [key: string]: unknown };
2728

@@ -95,7 +96,7 @@ export interface IProps {
9596
toolbar: NonNullable<EditorOptions['toolbar']>;
9697
/**
9798
* @see {@link https://www.tiny.cloud/docs/tinymce/7/react-ref/#disabled React Tech Ref - disabled}
98-
* @description Whether the editor should be "disabled".
99+
* @description Whether the editor should be disabled.
99100
*/
100101
disabled: boolean;
101102
/**
@@ -214,10 +215,15 @@ export class Editor extends React.Component<IAllProps> {
214215
}
215216
});
216217
}
218+
217219
if (this.props.readonly !== prevProps.readonly) {
218220
const readonly = this.props.readonly ?? false;
219221
setMode(this.editor, readonly ? 'readonly' : 'design');
220222
}
223+
224+
if (this.props.disabled !== prevProps.disabled) {
225+
this.editor.options.set('disabled', this.props.disabled);
226+
}
221227
}
222228
}
223229
}

src/stories/Editor.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ export const ToggleReadonlyProp: StoryObj<Editor> = {
157157
readonly={readonly}
158158
/>
159159
<button onClick={toggleReadonly}>
160-
{readonly ? 'Enable Editor' : 'Disable Editor'}
160+
{readonly ? 'Set editable' : 'Set Readonly'}
161161
</button>
162162
</div>
163163
);

src/test/ts/browser/EditorInitTest.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,27 @@ describe('EditorInitTest', () => {
6969
TinyAssertions.assertContent(ctx.editor, '<p>New Value</p>');
7070
});
7171

72-
it('Disabled prop should disable editor', async () => {
72+
it('Disabled prop should disable editor', async function () {
73+
using ctx = await render();
74+
const editor = ctx.editor;
75+
const minorVersion = parseInt(editor.editorManager.minorVersion, 10);
76+
// disabled option was re-introduced in tinymce 7.6
77+
if (version !== '7' || minorVersion < 6) {
78+
this.skip();
79+
}
80+
81+
Assertions.assertEq('Should be enabled', false, editor.options.get('disabled'));
82+
await ctx.reRender({ ...defaultProps, disabled: true });
83+
Assertions.assertEq('Should be disabled', true,
84+
editor.options.get('disabled'));
85+
});
86+
87+
it('Readonly prop should set editor to readonly mode', async () => {
7388
using ctx = await render();
7489
Assertions.assertEq('Should be design mode', true, '4' === version ? !ctx.editor.readonly : ctx.editor.mode.get() === 'design');
7590
await ctx.reRender({ ...defaultProps, disabled: true });
7691
Assertions.assertEq('Should be readonly mode', true, '4' === version ? ctx.editor.readonly : ctx.editor.mode.get() === 'readonly');
92+
7793
});
7894

7995
it('Using an overriden props will cause a TS error', async () => {

0 commit comments

Comments
 (0)