Skip to content

Commit 617e72d

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 5a8e659 commit 617e72d

File tree

3 files changed

+29
-26
lines changed

3 files changed

+29
-26
lines changed

src/editors/Communication.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ export default class CommunicationPlugin extends LitElement {
3737

3838
/** Opens a [[`WizardDialog`]] for creating a new `SubNetwork` element. */
3939
private openCreateSubNetworkWizard(): void {
40-
const parent =
41-
this.doc.querySelector(':root > Communication') ||
40+
const parent =this.doc.querySelector(':root > Communication') ||
4241
this.createCommunication();
4342

4443
this.dispatchEvent(newWizardEvent(createSubNetworkWizard(parent!)));

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

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
import { html, fixture, expect } from '@open-wc/testing';
22

3-
import '../../../mock-wizard.js';
4-
import { MockWizard } from '../../../mock-wizard.js';
3+
import '../../../mock-wizard-editor.js';
4+
import { MockWizardEditor } from '../../../mock-wizard-editor.js';
55

6-
import Communication from '../../../../src/editors/Communication.js';
7-
import { Editing } from '../../../../src/Editing.js';
8-
import { Wizarding } from '../../../../src/Wizarding.js';
6+
import Communication from '../../../../src/editors/Communication.js';
97
import { Dialog } from '@material/mwc-dialog';
108
import { WizardTextField } from '../../../../src/wizard-textfield.js';
119

1210
describe('Communication Plugin', () => {
1311
customElements.define(
1412
'communication-plugin',
15-
Wizarding(Editing(Communication))
13+
Communication
1614
);
1715
let element: Communication;
1816
beforeEach(async () => {
@@ -45,18 +43,23 @@ describe('Communication Plugin', () => {
4543

4644
describe('with a doc loaded missing a communication section', () => {
4745
let doc: XMLDocument;
48-
let parent: MockWizard;
46+
let parent: MockWizardEditor;
4947
let fab: HTMLElement;
48+
let element: Communication;
5049

5150
beforeEach(async () => {
5251
doc = await fetch('/test/testfiles/missingCommunication.scd')
5352
.then(response => response.text())
5453
.then(str => new DOMParser().parseFromString(str, 'application/xml'));
55-
parent = <MockWizard>(
54+
55+
element = await fixture(
56+
html`<communication-plugin .doc="${doc}"></communication-plugin>`
57+
);
58+
59+
parent = <MockWizardEditor>(
5660
await fixture(
57-
html`<mock-wizard
58-
><communication-plugin .doc=${doc}></communication-plugin
59-
></mock-wizard>`
61+
html`<mock-wizard-editor
62+
>${element}/mock-wizard-editor>`
6063
)
6164
);
6265
await element.updateComplete;
@@ -78,25 +81,28 @@ describe('Communication Plugin', () => {
7881

7982
it('Should create a Communication Element', async () => {
8083
expect(parent.wizardUI.dialogs.length).to.equal(0);
81-
fab.click();
84+
expect(element.doc.querySelector('Communication')).is.null;
85+
86+
await fab.click();
87+
await new Promise(resolve => setTimeout(resolve, 100)); // await animation
8288
await parent.updateComplete;
83-
expect(parent.wizardUI.dialogs.length).to.equal(1);
8489

85-
const dialog: Dialog = parent.wizardUI.dialogs.item(0);
90+
expect(parent.wizardUI.dialogs.length).to.equal(1);
91+
92+
const dialog: Dialog = parent.wizardUI.dialog!;
93+
expect(dialog).to.not.be.undefined;
8694

8795
const nameInput: WizardTextField = dialog.querySelector<WizardTextField>('wizard-textfield[label="name"]')!;
88-
8996
nameInput.value = 'Test';
97+
await new Promise(resolve => setTimeout(resolve, 100)); // await animation
9098

9199
const saveButton: HTMLElement = dialog.querySelector('mwc-button[slot="primaryAction"]')!;
100+
await saveButton.click();
101+
await new Promise(resolve => setTimeout(resolve, 100)); // await animation
92102

93-
await parent.updateComplete;
94-
95-
saveButton.click();
96-
97-
await parent.updateComplete;
98-
99-
expect(parent.wizardUI.dialogs.length).to.equal(0);
103+
expect(parent.wizardUI.dialog).not.to.exist;
104+
expect(element.doc.querySelector('Communication')).not.is.null;
105+
expect(element.doc.querySelector('Communication > SubNetwork[name="Test"]')).to.exist;
100106
});
101107
});
102108
});

test/integration/editors/communication/__snapshots__/Communication.test.snap.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ snapshots["Communication Plugin without a doc loaded looks like the latest snaps
1313
>
1414
</mwc-fab>
1515
</h1>
16-
<wizard-dialog>
17-
</wizard-dialog>
1816
`;
1917
/* end snapshot Communication Plugin without a doc loaded looks like the latest snapshot */
2018

0 commit comments

Comments
 (0)