Skip to content

Commit 2336d87

Browse files
INT-3328: fix tests
1 parent 8a7e6db commit 2336d87

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

tinymce-angular-component/src/test/ts/browser/DisabledPropertyTest.ts

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ import { Assertions } from '@ephox/agar';
22
import '../alien/InitTestEnvironment';
33

44
import { EditorComponent } from '../../../main/ts/public_api';
5-
import { beforeEach, describe, it } from '@ephox/bedrock-client';
5+
import { after, before, context, describe, it } from '@ephox/bedrock-client';
66
import { eachVersionContext, editorHook } from '../alien/TestHooks';
77
import { Editor } from 'tinymce';
88
import { ComponentFixture, TestBed } from '@angular/core/testing';
9-
import { FormsModule } from '@angular/forms';
109
import { Component, ViewChild } from '@angular/core';
10+
import { FormsModule } from '@angular/forms';
11+
import { VersionLoader } from '@tinymce/miniature';
12+
import { deleteTinymce } from '../alien/TestHelpers';
1113

1214
describe('DisabledPropertyTest', () => {
1315
const getMode = (editor: Editor) => {
@@ -108,7 +110,7 @@ describe('DisabledPropertyTest', () => {
108110
});
109111
});
110112

111-
eachVersionContext([ '7' ], () => {
113+
context('With version 7', () => {
112114
@Component({
113115
imports: [ FormsModule, EditorComponent ],
114116
template: `<editor [(ngModel)]="text" [disabled]="true" />`,
@@ -120,22 +122,42 @@ describe('DisabledPropertyTest', () => {
120122
@ViewChild(EditorComponent) public editorRef!: EditorComponent;
121123
}
122124

125+
const waitForEditorInitialized = (editor: Editor) => new Promise<void>((resolve) => {
126+
if (editor.initialized) {
127+
resolve();
128+
}
129+
editor.once('init', () => resolve());
130+
});
131+
123132
let fixture: ComponentFixture<TestHostComponent>;
124133
let testHost: TestHostComponent;
134+
let tinyEditor: Editor;
135+
136+
before(async () => {
137+
await VersionLoader.pLoadVersion('7');
125138

126-
beforeEach(async () => {
127139
await TestBed.configureTestingModule({
128140
imports: [ TestHostComponent ]
129141
}).compileComponents();
130142

131143
fixture = TestBed.createComponent(TestHostComponent);
132144
testHost = fixture.componentInstance;
133145
fixture.detectChanges();
146+
tinyEditor = testHost.editorRef.editor!;
147+
});
148+
149+
after(() => {
150+
deleteTinymce();
134151
});
135152

136-
it('INT-3328: disabled property should work with [ngModel] when TinyMCE has been loaded before editor component has been created', () => {
137-
const tinyEditor = testHost.editorRef.editor;
153+
it('INT-3328: disabled property should work with [ngModel] when TinyMCE has been loaded before editor component has been created', async () => {
138154
assertDisabledOption(tinyEditor!, true);
155+
/*
156+
I have to wait until the editor is fully initialized before using deleteTinymce() in after block.
157+
There's for example theme.js script that starts to load after editor instance has been created.
158+
If I remove tinymce from window too soon the theme.js will fail alongside with this test case.
159+
*/
160+
await waitForEditorInitialized(tinyEditor!);
139161
});
140162
});
141163
});

0 commit comments

Comments
 (0)