-
Notifications
You must be signed in to change notification settings - Fork 94
Expand file tree
/
Copy pathDisabledPropertyTest.ts
More file actions
163 lines (132 loc) · 5.85 KB
/
DisabledPropertyTest.ts
File metadata and controls
163 lines (132 loc) · 5.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import { Assertions } from '@ephox/agar';
import '../alien/InitTestEnvironment';
import { EditorComponent } from '../../../main/ts/public_api';
import { after, before, context, describe, it } from '@ephox/bedrock-client';
import { eachVersionContext, editorHook } from '../alien/TestHooks';
import { Editor } from 'tinymce';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { Component, ViewChild } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { VersionLoader } from '@tinymce/miniature';
import { deleteTinymce } from '../alien/TestHelpers';
describe('DisabledPropertyTest', () => {
const getMode = (editor: Editor) => {
if (typeof editor.mode?.get === 'function') {
return editor.mode.get();
}
return editor.readonly ? 'readonly' : 'design';
};
const assertDesignMode = (editor: Editor) => Assertions.assertEq('TinyMCE should be in design mode', 'design', getMode(editor));
const assertReadonlyMode = (editor: Editor) => Assertions.assertEq('TinyMCE should be in readonly mode', 'readonly', getMode(editor));
const assertDisabledOption = (editor: Editor, expected: boolean) =>
Assertions.assertEq(`TinyMCE should have disabled option set to ${expected}`, expected, editor.options.get('disabled'));
eachVersionContext([ '7.5.0' ], () => {
const createFixture = editorHook(EditorComponent);
it(`Component 'disabled' property is mapped to editor 'readonly' property`, async () => {
const { editor } = await createFixture({ disabled: true });
assertReadonlyMode(editor);
});
it(`Toggling component's 'disabled' property is mapped to editor 'readonly' property`, async () => {
const fixture = await createFixture();
const { editor } = fixture;
assertDesignMode(editor);
fixture.componentRef.setInput('disabled', true);
fixture.detectChanges();
assertReadonlyMode(editor);
fixture.componentRef.setInput('disabled', false);
fixture.detectChanges();
assertDesignMode(editor);
});
it(`[disabled]=true [readonly]=false triggers readonly mode`, async () => {
const { editor } = await createFixture({ disabled: true, readonly: false });
assertReadonlyMode(editor);
});
it(`[disabled]=false [readonly]=true triggers readonly mode`, async () => {
const { editor } = await createFixture({ disabled: false, readonly: true });
assertReadonlyMode(editor);
});
});
eachVersionContext([ '7' ], () => {
const createFixture = editorHook(EditorComponent);
it(`Component 'disabled' property is mapped to editor 'disabled' property`, async () => {
const { editor } = await createFixture({ disabled: true });
Assertions.assertEq('TinyMCE should have disabled option set to true', true, editor.options.get('disabled'));
assertDesignMode(editor);
});
it(`Toggling component's 'disabled' property is mapped to editor 'disabled' property`, async () => {
const fixture = await createFixture();
const { editor } = fixture;
assertDesignMode(editor);
assertDisabledOption(editor, false);
fixture.componentRef.setInput('disabled', true);
fixture.detectChanges();
assertDesignMode(editor);
assertDisabledOption(editor, true);
fixture.componentRef.setInput('disabled', false);
fixture.detectChanges();
assertDesignMode(editor);
assertDisabledOption(editor, false);
});
});
eachVersionContext([ '4', '5', '6', '7' ], () => {
const createFixture = editorHook(EditorComponent);
it(`Setting the 'readonly' property causing readonly mode`, async () => {
const { editor } = await createFixture({ readonly: true });
assertReadonlyMode(editor);
});
it(`Toggling component's 'readonly' property is mapped to editor 'readonly' mode`, async () => {
const fixture = await createFixture();
const { editor } = fixture;
assertDesignMode(editor);
fixture.componentRef.setInput('readonly', true);
fixture.detectChanges();
assertReadonlyMode(editor);
fixture.componentRef.setInput('readonly', false);
fixture.detectChanges();
assertDesignMode(editor);
});
});
context('With version 7', () => {
@Component({
imports: [ FormsModule, EditorComponent ],
template: `<editor [(ngModel)]="text" [disabled]="true" />`,
standalone: true,
selector: 'test-host-component'
})
class TestHostComponent {
public text = '<h1>Hello World</h1>';
@ViewChild(EditorComponent) public editorRef!: EditorComponent;
}
const waitForEditorInitialized = (editor: Editor) => new Promise<void>((resolve) => {
if (editor.initialized) {
resolve();
}
editor.once('init', () => resolve());
});
let fixture: ComponentFixture<TestHostComponent>;
let testHost: TestHostComponent;
let tinyEditor: Editor;
before(async () => {
await VersionLoader.pLoadVersion('7');
await TestBed.configureTestingModule({
imports: [ TestHostComponent ]
}).compileComponents();
fixture = TestBed.createComponent(TestHostComponent);
testHost = fixture.componentInstance;
fixture.detectChanges();
tinyEditor = testHost.editorRef.editor!;
});
after(() => {
deleteTinymce();
});
it('INT-3328: disabled property should work with [ngModel] when TinyMCE has been loaded before editor component has been created', async () => {
assertDisabledOption(tinyEditor!, true);
/*
I have to wait until the editor is fully initialized before using deleteTinymce() in after block.
There's for example theme.js script that starts to load after editor instance has been created.
If I remove tinymce from window too soon the theme.js will fail alongside with this test case.
*/
await waitForEditorInitialized(tinyEditor!);
});
});
});