Skip to content
This repository was archived by the owner on May 5, 2021. It is now read-only.

Commit 032af5e

Browse files
committed
tests
1 parent f6e3ab8 commit 032af5e

File tree

10 files changed

+779
-717
lines changed

10 files changed

+779
-717
lines changed

packages/core/test/ContextManager.test.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,16 +288,18 @@ describe('core', () => {
288288
contentBefore:
289289
'<div><div><p>cd</p></div></div>' +
290290
'<ul><li></li><li style="list-style: none;"><ul><li><p>c</p></li></ul></li><li><div>[]</div></li></ul>',
291-
stepFunction: (editor: BasicEditor) => {
291+
stepFunction: async (editor: BasicEditor) => {
292292
const callback = (): void => {};
293293
const check = (context: CheckingContext): boolean => !!context;
294294
const checkSpy1 = sinon.spy(check);
295295
const checkSpy2 = sinon.spy(check);
296296
const newSelection = new VSelection(editor);
297297

298-
const domEngine = editor.plugins.get(Layout).engines.dom;
299-
const editable = domEngine.components.get('editable')[0];
300-
newSelection.setAt(editable);
298+
await editor.execBatch(async () => {
299+
const domEngine = editor.plugins.get(Layout).engines.dom;
300+
const editable = domEngine.components.get('editable')[0];
301+
newSelection.setAt(editable);
302+
});
301303
const commands: CommandImplementation[] = [
302304
{
303305
title: 'paragraph',

packages/core/test/JWeditor.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ describe('core', () => {
234234
await testEditor(BasicEditor, {
235235
contentBefore: '<div>ab[]</div>',
236236
stepFunction: async editor => {
237-
await editor.execCustomCommand(async () => {
237+
await editor.execBatch(async () => {
238238
const layout = editor.plugins.get(Layout);
239239
const domEngine = layout.engines.dom;
240240
domEngine.components

packages/core/test/VDocument.test.ts

Lines changed: 69 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ import { BasicEditor } from '../../bundle-basic-editor/BasicEditor';
77
import { Core } from '../../core/src/Core';
88
import { Layout } from '../../plugin-layout/src/Layout';
99

10-
const deleteForward = async (editor: JWEditor): Promise<void> =>
10+
const deleteForward = async (editor: JWEditor): Promise<void> => {
1111
await editor.execCommand<Core>('deleteForward');
12+
};
1213
const deleteBackward = async (editor: JWEditor): Promise<void> =>
1314
await editor.execCommand<Core>('deleteBackward');
1415
const insertParagraphBreak = async (editor: JWEditor): Promise<void> =>
@@ -548,9 +549,11 @@ describe('VDocument', () => {
548549
stepFunction: (editor: JWEditor) => {
549550
const domEngine = editor.plugins.get(Layout).engines.dom;
550551
const editable = domEngine.components.get('editable')[0];
551-
editable.firstChild().breakable = false;
552-
editable.lastChild().breakable = false;
553-
return deleteForward(editor);
552+
return editor.execBatch(() => {
553+
editable.firstChild().breakable = false;
554+
editable.lastChild().breakable = false;
555+
return deleteForward(editor);
556+
});
554557
},
555558
contentAfter: '<p>a[</p><p>]f</p>',
556559
});
@@ -1506,15 +1509,17 @@ describe('VDocument', () => {
15061509
await testEditor(BasicEditor, {
15071510
contentBefore: 'ab[]',
15081511
stepFunction: async (editor: JWEditor) => {
1509-
const domEngine = editor.plugins.get(Layout).engines.dom;
1510-
const editable = domEngine.components.get('editable')[0];
1511-
const aNode = editable.next(node => node.name === 'a');
1512-
await withRange(editor, VRange.at(aNode), async range => {
1513-
await editor.execCommand<Char>('insertText', {
1514-
text: 'c',
1515-
context: {
1516-
range: range,
1517-
},
1512+
await editor.execBatch(async () => {
1513+
const domEngine = editor.plugins.get(Layout).engines.dom;
1514+
const editable = domEngine.components.get('editable')[0];
1515+
const aNode = editable.next(node => node.name === 'a');
1516+
await withRange(editor, VRange.at(aNode), async range => {
1517+
await editor.execCommand<Char>('insertText', {
1518+
text: 'c',
1519+
context: {
1520+
range: range,
1521+
},
1522+
});
15181523
});
15191524
});
15201525
},
@@ -1525,15 +1530,17 @@ describe('VDocument', () => {
15251530
await testEditor(BasicEditor, {
15261531
contentBefore: 'ab[]',
15271532
stepFunction: async (editor: JWEditor) => {
1528-
const domEngine = editor.plugins.get(Layout).engines.dom;
1529-
const editable = domEngine.components.get('editable')[0];
1530-
const aNode = editable.next(node => node.name === 'a');
1531-
await withRange(editor, VRange.selecting(aNode, aNode), async range => {
1532-
await editor.execCommand<Char>('insertText', {
1533-
text: 'c',
1534-
context: {
1535-
range: range,
1536-
},
1533+
await editor.execBatch(async () => {
1534+
const domEngine = editor.plugins.get(Layout).engines.dom;
1535+
const editable = domEngine.components.get('editable')[0];
1536+
const aNode = editable.next(node => node.name === 'a');
1537+
await withRange(editor, VRange.selecting(aNode, aNode), async range => {
1538+
await editor.execCommand<Char>('insertText', {
1539+
text: 'c',
1540+
context: {
1541+
range: range,
1542+
},
1543+
});
15371544
});
15381545
});
15391546
},
@@ -1551,12 +1558,14 @@ describe('VDocument', () => {
15511558
[aNode, RelativePosition.BEFORE],
15521559
[aNode, RelativePosition.BEFORE],
15531560
];
1554-
await withRange(editor, rangeParams, async range => {
1555-
await editor.execCommand<Char>('insertText', {
1556-
text: 'c',
1557-
context: {
1558-
range: range,
1559-
},
1561+
await editor.execBatch(async () => {
1562+
await withRange(editor, rangeParams, async range => {
1563+
await editor.execCommand<Char>('insertText', {
1564+
text: 'c',
1565+
context: {
1566+
range: range,
1567+
},
1568+
});
15601569
});
15611570
});
15621571
},
@@ -1574,12 +1583,14 @@ describe('VDocument', () => {
15741583
[aNode, RelativePosition.BEFORE],
15751584
[aNode, RelativePosition.AFTER],
15761585
];
1577-
await withRange(editor, rangeParams, async range => {
1578-
await editor.execCommand<Char>('insertText', {
1579-
text: 'c',
1580-
context: {
1581-
range: range,
1582-
},
1586+
await editor.execBatch(async () => {
1587+
await withRange(editor, rangeParams, async range => {
1588+
await editor.execCommand<Char>('insertText', {
1589+
text: 'c',
1590+
context: {
1591+
range: range,
1592+
},
1593+
});
15831594
});
15841595
});
15851596
},
@@ -1597,12 +1608,14 @@ describe('VDocument', () => {
15971608
[aNode, RelativePosition.AFTER],
15981609
[aNode, RelativePosition.AFTER],
15991610
];
1600-
await withRange(editor, rangeParams, async range => {
1601-
await editor.execCommand<Char>('insertText', {
1602-
text: 'c',
1603-
context: {
1604-
range: range,
1605-
},
1611+
await editor.execBatch(async () => {
1612+
await withRange(editor, rangeParams, async range => {
1613+
await editor.execCommand<Char>('insertText', {
1614+
text: 'c',
1615+
context: {
1616+
range: range,
1617+
},
1618+
});
16061619
});
16071620
});
16081621
},
@@ -1621,12 +1634,14 @@ describe('VDocument', () => {
16211634
[aNode, RelativePosition.AFTER],
16221635
[bNode, RelativePosition.BEFORE],
16231636
];
1624-
await withRange(editor, rangeParams, async range => {
1625-
await editor.execCommand<Char>('insertText', {
1626-
text: 'c',
1627-
context: {
1628-
range: range,
1629-
},
1637+
await editor.execBatch(async () => {
1638+
await withRange(editor, rangeParams, async range => {
1639+
await editor.execCommand<Char>('insertText', {
1640+
text: 'c',
1641+
context: {
1642+
range: range,
1643+
},
1644+
});
16301645
});
16311646
});
16321647
},
@@ -1645,12 +1660,14 @@ describe('VDocument', () => {
16451660
[aNode, RelativePosition.AFTER],
16461661
[bNode, RelativePosition.AFTER],
16471662
];
1648-
await withRange(editor, rangeParams, async range => {
1649-
await editor.execCommand<Char>('insertText', {
1650-
text: 'c',
1651-
context: {
1652-
range: range,
1653-
},
1663+
await editor.execBatch(async () => {
1664+
await withRange(editor, rangeParams, async range => {
1665+
await editor.execCommand<Char>('insertText', {
1666+
text: 'c',
1667+
context: {
1668+
range: range,
1669+
},
1670+
});
16541671
});
16551672
});
16561673
},

packages/core/test/VRange.test.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ describe('VRange', () => {
99
contentBefore: '<v>abc<w>de[f<x>ghi<y>jkl<z>mno</z>pqr</y>stu</x>vw</w>xy]z</v>',
1010
stepFunction: async (editor: BasicEditor) => {
1111
editor.dispatcher.registerCommand('refresh', { handler: () => {} });
12-
const nodes = editor.selection.range.split();
13-
const domEngine = editor.plugins.get(Layout).engines.dom;
14-
const editable = domEngine.components.get('editable')[0];
15-
editable.lastChild().after(nodes[0]);
12+
await editor.execBatch(async () => {
13+
const nodes = editor.selection.range.split();
14+
const domEngine = editor.plugins.get(Layout).engines.dom;
15+
const editable = domEngine.components.get('editable')[0];
16+
editable.lastChild().after(nodes[0]);
17+
});
1618
await editor.execCommand('refresh');
1719
},
1820
contentAfter:

packages/plugin-align/test/Align.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ describePlugin(Align, testEditor => {
4040
const domEngine = editor.plugins.get(Layout).engines.dom;
4141
const editable = domEngine.components.get('editable')[0];
4242
const root = editable;
43-
root.lastChild().editable = false;
44-
return align(AlignType.LEFT)(editor);
43+
return editor.execBatch(() => {
44+
root.lastChild().editable = false;
45+
return align(AlignType.LEFT)(editor);
46+
});
4547
},
4648
contentAfter: '<p>ab</p><p style="text-align: right;">c[]d</p>',
4749
});

packages/plugin-dialog/test/Dialog.test.ts

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ describe('Dialog', async () => {
7979
});
8080

8181
it('should add a vNode in the dialog', async () => {
82-
await editor.plugins.get(Layout).append('aaa', 'float');
82+
await editor.execBatch(() => {
83+
return editor.plugins.get(Layout).append('aaa', 'float');
84+
});
8385
expect(container.innerHTML.replace(/[\s\n]+/g, ' ')).to.equal(
8486
[
8587
'<jw-editor>',
@@ -97,14 +99,18 @@ describe('Dialog', async () => {
9799
);
98100
});
99101
it('should add a vNode in the dialog and hide it', async () => {
100-
await editor.plugins.get(Layout).append('aaa', 'float');
102+
await editor.execBatch(() => {
103+
return editor.plugins.get(Layout).append('aaa', 'float');
104+
});
101105
await editor.execCommand('hide', { componentId: 'aaa' });
102106
expect(container.innerHTML.replace(/[\s\n]+/g, ' ')).to.equal(
103107
['<jw-editor>', '<main></main>', '</jw-editor>'].join(''),
104108
);
105109
});
106110
it('should add a vNode in the dialog and show it', async () => {
107-
await editor.plugins.get(Layout).append('aaa', 'float');
111+
await editor.execBatch(() => {
112+
return editor.plugins.get(Layout).append('aaa', 'float');
113+
});
108114
await editor.execCommand('hide', { componentId: 'aaa' });
109115
await editor.execCommand('show', { componentId: 'aaa' });
110116
expect(container.innerHTML.replace(/[\s\n]+/g, ' ')).to.equal(
@@ -124,7 +130,9 @@ describe('Dialog', async () => {
124130
);
125131
});
126132
it('should add a vNode in dialog because dialog is the default zone', async () => {
127-
await editor.plugins.get(Layout).append('aaa', 'not available zone');
133+
await editor.execBatch(() => {
134+
return editor.plugins.get(Layout).append('aaa', 'not available zone');
135+
});
128136
await editor.execCommand('show', { componentId: 'aaa' });
129137
expect(container.innerHTML.replace(/[\s\n]+/g, ' ')).to.equal(
130138
[
@@ -143,10 +151,14 @@ describe('Dialog', async () => {
143151
);
144152
});
145153
it('should add 2 vNodes in the dialog and show it', async () => {
146-
await editor.plugins.get(Layout).append('aaa', 'float');
154+
await editor.execBatch(() => {
155+
return editor.plugins.get(Layout).append('aaa', 'float');
156+
});
147157
await editor.execCommand('show', { componentId: 'aaa' });
148158

149-
await editor.plugins.get(Layout).append('bbb', 'not available zone');
159+
await editor.execBatch(() => {
160+
return editor.plugins.get(Layout).append('bbb', 'not available zone');
161+
});
150162
await editor.execCommand('show', { componentId: 'bbb' });
151163

152164
expect(container.innerHTML.replace(/[\s\n]+/g, ' ')).to.equal(
@@ -174,10 +186,14 @@ describe('Dialog', async () => {
174186
);
175187
});
176188
it('should close 2 dialogs with the X button', async () => {
177-
await editor.plugins.get(Layout).append('aaa', 'float');
189+
await editor.execBatch(() => {
190+
return editor.plugins.get(Layout).append('aaa', 'float');
191+
});
178192
await editor.execCommand('show', { componentId: 'aaa' });
179193

180-
await editor.plugins.get(Layout).append('bbb', 'not available zone');
194+
await editor.execBatch(() => {
195+
return editor.plugins.get(Layout).append('bbb', 'not available zone');
196+
});
181197
await editor.execCommand('show', { componentId: 'bbb' });
182198

183199
await click(
@@ -217,10 +233,14 @@ describe('Dialog', async () => {
217233
expect(section.parent).to.instanceOf(DialogZoneNode);
218234
});
219235
it('should close 2 dialogs it with the backdrop', async () => {
220-
await editor.plugins.get(Layout).append('aaa', 'float');
236+
await editor.execBatch(() => {
237+
return editor.plugins.get(Layout).append('aaa', 'float');
238+
});
221239
await editor.execCommand('show', { componentId: 'aaa' });
222240

223-
await editor.plugins.get(Layout).append('bbb', 'not available zone');
241+
await editor.execBatch(() => {
242+
return editor.plugins.get(Layout).append('bbb', 'not available zone');
243+
});
224244
await editor.execCommand('show', { componentId: 'bbb' });
225245

226246
await click(
@@ -259,7 +279,9 @@ describe('Dialog', async () => {
259279
expect(section.parent).to.instanceOf(DialogZoneNode);
260280
});
261281
it('should close a dialog and re-open a dialog', async () => {
262-
await editor.plugins.get(Layout).append('aaa', 'float');
282+
await editor.execBatch(() => {
283+
return editor.plugins.get(Layout).append('aaa', 'float');
284+
});
263285
await editor.execCommand('show', { componentId: 'aaa' });
264286

265287
await click(
@@ -270,7 +292,9 @@ describe('Dialog', async () => {
270292
['<jw-editor>', '<main></main>', '</jw-editor>'].join(''),
271293
);
272294

273-
await editor.plugins.get(Layout).append('bbb', 'not available zone');
295+
await editor.execBatch(() => {
296+
return editor.plugins.get(Layout).append('bbb', 'not available zone');
297+
});
274298
await editor.execCommand('show', { componentId: 'bbb' });
275299

276300
expect(container.innerHTML.replace(/[\s\n]+/g, ' ')).to.equal(
@@ -291,7 +315,9 @@ describe('Dialog', async () => {
291315
);
292316
});
293317
it('should not close the dialog if click in content', async () => {
294-
await editor.plugins.get(Layout).append('bbb', 'not available zone');
318+
await editor.execBatch(() => {
319+
return editor.plugins.get(Layout).append('bbb', 'not available zone');
320+
});
295321
await editor.execCommand('show', { componentId: 'bbb' });
296322

297323
await click(Array.from(container.querySelectorAll('jw-dialog jw-content')).pop());
@@ -314,7 +340,9 @@ describe('Dialog', async () => {
314340
);
315341
});
316342
it('should hide a vNode in dialog (without remove the vNode)', async () => {
317-
await editor.plugins.get(Layout).append('bbb', 'not available zone');
343+
await editor.execBatch(() => {
344+
return editor.plugins.get(Layout).append('bbb', 'not available zone');
345+
});
318346

319347
await editor.execCommand('hide', { componentId: 'bbb' });
320348

packages/plugin-dom-follow-range/test/FollowRange.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ describe('FollowRange', async () => {
8282
location: [section, 'replace'],
8383
});
8484
await editor.start();
85+
86+
editor.memory.create('test').switchTo('test'); // Unfreeze the memory for test.
87+
8588
await editor.plugins.get(Layout).append('aaa', 'range');
8689
await editor.plugins.get(Layout).append('bbb', 'range');
8790
expect(container.innerHTML.replace(/[\s\n]+/g, ' ')).to.equal(

0 commit comments

Comments
 (0)