forked from ca-d/open-scd-core
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathopen-scd.wizard.spec.ts
72 lines (54 loc) · 1.86 KB
/
open-scd.wizard.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { expect } from '@open-wc/testing';
import './open-scd.js';
import type { OpenSCD } from './open-scd.js';
import { newEditWizardEvent } from './foundation/wizard-event.js';
const factor = window.process && process.env.CI ? 4 : 2;
function timeout(ms: number) {
return new Promise(res => setTimeout(res, ms * factor));
}
mocha.timeout(2000 * factor);
const doc = new DOMParser().parseFromString(
`<Parent>
<Element>
<ChildElement childAttr="someAttr"></ChildElement>
<ChildElement2 childAttr="someAttr"></ChildElement2>
<ChildElement3 childAttr="someAttr"></ChildElement3>
<ChildElement4 childAttr="someAttr"></ChildElement4>
</Element>
</Parent>`,
'application/xml'
);
let editor: OpenSCD;
beforeEach(() => {
editor = document.createElement('open-scd');
document.body.prepend(editor);
});
afterEach(() => {
editor.remove();
});
describe(`code wizard`, () => {
it(`removes wizard from workflow on close wizard event`, async () => {
await editor.updateComplete;
const element = doc.querySelector('ChildElement')!;
editor.dispatchEvent(newEditWizardEvent(element));
await timeout(100);
editor.codeWizard!.closeBtn.click();
await timeout(200);
expect(editor.workflow.length).to.equal(0);
});
it(`exchanges code wizard value on save`, async () => {
await editor.updateComplete;
const element = doc.querySelector('ChildElement')!;
const parent = element.parentElement;
const value = '<NewChildElement/>';
editor.dispatchEvent(newEditWizardEvent(element));
await timeout(50);
editor.codeWizard!.editor.value = value;
await timeout(200);
editor.codeWizard?.saveBtn.click();
await timeout(200);
expect(element.parentElement).to.be.null;
expect(parent?.querySelector('NewChildElement')).to.not.be.null;
expect(editor.workflow.length).to.equal(0);
});
});