ckeditor5-symfony 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ckeditor5-symfony-error.d.ts +7 -0
- package/dist/ckeditor5-symfony-error.d.ts.map +1 -0
- package/dist/elements/context/context.d.ts +18 -0
- package/dist/elements/context/context.d.ts.map +1 -0
- package/dist/elements/context/contexts-registry.d.ts +9 -0
- package/dist/elements/context/contexts-registry.d.ts.map +1 -0
- package/dist/elements/context/index.d.ts +4 -0
- package/dist/elements/context/index.d.ts.map +1 -0
- package/dist/elements/context/typings.d.ts +34 -0
- package/dist/elements/context/typings.d.ts.map +1 -0
- package/dist/elements/editable.d.ts +18 -0
- package/dist/elements/editable.d.ts.map +1 -0
- package/dist/elements/editor/custom-editor-plugins.d.ts +54 -0
- package/dist/elements/editor/custom-editor-plugins.d.ts.map +1 -0
- package/dist/elements/editor/editor.d.ts +23 -0
- package/dist/elements/editor/editor.d.ts.map +1 -0
- package/dist/elements/editor/editors-registry.d.ts +9 -0
- package/dist/elements/editor/editors-registry.d.ts.map +1 -0
- package/dist/elements/editor/index.d.ts +3 -0
- package/dist/elements/editor/index.d.ts.map +1 -0
- package/dist/elements/editor/plugins/index.d.ts +2 -0
- package/dist/elements/editor/plugins/index.d.ts.map +1 -0
- package/dist/elements/editor/plugins/sync-editor-with-input.d.ts +6 -0
- package/dist/elements/editor/plugins/sync-editor-with-input.d.ts.map +1 -0
- package/dist/elements/editor/typings.d.ts +99 -0
- package/dist/elements/editor/typings.d.ts.map +1 -0
- package/dist/elements/editor/utils/create-editor-in-context.d.ts +44 -0
- package/dist/elements/editor/utils/create-editor-in-context.d.ts.map +1 -0
- package/dist/elements/editor/utils/index.d.ts +12 -0
- package/dist/elements/editor/utils/index.d.ts.map +1 -0
- package/dist/elements/editor/utils/is-single-root-editor.d.ts +9 -0
- package/dist/elements/editor/utils/is-single-root-editor.d.ts.map +1 -0
- package/dist/elements/editor/utils/load-editor-constructor.d.ts +9 -0
- package/dist/elements/editor/utils/load-editor-constructor.d.ts.map +1 -0
- package/dist/elements/editor/utils/load-editor-plugins.d.ts +20 -0
- package/dist/elements/editor/utils/load-editor-plugins.d.ts.map +1 -0
- package/dist/elements/editor/utils/load-editor-translations.d.ts +14 -0
- package/dist/elements/editor/utils/load-editor-translations.d.ts.map +1 -0
- package/dist/elements/editor/utils/normalize-custom-translations.d.ts +11 -0
- package/dist/elements/editor/utils/normalize-custom-translations.d.ts.map +1 -0
- package/dist/elements/editor/utils/query-all-editor-ids.d.ts +5 -0
- package/dist/elements/editor/utils/query-all-editor-ids.d.ts.map +1 -0
- package/dist/elements/editor/utils/query-editor-editables.d.ts +25 -0
- package/dist/elements/editor/utils/query-editor-editables.d.ts.map +1 -0
- package/dist/elements/editor/utils/resolve-editor-config-elements-references.d.ts +9 -0
- package/dist/elements/editor/utils/resolve-editor-config-elements-references.d.ts.map +1 -0
- package/dist/elements/editor/utils/set-editor-editable-height.d.ts +9 -0
- package/dist/elements/editor/utils/set-editor-editable-height.d.ts.map +1 -0
- package/dist/elements/editor/utils/wrap-with-watchdog.d.ts +24 -0
- package/dist/elements/editor/utils/wrap-with-watchdog.d.ts.map +1 -0
- package/dist/elements/index.d.ts +6 -0
- package/dist/elements/index.d.ts.map +1 -0
- package/dist/elements/register-custom-elements.d.ts +5 -0
- package/dist/elements/register-custom-elements.d.ts.map +1 -0
- package/dist/elements/ui-part.d.ts +18 -0
- package/dist/elements/ui-part.d.ts.map +1 -0
- package/dist/index.cjs +5 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.mjs +1089 -0
- package/dist/index.mjs.map +1 -0
- package/dist/shared/async-registry.d.ts +136 -0
- package/dist/shared/async-registry.d.ts.map +1 -0
- package/dist/shared/camel-case.d.ts +8 -0
- package/dist/shared/camel-case.d.ts.map +1 -0
- package/dist/shared/debounce.d.ts +2 -0
- package/dist/shared/debounce.d.ts.map +1 -0
- package/dist/shared/deep-camel-case-keys.d.ts +8 -0
- package/dist/shared/deep-camel-case-keys.d.ts.map +1 -0
- package/dist/shared/filter-object-values.d.ts +9 -0
- package/dist/shared/filter-object-values.d.ts.map +1 -0
- package/dist/shared/index.d.ts +15 -0
- package/dist/shared/index.d.ts.map +1 -0
- package/dist/shared/is-empty-object.d.ts +2 -0
- package/dist/shared/is-empty-object.d.ts.map +1 -0
- package/dist/shared/is-plain-object.d.ts +8 -0
- package/dist/shared/is-plain-object.d.ts.map +1 -0
- package/dist/shared/map-object-values.d.ts +11 -0
- package/dist/shared/map-object-values.d.ts.map +1 -0
- package/dist/shared/once.d.ts +2 -0
- package/dist/shared/once.d.ts.map +1 -0
- package/dist/shared/shallow-equal.d.ts +9 -0
- package/dist/shared/shallow-equal.d.ts.map +1 -0
- package/dist/shared/timeout.d.ts +8 -0
- package/dist/shared/timeout.d.ts.map +1 -0
- package/dist/shared/uid.d.ts +7 -0
- package/dist/shared/uid.d.ts.map +1 -0
- package/dist/shared/wait-for-dom-ready.d.ts +5 -0
- package/dist/shared/wait-for-dom-ready.d.ts.map +1 -0
- package/dist/shared/wait-for.d.ts +20 -0
- package/dist/shared/wait-for.d.ts.map +1 -0
- package/dist/types/can-be-promise.type.d.ts +2 -0
- package/dist/types/can-be-promise.type.d.ts.map +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/required-by.type.d.ts +2 -0
- package/dist/types/required-by.type.d.ts.map +1 -0
- package/package.json +40 -0
- package/src/ckeditor5-symfony-error.ts +9 -0
- package/src/elements/context/context.test.ts +291 -0
- package/src/elements/context/context.ts +99 -0
- package/src/elements/context/contexts-registry.test.ts +10 -0
- package/src/elements/context/contexts-registry.ts +10 -0
- package/src/elements/context/index.ts +3 -0
- package/src/elements/context/typings.ts +39 -0
- package/src/elements/editable.test.ts +334 -0
- package/src/elements/editable.ts +114 -0
- package/src/elements/editor/custom-editor-plugins.test.ts +103 -0
- package/src/elements/editor/custom-editor-plugins.ts +86 -0
- package/src/elements/editor/editor.test.ts +438 -0
- package/src/elements/editor/editor.ts +279 -0
- package/src/elements/editor/editors-registry.test.ts +10 -0
- package/src/elements/editor/editors-registry.ts +10 -0
- package/src/elements/editor/index.ts +2 -0
- package/src/elements/editor/plugins/index.ts +1 -0
- package/src/elements/editor/plugins/sync-editor-with-input.ts +78 -0
- package/src/elements/editor/typings.ts +114 -0
- package/src/elements/editor/utils/create-editor-in-context.ts +90 -0
- package/src/elements/editor/utils/index.ts +11 -0
- package/src/elements/editor/utils/is-single-root-editor.test.ts +40 -0
- package/src/elements/editor/utils/is-single-root-editor.ts +11 -0
- package/src/elements/editor/utils/load-editor-constructor.test.ts +62 -0
- package/src/elements/editor/utils/load-editor-constructor.ts +29 -0
- package/src/elements/editor/utils/load-editor-plugins.test.ts +100 -0
- package/src/elements/editor/utils/load-editor-plugins.ts +73 -0
- package/src/elements/editor/utils/load-editor-translations.ts +233 -0
- package/src/elements/editor/utils/normalize-custom-translations.test.ts +152 -0
- package/src/elements/editor/utils/normalize-custom-translations.ts +18 -0
- package/src/elements/editor/utils/query-all-editor-ids.ts +9 -0
- package/src/elements/editor/utils/query-editor-editables.ts +101 -0
- package/src/elements/editor/utils/resolve-editor-config-elements-references.test.ts +93 -0
- package/src/elements/editor/utils/resolve-editor-config-elements-references.ts +36 -0
- package/src/elements/editor/utils/set-editor-editable-height.test.ts +131 -0
- package/src/elements/editor/utils/set-editor-editable-height.ts +15 -0
- package/src/elements/editor/utils/wrap-with-watchdog.test.ts +45 -0
- package/src/elements/editor/utils/wrap-with-watchdog.ts +51 -0
- package/src/elements/index.ts +14 -0
- package/src/elements/register-custom-elements.ts +24 -0
- package/src/elements/ui-part.test.ts +142 -0
- package/src/elements/ui-part.ts +80 -0
- package/src/index.ts +6 -0
- package/src/shared/async-registry.test.ts +737 -0
- package/src/shared/async-registry.ts +353 -0
- package/src/shared/camel-case.test.ts +35 -0
- package/src/shared/camel-case.ts +11 -0
- package/src/shared/debounce.test.ts +72 -0
- package/src/shared/debounce.ts +16 -0
- package/src/shared/deep-camel-case-keys.test.ts +34 -0
- package/src/shared/deep-camel-case-keys.ts +26 -0
- package/src/shared/filter-object-values.test.ts +25 -0
- package/src/shared/filter-object-values.ts +17 -0
- package/src/shared/index.ts +14 -0
- package/src/shared/is-empty-object.test.ts +78 -0
- package/src/shared/is-empty-object.ts +3 -0
- package/src/shared/is-plain-object.test.ts +38 -0
- package/src/shared/is-plain-object.ts +15 -0
- package/src/shared/map-object-values.test.ts +29 -0
- package/src/shared/map-object-values.ts +19 -0
- package/src/shared/once.test.ts +116 -0
- package/src/shared/once.ts +12 -0
- package/src/shared/shallow-equal.test.ts +51 -0
- package/src/shared/shallow-equal.ts +30 -0
- package/src/shared/timeout.test.ts +65 -0
- package/src/shared/timeout.ts +13 -0
- package/src/shared/uid.test.ts +25 -0
- package/src/shared/uid.ts +8 -0
- package/src/shared/wait-for-dom-ready.test.ts +87 -0
- package/src/shared/wait-for-dom-ready.ts +21 -0
- package/src/shared/wait-for.test.ts +24 -0
- package/src/shared/wait-for.ts +56 -0
- package/src/types/can-be-promise.type.ts +1 -0
- package/src/types/index.ts +2 -0
- package/src/types/required-by.type.ts +1 -0
|
@@ -0,0 +1,438 @@
|
|
|
1
|
+
import type { LanguageConfig } from 'ckeditor5';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
BalloonEditor,
|
|
5
|
+
ClassicEditor,
|
|
6
|
+
DecoupledEditor,
|
|
7
|
+
Editor,
|
|
8
|
+
InlineEditor,
|
|
9
|
+
MultiRootEditor,
|
|
10
|
+
Plugin,
|
|
11
|
+
} from 'ckeditor5';
|
|
12
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
13
|
+
|
|
14
|
+
import {
|
|
15
|
+
createEditableSnapshot,
|
|
16
|
+
createEditorPreset,
|
|
17
|
+
getTestEditorInput,
|
|
18
|
+
html,
|
|
19
|
+
isEditorShown,
|
|
20
|
+
renderTestEditable,
|
|
21
|
+
renderTestEditor,
|
|
22
|
+
waitForTestEditor,
|
|
23
|
+
} from '~/test-utils';
|
|
24
|
+
|
|
25
|
+
import { timeout } from '../../shared/timeout';
|
|
26
|
+
import { registerCustomElements } from '../register-custom-elements';
|
|
27
|
+
import { CustomEditorPluginsRegistry } from './custom-editor-plugins';
|
|
28
|
+
import { EditorsRegistry } from './editors-registry';
|
|
29
|
+
import { unwrapEditorWatchdog } from './utils';
|
|
30
|
+
|
|
31
|
+
describe('editor component', () => {
|
|
32
|
+
beforeEach(() => {
|
|
33
|
+
document.body.innerHTML = '';
|
|
34
|
+
registerCustomElements();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
afterEach(async () => {
|
|
38
|
+
vi.useRealTimers();
|
|
39
|
+
document.body.innerHTML = '';
|
|
40
|
+
|
|
41
|
+
CustomEditorPluginsRegistry.the.unregisterAll();
|
|
42
|
+
EditorsRegistry.the.reset();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('should save the editor instance in the registry with provided editorId', async () => {
|
|
46
|
+
renderTestEditor();
|
|
47
|
+
|
|
48
|
+
const editor = await waitForTestEditor();
|
|
49
|
+
|
|
50
|
+
expect(editor).toBeInstanceOf(Editor);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('should be possible to pass custom plugins to the editor', async () => {
|
|
54
|
+
class MyCustomPlugin extends Plugin {
|
|
55
|
+
static pluginName = 'MyCustomPlugin';
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const preset = createEditorPreset('classic', {
|
|
59
|
+
toolbar: [],
|
|
60
|
+
plugins: ['MyCustomPlugin'],
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
CustomEditorPluginsRegistry.the.register('MyCustomPlugin', () => MyCustomPlugin);
|
|
64
|
+
renderTestEditor({ preset });
|
|
65
|
+
|
|
66
|
+
const editor = await waitForTestEditor();
|
|
67
|
+
|
|
68
|
+
expect(editor.plugins.get('MyCustomPlugin')).toBeInstanceOf(MyCustomPlugin);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
describe('editor types', () => {
|
|
72
|
+
describe('classic', () => {
|
|
73
|
+
it('should create an classic editor with default preset', async () => {
|
|
74
|
+
renderTestEditor();
|
|
75
|
+
|
|
76
|
+
const editor = await waitForTestEditor();
|
|
77
|
+
|
|
78
|
+
expect(editor).to.toBeInstanceOf(ClassicEditor);
|
|
79
|
+
expect(isEditorShown()).toBe(true);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('should assign default value from `content` snapshot property', async () => {
|
|
83
|
+
const initialValue = `<p>Hello World! Today is ${new Date().toLocaleDateString()}</p>`;
|
|
84
|
+
|
|
85
|
+
renderTestEditor({
|
|
86
|
+
content: {
|
|
87
|
+
main: initialValue,
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
const editor = await waitForTestEditor();
|
|
92
|
+
|
|
93
|
+
expect(editor.getData()).toBe(initialValue);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('should assign empty main value if initialized editor with empty `content` snapshot property', async () => {
|
|
97
|
+
renderTestEditor({
|
|
98
|
+
content: {},
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
const editor = await waitForTestEditor();
|
|
102
|
+
|
|
103
|
+
expect(editor.getData()).toBe('');
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
describe('inline', () => {
|
|
108
|
+
it('should create an inline editor with default preset', async () => {
|
|
109
|
+
renderTestEditor({ preset: createEditorPreset('inline') });
|
|
110
|
+
|
|
111
|
+
const editor = await waitForTestEditor();
|
|
112
|
+
|
|
113
|
+
expect(editor).to.toBeInstanceOf(InlineEditor);
|
|
114
|
+
expect(isEditorShown()).toBe(true);
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
describe('decoupled', () => {
|
|
119
|
+
it('should create a decoupled editor with `main` editable and default preset', async () => {
|
|
120
|
+
renderTestEditor({ preset: createEditorPreset('decoupled') });
|
|
121
|
+
renderTestEditable(createEditableSnapshot('main', null));
|
|
122
|
+
|
|
123
|
+
const editor = await waitForTestEditor();
|
|
124
|
+
|
|
125
|
+
expect(editor).to.toBeInstanceOf(DecoupledEditor);
|
|
126
|
+
expect(isEditorShown()).toBe(true);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it('should pick initial content from the editable snapshot if provided', async () => {
|
|
130
|
+
const initialEditableContent = '<p>Initial editable content</p>';
|
|
131
|
+
|
|
132
|
+
renderTestEditor({ preset: createEditorPreset('decoupled') });
|
|
133
|
+
renderTestEditable(createEditableSnapshot('main', initialEditableContent));
|
|
134
|
+
|
|
135
|
+
const editor = await waitForTestEditor();
|
|
136
|
+
|
|
137
|
+
expect(editor).to.toBeInstanceOf(DecoupledEditor);
|
|
138
|
+
expect(editor.getData()).toBe(initialEditableContent);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it('should wait for root element to be present in DOM if it is not', async () => {
|
|
142
|
+
renderTestEditor({ preset: createEditorPreset('decoupled') });
|
|
143
|
+
|
|
144
|
+
await timeout(200);
|
|
145
|
+
|
|
146
|
+
renderTestEditable(createEditableSnapshot('main', null));
|
|
147
|
+
|
|
148
|
+
const editor = await waitForTestEditor();
|
|
149
|
+
|
|
150
|
+
expect(editor).to.toBeInstanceOf(DecoupledEditor);
|
|
151
|
+
expect(isEditorShown()).toBe(true);
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
describe('balloon', () => {
|
|
156
|
+
it('should create a balloon editor with default preset', async () => {
|
|
157
|
+
renderTestEditor({ preset: createEditorPreset('balloon') });
|
|
158
|
+
|
|
159
|
+
const editor = await waitForTestEditor();
|
|
160
|
+
|
|
161
|
+
expect(editor).to.toBeInstanceOf(BalloonEditor);
|
|
162
|
+
expect(isEditorShown()).toBe(true);
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
describe('multiroot', () => {
|
|
167
|
+
it('should create a multiroot editor without editables in the DOM and initial content', async () => {
|
|
168
|
+
renderTestEditor({
|
|
169
|
+
preset: createEditorPreset('multiroot'),
|
|
170
|
+
content: {},
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
const editor = await waitForTestEditor();
|
|
174
|
+
|
|
175
|
+
expect(editor).toBeInstanceOf(MultiRootEditor);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it('should wait and for root elements to be present in DOM if they are not (with content=null value)', async () => {
|
|
179
|
+
renderTestEditor({
|
|
180
|
+
preset: createEditorPreset('multiroot'),
|
|
181
|
+
content: {
|
|
182
|
+
header: '<p>Header root initial content</p>',
|
|
183
|
+
},
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
await timeout(500); // Simulate some delay before adding the root.
|
|
187
|
+
|
|
188
|
+
renderTestEditable(createEditableSnapshot('header'));
|
|
189
|
+
|
|
190
|
+
const editor = await waitForTestEditor();
|
|
191
|
+
|
|
192
|
+
expect(editor).toBeInstanceOf(MultiRootEditor);
|
|
193
|
+
expect(editor.getData({ rootName: 'header' })).toBe('<p>Header root initial content</p>');
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it('should wait and for root elements to be present in DOM if they are not (with content=\'\' value)', async () => {
|
|
197
|
+
renderTestEditor({
|
|
198
|
+
preset: createEditorPreset('multiroot'),
|
|
199
|
+
content: {
|
|
200
|
+
header: '<p>Header root initial content</p>',
|
|
201
|
+
},
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
await timeout(500); // Simulate some delay before adding the root.
|
|
205
|
+
|
|
206
|
+
renderTestEditable(createEditableSnapshot('header', ''));
|
|
207
|
+
|
|
208
|
+
const editor = await waitForTestEditor();
|
|
209
|
+
|
|
210
|
+
expect(editor).toBeInstanceOf(MultiRootEditor);
|
|
211
|
+
expect(editor.getData({ rootName: 'header' })).toBe('');
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it('should wait and for root elements to be present in DOM if they are not (with set content value)', async () => {
|
|
215
|
+
renderTestEditor({
|
|
216
|
+
preset: createEditorPreset('multiroot'),
|
|
217
|
+
content: {
|
|
218
|
+
header: '<p>Header root initial content</p>',
|
|
219
|
+
},
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
await timeout(500); // Simulate some delay before adding the root.
|
|
223
|
+
|
|
224
|
+
renderTestEditable(createEditableSnapshot('header', '<p>Editable content overrides snapshot content</p>'));
|
|
225
|
+
|
|
226
|
+
const editor = await waitForTestEditor();
|
|
227
|
+
|
|
228
|
+
expect(editor).toBeInstanceOf(MultiRootEditor);
|
|
229
|
+
expect(editor.getData({ rootName: 'header' })).toBe('<p>Editable content overrides snapshot content</p>');
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
it('should not crash after setting content using `setData`', async () => {
|
|
233
|
+
renderTestEditor({
|
|
234
|
+
content: {
|
|
235
|
+
main: '<p>Initial content</p>',
|
|
236
|
+
},
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
const editor = await waitForTestEditor();
|
|
240
|
+
|
|
241
|
+
expect(() => {
|
|
242
|
+
editor.setData('<p>New content</p>');
|
|
243
|
+
}).not.toThrow();
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
describe('`editableHeight` snapshot parameter`', () => {
|
|
249
|
+
it('should not set any height if `editableHeight` parameter is `null`', async () => {
|
|
250
|
+
renderTestEditor({ editableHeight: null });
|
|
251
|
+
|
|
252
|
+
const editor = await waitForTestEditor();
|
|
253
|
+
|
|
254
|
+
const editableElement = editor.ui.getEditableElement()!;
|
|
255
|
+
|
|
256
|
+
expect(getComputedStyle(editableElement).height).toBe('');
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
it('should set the editable height if `editableHeight` snapshot parameter is provided', async () => {
|
|
260
|
+
renderTestEditor({ editableHeight: 400 });
|
|
261
|
+
|
|
262
|
+
const editor = await waitForTestEditor();
|
|
263
|
+
|
|
264
|
+
const editableElement = editor.ui.getEditableElement()!;
|
|
265
|
+
|
|
266
|
+
expect(getComputedStyle(editableElement).height).toBe('400px');
|
|
267
|
+
});
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
describe('`saveDebounceMs` snapshot parameter`', () => {
|
|
271
|
+
beforeEach(() => {
|
|
272
|
+
vi.useFakeTimers();
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
it('should use parameter to debounce input sync', async () => {
|
|
276
|
+
renderTestEditor({ saveDebounceMs: 400 }, { withInput: true });
|
|
277
|
+
|
|
278
|
+
const editor = await waitForTestEditor();
|
|
279
|
+
const input = getTestEditorInput();
|
|
280
|
+
|
|
281
|
+
editor.setData('<p>Debounce test</p>');
|
|
282
|
+
expect(input.value).to.be.equal('<p>Initial content</p>');
|
|
283
|
+
|
|
284
|
+
await vi.advanceTimersByTimeAsync(399);
|
|
285
|
+
expect(input.value).to.be.equal('<p>Initial content</p>');
|
|
286
|
+
|
|
287
|
+
await vi.advanceTimersByTimeAsync(1);
|
|
288
|
+
expect(input.value).to.be.equal('<p>Debounce test</p>');
|
|
289
|
+
});
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
describe('`language` snapshot parameter`', () => {
|
|
293
|
+
it('should be possible to pass language configuration to the editor configuration', async () => {
|
|
294
|
+
renderTestEditor({
|
|
295
|
+
language: {
|
|
296
|
+
ui: 'pl',
|
|
297
|
+
content: 'de',
|
|
298
|
+
},
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
const editor = await waitForTestEditor();
|
|
302
|
+
const configLanguage = editor.config.get('language') as LanguageConfig;
|
|
303
|
+
|
|
304
|
+
expect(configLanguage.ui).toBe('pl');
|
|
305
|
+
expect(configLanguage.content).toBe('de');
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
it('should have buttons translated to the selected UI language', async () => {
|
|
309
|
+
renderTestEditor({
|
|
310
|
+
language: {
|
|
311
|
+
ui: 'pl',
|
|
312
|
+
content: 'pl',
|
|
313
|
+
},
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
const editor = await waitForTestEditor();
|
|
317
|
+
|
|
318
|
+
expect(editor.t('Bold')).toBe('Pogrubienie');
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
it('should be possible to pass custom translations to the editor', async () => {
|
|
322
|
+
const preset = createEditorPreset('classic', {}, {
|
|
323
|
+
pl: {
|
|
324
|
+
Bold: 'Czcionka grubaśna',
|
|
325
|
+
},
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
renderTestEditor({
|
|
329
|
+
preset,
|
|
330
|
+
language: {
|
|
331
|
+
ui: 'pl',
|
|
332
|
+
content: 'pl',
|
|
333
|
+
},
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
const editor = await waitForTestEditor();
|
|
337
|
+
|
|
338
|
+
expect(editor.t('Bold')).toBe('Czcionka grubaśna');
|
|
339
|
+
});
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
describe('`watchdog` snapshot parameter`', () => {
|
|
343
|
+
it('should not wrap editor with watchdog if `watchdog` is false', async () => {
|
|
344
|
+
renderTestEditor({
|
|
345
|
+
watchdog: false,
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
const editor = await waitForTestEditor();
|
|
349
|
+
const watchdog = unwrapEditorWatchdog(editor);
|
|
350
|
+
|
|
351
|
+
expect(watchdog).toBeNull();
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
it('should resurrect editor after crashing and broadcast the new instance when `watchdog` is enabled', async () => {
|
|
355
|
+
renderTestEditor({
|
|
356
|
+
editorId: 'editor-with-watchdog',
|
|
357
|
+
watchdog: true,
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
const originalEditor = await waitForTestEditor('editor-with-watchdog');
|
|
361
|
+
const watchdog = unwrapEditorWatchdog(originalEditor)!;
|
|
362
|
+
|
|
363
|
+
(watchdog as any)._restart();
|
|
364
|
+
|
|
365
|
+
await vi.waitFor(async () => {
|
|
366
|
+
const newEditor = await waitForTestEditor('editor-with-watchdog');
|
|
367
|
+
|
|
368
|
+
expect(newEditor).not.equals(originalEditor);
|
|
369
|
+
});
|
|
370
|
+
});
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
describe('form integration', () => {
|
|
374
|
+
beforeEach(() => {
|
|
375
|
+
vi.useFakeTimers();
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
it('should sync editor data to the associated input field', async () => {
|
|
379
|
+
renderTestEditor({ saveDebounceMs: 0 }, { withInput: true });
|
|
380
|
+
|
|
381
|
+
const editor = await waitForTestEditor();
|
|
382
|
+
const input = getTestEditorInput();
|
|
383
|
+
|
|
384
|
+
editor.setData('<p>Form integration test</p>');
|
|
385
|
+
await vi.advanceTimersByTimeAsync(1);
|
|
386
|
+
|
|
387
|
+
expect(input.value).to.be.equal('<p>Form integration test</p>');
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
it('should not crash if hidden input is not present', async () => {
|
|
391
|
+
renderTestEditor({ saveDebounceMs: 0 }, { withInput: false });
|
|
392
|
+
|
|
393
|
+
const editor = await waitForTestEditor();
|
|
394
|
+
|
|
395
|
+
expect(() => {
|
|
396
|
+
editor.setData('<p>Form integration test</p>');
|
|
397
|
+
vi.advanceTimersByTime(1);
|
|
398
|
+
}).not.to.throw();
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
it('should immediately sync editor data to the associated input field on form submit', async () => {
|
|
402
|
+
const form = html.form({ id: 'form' });
|
|
403
|
+
document.body.appendChild(form);
|
|
404
|
+
|
|
405
|
+
renderTestEditor({ saveDebounceMs: 5000 }, { withInput: true, container: form });
|
|
406
|
+
|
|
407
|
+
const editor = await waitForTestEditor();
|
|
408
|
+
const input = getTestEditorInput();
|
|
409
|
+
|
|
410
|
+
editor.setData('<p>Form integration test</p>');
|
|
411
|
+
await vi.advanceTimersByTimeAsync(1000);
|
|
412
|
+
|
|
413
|
+
// Value should not be synced yet due to debounce.
|
|
414
|
+
expect(input.value).to.be.equal('<p>Initial content</p>');
|
|
415
|
+
|
|
416
|
+
// Submit the form.
|
|
417
|
+
form.dispatchEvent(new Event('submit', { bubbles: true }));
|
|
418
|
+
await vi.advanceTimersByTimeAsync(1);
|
|
419
|
+
|
|
420
|
+
// Value should be synced immediately on form submit.
|
|
421
|
+
expect(input.value).to.be.equal('<p>Form integration test</p>');
|
|
422
|
+
});
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
describe('destroy', () => {
|
|
426
|
+
it('should destroy editor on component unmount', async () => {
|
|
427
|
+
const component = renderTestEditor();
|
|
428
|
+
|
|
429
|
+
const editor = await waitForTestEditor();
|
|
430
|
+
|
|
431
|
+
component.remove();
|
|
432
|
+
|
|
433
|
+
await vi.waitFor(() => {
|
|
434
|
+
expect(editor.state).toBe('destroyed');
|
|
435
|
+
});
|
|
436
|
+
});
|
|
437
|
+
});
|
|
438
|
+
});
|