Skip to content

Commit 1a67f66

Browse files
committed
feat: add tests for FunctionEditor component
1 parent afc3624 commit 1a67f66

File tree

2 files changed

+42
-9
lines changed

2 files changed

+42
-9
lines changed

function-editor.spec.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/* eslint-disable no-unused-expressions */
2+
import { html, fixture, expect } from '@open-wc/testing';
3+
import './function-editor.js';
4+
import { testScl } from './scl-bay-template.testfiles.js';
5+
6+
describe('FunctionEditor', () => {
7+
let element: any;
8+
let doc: XMLDocument;
9+
10+
beforeEach(async () => {
11+
doc = new DOMParser().parseFromString(testScl, 'application/xml');
12+
const func = doc.querySelector('Function');
13+
element = await fixture(
14+
html`<compas-function-editor-a1b2c3d4
15+
.doc=${doc}
16+
.function=${func}
17+
></compas-function-editor-a1b2c3d4>`
18+
);
19+
await element.updateComplete;
20+
});
21+
22+
it('renders the add subfunction dialog and fields', () => {
23+
element.addSubFunctionDialog.show();
24+
expect(element.addSubFunctionDialog.open).to.be.true;
25+
expect(element.subFunctionNameField).to.exist;
26+
expect(element.subFunctionDescField).to.exist;
27+
expect(element.subFunctionTypeField).to.exist;
28+
});
29+
30+
it('enforces unique subfunction names', async () => {
31+
const parent = doc.querySelector('Function');
32+
element.subFunctionDialogParent = parent;
33+
34+
element.addSubFunctionDialog.show();
35+
element.subFunctionNameField.value = 'General';
36+
element.saveSubFunction();
37+
await element.updateComplete;
38+
expect(element.subFunctionNameField.validationMessage).to.match(
39+
/Name must be unique/i
40+
);
41+
});
42+
});

function-editor.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -970,15 +970,6 @@ export default class FunctionEditor9030 extends LitElement {
970970
this.openCreateWizard('EqFunction');
971971
}
972972

973-
addSubFunction(parent: Element): void {
974-
if (parent.tagName === 'Function' || parent.tagName === 'SubFunction') {
975-
this.dispatchEvent(newCreateWizardEvent(parent, 'SubFunction'));
976-
return;
977-
}
978-
979-
this.dispatchEvent(newCreateWizardEvent(parent, 'EqSubFunction'));
980-
}
981-
982973
createNewLNodeElements(): void {
983974
if (!this.lnodeparent) return;
984975

0 commit comments

Comments
 (0)