Skip to content

Commit abd2806

Browse files
eric-mallacclaude
andcommitted
test(image-editor): run core image editor tests against the core editor in the PRO build
Instead of skipping the suites when image-editor-pro replaces the module registry entry, restore Jodit.modules.ImageEditorCore (kept by the PRO plugin) for the duration of the tests and create editors with disablePlugins: 'imageEditorPro' (unknown plugin names are ignored by the core, so this is a no-op in the core run). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 2dd8260 commit abd2806

2 files changed

Lines changed: 80 additions & 34 deletions

File tree

src/modules/image-editor/image-editor.test.js

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,30 @@
44
* Copyright (c) 2013-2026 Valerii Chupurnov. All rights reserved. https://xdsoft.net
55
*/
66

7-
('imageeditor' in window.skipTest ? describe.skip : describe)(
8-
'Image editor',
9-
() => {
7+
describe('Image editor', () => {
8+
// These tests assert the CORE image editor UI. The PRO build
9+
// (image-editor-pro) replaces `Jodit.modules.ImageEditor` globally and
10+
// keeps the original as `Jodit.modules.ImageEditorCore` — restore it for
11+
// the duration of the suite. Editors are also created with
12+
// `disablePlugins: 'imageEditorPro'` so a new instance does not replace
13+
// the module again (unknown plugin names are ignored by the core).
14+
let proImageEditor = null;
15+
16+
beforeEach(() => {
17+
if (Jodit.modules.ImageEditorCore) {
18+
proImageEditor = Jodit.modules.ImageEditor;
19+
Jodit.modules.ImageEditor = Jodit.modules.ImageEditorCore;
20+
}
21+
});
22+
23+
afterEach(() => {
24+
if (proImageEditor) {
25+
Jodit.modules.ImageEditor = proImageEditor;
26+
proImageEditor = null;
27+
}
28+
});
29+
30+
{
1031
function getForm(dialog) {
1132
return dialog.querySelector('.jodit-ui-image-properties-form')
1233
.component;
@@ -30,7 +51,7 @@
3051
url: 'https://xdsoft.net/jodit/connector/index.php'
3152
}
3253
},
33-
disablePlugins: 'mobile'
54+
disablePlugins: 'mobile,imageEditorPro'
3455
});
3556

3657
editor.value = '<img alt="" src="tests/artio.jpg">';
@@ -132,6 +153,7 @@
132153
const area = appendTestArea();
133154

134155
const editor = Jodit.make(area, {
156+
disablePlugins: 'imageEditorPro',
135157
history: {
136158
timeout: 0
137159
},
@@ -256,6 +278,7 @@
256278
describe('Save as', () => {
257279
it('Should shoe prompt dialog and update image src with new path from server', async () => {
258280
const editor = getJodit({
281+
disablePlugins: 'imageEditorPro',
259282
uploader: {
260283
url: 'https://xdsoft.net/jodit/connector/index.php?action=upload'
261284
},
@@ -317,6 +340,7 @@
317340

318341
it('Should keep original src when server does not return newPath', async () => {
319342
const editor = getJodit({
343+
disablePlugins: 'imageEditorPro',
320344
uploader: {
321345
url: 'https://xdsoft.net/jodit/connector/index.php?action=upload'
322346
},
@@ -375,6 +399,7 @@
375399
describe('Enable ratio', () => {
376400
it('Should deny resize image without ratio', async () => {
377401
const editor = getJodit({
402+
disablePlugins: 'imageEditorPro',
378403
history: {
379404
timeout: 0
380405
},
@@ -487,6 +512,7 @@
487512
it('Should allow resize image without ratio', async () => {
488513
const area = appendTestArea();
489514
const editor = Jodit.make(area, {
515+
disablePlugins: 'imageEditorPro',
490516
history: {
491517
timeout: 0
492518
},
@@ -621,7 +647,7 @@
621647
url: 'https://xdsoft.net/jodit/connector/index.php'
622648
}
623649
},
624-
disablePlugins: 'mobile'
650+
disablePlugins: 'mobile,imageEditorPro'
625651
});
626652

627653
const fb = editor.filebrowser;
@@ -681,4 +707,4 @@
681707
}).timeout(7000);
682708
});
683709
}
684-
);
710+
});

test/tests/acceptance/image-editor-save-event.test.js

Lines changed: 48 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,59 @@
55
*/
66

77
// https://github.com/xdan/jodit/issues/820
8-
('imageeditor' in window.skipTest ? describe.skip : describe)(
9-
'Image editor afterImageEditorSave event (#820)',
10-
() => {
11-
const DATA_URL =
12-
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAC0lEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==';
13-
14-
it('Should fire afterImageEditorSave with the action box when Save is clicked', async () => {
15-
const editor = getJodit({ history: { timeout: 0 } });
8+
describe('Image editor afterImageEditorSave event (#820)', () => {
9+
const DATA_URL =
10+
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAC0lEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==';
11+
12+
// The test asserts the CORE image editor. The PRO build
13+
// (image-editor-pro) replaces `Jodit.modules.ImageEditor` globally and
14+
// keeps the original as `Jodit.modules.ImageEditorCore` — restore it for
15+
// the duration of the test.
16+
let proImageEditor = null;
17+
18+
beforeEach(() => {
19+
if (Jodit.modules.ImageEditorCore) {
20+
proImageEditor = Jodit.modules.ImageEditor;
21+
Jodit.modules.ImageEditor = Jodit.modules.ImageEditorCore;
22+
}
23+
});
24+
25+
afterEach(() => {
26+
if (proImageEditor) {
27+
Jodit.modules.ImageEditor = proImageEditor;
28+
proImageEditor = null;
29+
}
30+
});
31+
32+
it('Should fire afterImageEditorSave with the action box when Save is clicked', async () => {
33+
const editor = getJodit({
34+
disablePlugins: 'imageEditorPro',
35+
history: { timeout: 0 }
36+
});
1637

17-
let fired = null;
18-
editor.e.on('afterImageEditorSave', data => {
19-
fired = data;
20-
});
38+
let fired = null;
39+
editor.e.on('afterImageEditorSave', data => {
40+
fired = data;
41+
});
2142

22-
const ie = editor.getInstance('ImageEditor', editor.o);
23-
ie.open(DATA_URL, () => {});
43+
const ie = editor.getInstance('ImageEditor', editor.o);
44+
ie.open(DATA_URL, () => {});
2445

25-
await delay(400);
46+
await delay(400);
2647

27-
const dialog = editor.ownerDocument.querySelector('.jodit-dialog');
28-
expect(dialog).is.not.null;
48+
const dialog = editor.ownerDocument.querySelector('.jodit-dialog');
49+
expect(dialog).is.not.null;
2950

30-
const saveBtn = dialog.querySelector('[data-ref="save"]');
31-
expect(saveBtn).is.not.null;
51+
const saveBtn = dialog.querySelector('[data-ref="save"]');
52+
expect(saveBtn).is.not.null;
3253

33-
simulateEvent('click', saveBtn);
34-
await delay(50);
54+
simulateEvent('click', saveBtn);
55+
await delay(50);
3556

36-
expect(fired).is.not.null;
37-
expect(fired.action).equals('resize');
38-
expect(fired.box).is.not.undefined;
57+
expect(fired).is.not.null;
58+
expect(fired.action).equals('resize');
59+
expect(fired.box).is.not.undefined;
3960

40-
editor.destruct();
41-
});
42-
}
43-
);
61+
editor.destruct();
62+
});
63+
});

0 commit comments

Comments
 (0)