-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoscd-background-editv1.spec.ts
More file actions
57 lines (47 loc) · 1.53 KB
/
oscd-background-editv1.spec.ts
File metadata and controls
57 lines (47 loc) · 1.53 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
import { expect, fixture, html } from '@open-wc/testing';
import { SinonSpy, spy } from 'sinon';
import OscdMenuOpen from './oscd-background-editv1.js';
import OscdBackgroundEditV1 from './oscd-background-editv1.js';
import { XMLEditor } from '@omicronenergy/oscd-editor';
import { isEdit, isEditV2 } from '@omicronenergy/oscd-api/utils.js';
const doc = new DOMParser().parseFromString(
'<SCL><Substation name="AA1"></Substation></SCL>',
'application/xml',
);
customElements.define('oscd-background-editv1', OscdMenuOpen);
describe('oscd-background-editv1', () => {
let plugin: OscdBackgroundEditV1;
let xmlEditorCommit: SinonSpy;
beforeEach(async () => {
xmlEditorCommit = spy();
plugin = await fixture(
html`<oscd-background-editv1></oscd-background-editv1>`,
);
plugin.editor = {
commit: xmlEditorCommit,
} as unknown as XMLEditor;
document.body.append(plugin);
plugin.click();
});
afterEach(() => plugin.remove());
it('It calls XMLEditor.commit when an oscd-edit event is recieved', async () => {
const editV1 = {
element: doc.querySelector('Substation')!,
attributes: {
attr1: {
value: 'value1',
namespaceURI: 'http://www.example.com/ns',
},
},
};
expect(editV1).to.satisfy(isEdit);
document.dispatchEvent(
new CustomEvent('oscd-edit', {
detail: editV1,
}),
);
expect(xmlEditorCommit.callCount).to.equal(1);
const [editV2] = xmlEditorCommit.args;
expect(editV2).to.satisfy(isEditV2);
});
});