Skip to content

Commit 5a8e659

Browse files
fix: Adding Subnetwork to a configuration without a Communication Element failed for the first time
When creating a `Communication` Element in Communication.ts, the created Element is also returned to use it as a parent for the wizard The `Should create a Communication Element` integration test is extended to also check that the Wizard is closed properly Signed-off-by: Pascal Wilbrink <[email protected]>
1 parent 7a12d77 commit 5a8e659

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

src/editors/Communication.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,28 @@ export default class CommunicationPlugin extends LitElement {
1818
@property()
1919
doc!: XMLDocument;
2020

21-
private createCommunication(): void {
21+
/**
22+
* Creates the Communication Element and returns the created Element
23+
* @returns {Element} Communication `Element`
24+
*/
25+
private createCommunication(): Element {
26+
const element: Element = createElement(this.doc, 'Communication', {});
2227
this.dispatchEvent(
2328
newActionEvent({
2429
new: {
2530
parent: this.doc.documentElement,
26-
element: createElement(this.doc, 'Communication', {}),
31+
element: element,
2732
},
2833
})
2934
);
35+
return element;
3036
}
3137

3238
/** Opens a [[`WizardDialog`]] for creating a new `SubNetwork` element. */
3339
private openCreateSubNetworkWizard(): void {
34-
const parent = this.doc.querySelector(':root > Communication');
35-
if (!parent) this.createCommunication();
40+
const parent =
41+
this.doc.querySelector(':root > Communication') ||
42+
this.createCommunication();
3643

3744
this.dispatchEvent(newWizardEvent(createSubNetworkWizard(parent!)));
3845
}

test/integration/editors/communication/Communication.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { MockWizard } from '../../../mock-wizard.js';
66
import Communication from '../../../../src/editors/Communication.js';
77
import { Editing } from '../../../../src/Editing.js';
88
import { Wizarding } from '../../../../src/Wizarding.js';
9+
import { Dialog } from '@material/mwc-dialog';
10+
import { WizardTextField } from '../../../../src/wizard-textfield.js';
911

1012
describe('Communication Plugin', () => {
1113
customElements.define(
@@ -73,5 +75,28 @@ describe('Communication Plugin', () => {
7375
await parent.updateComplete;
7476
expect(parent.wizardUI.dialogs.length).to.equal(1);
7577
});
78+
79+
it('Should create a Communication Element', async () => {
80+
expect(parent.wizardUI.dialogs.length).to.equal(0);
81+
fab.click();
82+
await parent.updateComplete;
83+
expect(parent.wizardUI.dialogs.length).to.equal(1);
84+
85+
const dialog: Dialog = parent.wizardUI.dialogs.item(0);
86+
87+
const nameInput: WizardTextField = dialog.querySelector<WizardTextField>('wizard-textfield[label="name"]')!;
88+
89+
nameInput.value = 'Test';
90+
91+
const saveButton: HTMLElement = dialog.querySelector('mwc-button[slot="primaryAction"]')!;
92+
93+
await parent.updateComplete;
94+
95+
saveButton.click();
96+
97+
await parent.updateComplete;
98+
99+
expect(parent.wizardUI.dialogs.length).to.equal(0);
100+
});
76101
});
77102
});

0 commit comments

Comments
 (0)