Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Adding Subnetwork to a configuration without a Communication Ele… #875

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/editors/Communication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,27 @@ export default class CommunicationPlugin extends LitElement {
@property()
doc!: XMLDocument;

private createCommunication(): void {
/**
* Creates the Communication Element and returns the created Element
* @returns {Element} Communication `Element`
*/
private createCommunication(): Element {
const element: Element = createElement(this.doc, 'Communication', {});
this.dispatchEvent(
newActionEvent({
new: {
parent: this.doc.documentElement,
element: createElement(this.doc, 'Communication', {}),
element: element,
},
})
);
return element;
}

/** Opens a [[`WizardDialog`]] for creating a new `SubNetwork` element. */
private openCreateSubNetworkWizard(): void {
const parent = this.doc.querySelector(':root > Communication');
if (!parent) this.createCommunication();
const parent =this.doc.querySelector(':root > Communication') ||
this.createCommunication();

this.dispatchEvent(newWizardEvent(createSubNetworkWizard(parent!)));
}
Expand Down
50 changes: 39 additions & 11 deletions test/integration/editors/communication/Communication.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { html, fixture, expect } from '@open-wc/testing';

import '../../../mock-wizard.js';
import { MockWizard } from '../../../mock-wizard.js';
import '../../../mock-wizard-editor.js';
import { MockWizardEditor } from '../../../mock-wizard-editor.js';

import Communication from '../../../../src/editors/Communication.js';
import { Editing } from '../../../../src/Editing.js';
import { Wizarding } from '../../../../src/Wizarding.js';
import Communication from '../../../../src/editors/Communication.js';
import { Dialog } from '@material/mwc-dialog';
import { WizardTextField } from '../../../../src/wizard-textfield.js';

describe('Communication Plugin', () => {
customElements.define(
'communication-plugin',
Wizarding(Editing(Communication))
Communication
);
let element: Communication;
beforeEach(async () => {
Expand Down Expand Up @@ -43,18 +43,23 @@ describe('Communication Plugin', () => {

describe('with a doc loaded missing a communication section', () => {
let doc: XMLDocument;
let parent: MockWizard;
let parent: MockWizardEditor;
let fab: HTMLElement;
let element: Communication;

beforeEach(async () => {
doc = await fetch('/test/testfiles/missingCommunication.scd')
.then(response => response.text())
.then(str => new DOMParser().parseFromString(str, 'application/xml'));
parent = <MockWizard>(

element = await fixture(
html`<communication-plugin .doc="${doc}"></communication-plugin>`
);

parent = <MockWizardEditor>(
await fixture(
html`<mock-wizard
><communication-plugin .doc=${doc}></communication-plugin
></mock-wizard>`
html`<mock-wizard-editor
>${element}/mock-wizard-editor>`
)
);
await element.updateComplete;
Expand All @@ -73,5 +78,28 @@ describe('Communication Plugin', () => {
await parent.updateComplete;
expect(parent.wizardUI.dialogs.length).to.equal(1);
});

it('Should create a Communication Element', async () => {
expect(parent.wizardUI.dialogs.length).to.equal(0);
JakobVogelsang marked this conversation as resolved.
Show resolved Hide resolved
expect(element.doc.querySelector('Communication')).is.null;

await fab.click();
await new Promise(resolve => setTimeout(resolve, 100)); // await animation
JakobVogelsang marked this conversation as resolved.
Show resolved Hide resolved
await parent.updateComplete;

const dialog: Dialog = parent.wizardUI.dialog!;
pascalwilbrink marked this conversation as resolved.
Show resolved Hide resolved
expect(dialog).to.not.be.undefined;

const nameInput: WizardTextField = dialog.querySelector<WizardTextField>('wizard-textfield[label="name"]')!;
pascalwilbrink marked this conversation as resolved.
Show resolved Hide resolved
nameInput.value = 'Test';
await new Promise(resolve => setTimeout(resolve, 100)); // await animation
pascalwilbrink marked this conversation as resolved.
Show resolved Hide resolved

const saveButton: HTMLElement = dialog.querySelector('mwc-button[slot="primaryAction"]')!;
await saveButton.click();
await new Promise(resolve => setTimeout(resolve, 100)); // await animation
pascalwilbrink marked this conversation as resolved.
Show resolved Hide resolved

pascalwilbrink marked this conversation as resolved.
Show resolved Hide resolved
expect(element.doc.querySelector('Communication')).not.is.null;
expect(element.doc.querySelector('Communication > SubNetwork[name="Test"]')).to.exist;
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ snapshots["Communication Plugin without a doc loaded looks like the latest snaps
>
</mwc-fab>
</h1>
<wizard-dialog>
</wizard-dialog>
`;
/* end snapshot Communication Plugin without a doc loaded looks like the latest snapshot */