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

Commit a4f8889

Browse files
committed
tests for perfs
1 parent 032af5e commit a4f8889

File tree

1 file changed

+112
-0
lines changed

1 file changed

+112
-0
lines changed
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/* eslint-disable max-nested-callbacks */
2+
import { expect } from 'chai';
3+
import { BasicEditor } from '../../bundle-basic-editor/BasicEditor';
4+
import { DomEditable } from '../../plugin-dom-editable/src/DomEditable';
5+
import { DomLayout } from '../../plugin-dom-layout/src/DomLayout';
6+
import { Layout } from '../../plugin-layout/src/Layout';
7+
import { DomLayoutEngine } from '../../plugin-dom-layout/src/DomLayoutEngine';
8+
9+
describe('test performances', () => {
10+
describe('stores', () => {
11+
describe('Memory / VDocument', () => {
12+
let wrapper: HTMLElement;
13+
let editor: BasicEditor;
14+
15+
beforeEach(async () => {
16+
wrapper = document.createElement('test-wrapper');
17+
wrapper.style.display = 'block';
18+
document.body.appendChild(wrapper);
19+
const root = document.createElement('div');
20+
root.innerHTML = `<h1>Jabberwocky</h1>
21+
<h3>by Lewis Carroll</h3>
22+
<p><i>’Twas brillig, and the slithy toves<br/>
23+
Did gyre and gimble in the wabe:<br/>
24+
All mimsy were the borogoves,<br/>
25+
And the mome raths outgrabe.<br/>
26+
<br/>
27+
“Beware the Jabberwock, my son!<br/>
28+
The jaws that bite, the claws that catch!<br/>
29+
Beware the Jubjub bird, and shun<br/>
30+
The frumious Bandersnatch!”<br/>
31+
<br/>
32+
He took his vorpal sword in hand;<br/>
33+
Long time the manxome foe he sought—<br/>
34+
So rested he by the Tumtum tree<br/>
35+
And stood awhile in thought.<br/>
36+
<br/>
37+
And, as in uffish thought he stood,<br/>
38+
The Jabberwock, with eyes of flame,<br/>
39+
Came whiffling through the tulgey wood,<br/>
40+
And burbled as it came!<br/>
41+
<br/>
42+
One, two! One, two! And through and through<br/>
43+
The vorpal blade went snicker-snack!<br/>
44+
He left it dead, and with its head<br/>
45+
He went galumphing back.<br/>
46+
<br/>
47+
“And hast thou slain the Jabberwock?<br/>
48+
Come to my arms, my beamish boy!<br/>
49+
O frabjous day! Callooh! Callay!”<br/>
50+
He chortled in his joy.<br/>
51+
<br/>
52+
’Twas brillig, and the slithy toves<br/>
53+
Did gyre and gimble in the wabe:<br/>
54+
All mimsy were the borogoves,<br/>
55+
And the mome raths outgrabe.<br/></i></p>`;
56+
wrapper.appendChild(root);
57+
58+
editor = new BasicEditor();
59+
editor.configure(DomLayout, { location: [root, 'replace'] });
60+
editor.configure(DomEditable, { source: root });
61+
await editor.start();
62+
});
63+
afterEach(async () => {
64+
editor.stop();
65+
document.body.removeChild(wrapper);
66+
});
67+
68+
it('should split a paragraph in two', async () => {
69+
// Parse the editable in the internal format of the editor.
70+
const memory = editor.memory;
71+
const domEngine = editor.plugins.get(Layout).engines.dom as DomLayoutEngine;
72+
const editable = domEngine.components.get('editable')[0];
73+
editor.selection.setAt(editable.children()[2].children()[500]);
74+
75+
memory.linkToMemory(editable);
76+
memory.create('root').switchTo('root');
77+
78+
expect(editable.children().length).to.equal(3);
79+
memory.create('test').switchTo('test');
80+
await editor.execCommand('insertParagraphBreak');
81+
expect(editable.children().length).to.equal(4);
82+
83+
const t1 = [];
84+
const t2 = [];
85+
for (let k = 2; k < 26; k++) {
86+
let d = Date.now();
87+
memory
88+
.switchTo('root')
89+
.create(k.toString())
90+
.switchTo(k.toString());
91+
t1.push(Date.now() - d);
92+
93+
d = Date.now();
94+
await editor.execCommand('insertParagraphBreak');
95+
t2.push(Date.now() - d);
96+
}
97+
98+
// We remove the first load because it does not represent time in
99+
// use. In fact, time is much longer because the functions and
100+
// object are not yet loaded. The loading test is done separately.
101+
t1.shift();
102+
t2.shift();
103+
104+
const averageInsert = Math.round(t2.reduce((a, b) => a + b) / t2.length);
105+
expect(averageInsert).to.lessThan(30, 'Time to compute the insert paragraph');
106+
107+
const averageSwitch = Math.round(t1.reduce((a, b) => a + b) / t1.length);
108+
expect(averageSwitch).to.lessThan(1, 'Time to switch the memory');
109+
});
110+
});
111+
});
112+
});

0 commit comments

Comments
 (0)