forked from OpenEnergyTools/scl-communication
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoscd-editor-communication.spec.ts
More file actions
68 lines (50 loc) · 2 KB
/
oscd-editor-communication.spec.ts
File metadata and controls
68 lines (50 loc) · 2 KB
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
/* eslint-disable @typescript-eslint/no-unused-expressions */
import { expect, fixture, html } from '@open-wc/testing';
import { SinonSpy, spy } from 'sinon';
import { isInsert } from '@openenergytools/scl-lib/dist/foundation/utils.js';
import { docBlob, missingCommunication } from './communication.testfiles.js';
import OscdEditorCommunication from './oscd-editor-communication.js';
import { OscdEditDialogEvents } from '@omicronenergy/oscd-edit-dialog/oscd-edit-dialog-events.js';
const doc = new DOMParser().parseFromString(docBlob, 'application/xml');
const missComm = new DOMParser().parseFromString(
missingCommunication,
'application/xml',
);
describe('Scl Communication Plugin', () => {
customElements.define('oscd-editor-communication', OscdEditorCommunication);
let editor: OscdEditorCommunication;
let editEvent: SinonSpy;
beforeEach(async () => {
editor = await fixture(
html`<oscd-editor-communication
.doc="${doc}"
></oscd-editor-communication>`,
);
editEvent = spy();
editor.addEventListener('oscd-edit-v2', event => {
editEvent(event);
editor.editCount += 1;
});
editor.addEventListener(OscdEditDialogEvents.CREATE_EVENT, editEvent);
});
afterEach(() => {
editor.remove();
});
it('sends a wizard create request on Fab click', () => {
editor.add.click();
expect(editEvent).to.have.been.calledOnce;
const eventDetails = editEvent.args[0][0].detail;
expect(eventDetails.parent).to.equal(doc.querySelector('Communication'));
});
it('create a Communication section parent element when missing', async () => {
editor.doc = missComm;
await editor.updateComplete;
editor.add.click();
expect(editEvent).to.have.been.calledTwice;
const insert = editEvent.args[0][0].detail.edit;
expect(insert).to.satisfy(isInsert);
const createRequest = editEvent.args[1][0].detail;
expect(createRequest.parent).to.equal(insert.node);
expect(createRequest.tagName).to.equal('SubNetwork');
});
});