Skip to content

Commit 15c2d3b

Browse files
fix(editors/template): make sure that edit wizards are always opened (openscd#845)
1 parent b012f7d commit 15c2d3b

File tree

2 files changed

+163
-8
lines changed

2 files changed

+163
-8
lines changed

src/editors/Templates.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const nsd7420 = fetch('public/xml/IEC_61850-7-420_2019A4.nsd')
5151
/** An editor [[`plugin`]] for editing the `DataTypeTemplates` section. */
5252
export default class TemplatesPlugin extends LitElement {
5353
/** The document being edited as provided to plugins by [[`OpenSCD`]]. */
54-
@property()
54+
@property({ attribute: false })
5555
doc!: XMLDocument;
5656

5757
async openCreateLNodeTypeWizard(): Promise<void> {
@@ -181,7 +181,7 @@ export default class TemplatesPlugin extends LitElement {
181181
</h1>
182182
<filtered-list
183183
id="lnodetypelist"
184-
@selected=${(e: SingleSelectedEvent) =>
184+
@action=${(e: SingleSelectedEvent) =>
185185
this.openLNodeTypeWizard(
186186
(<ListItem>(<List>e.target).selected).value
187187
)}
@@ -221,7 +221,7 @@ export default class TemplatesPlugin extends LitElement {
221221
</h1>
222222
<filtered-list
223223
id="dotypelist"
224-
@selected=${(e: SingleSelectedEvent) =>
224+
@action=${(e: SingleSelectedEvent) =>
225225
this.openDOTypeWizard(
226226
(<ListItem>(<List>e.target).selected).value
227227
)}
@@ -260,7 +260,7 @@ export default class TemplatesPlugin extends LitElement {
260260
</h1>
261261
<filtered-list
262262
id="datypelist"
263-
@selected=${(e: SingleSelectedEvent) =>
263+
@action=${(e: SingleSelectedEvent) =>
264264
this.openDATypeWizard(
265265
(<ListItem>(<List>e.target).selected).value
266266
)}
@@ -296,7 +296,7 @@ export default class TemplatesPlugin extends LitElement {
296296
</h1>
297297
<filtered-list
298298
id="enumtypelist"
299-
@selected=${(e: SingleSelectedEvent) =>
299+
@action=${(e: SingleSelectedEvent) =>
300300
this.openEnumTypeWizard(
301301
(<ListItem>(<List>e.target).selected).value
302302
)}

test/integration/editors/templates/Templates.test.ts

Lines changed: 158 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,30 @@ import { html, fixture, expect } from '@open-wc/testing';
33
import '../../../mock-wizard-editor.js';
44
import { MockWizardEditor } from '../../../mock-wizard-editor.js';
55

6+
import TemplatesPlugin from '../../../../src/editors/Templates.js';
67
import { Editing, EditingElement } from '../../../../src/Editing.js';
78
import { Wizarding, WizardingElement } from '../../../../src/Wizarding.js';
8-
import TemplatesPlugin from '../../../../src/editors/Templates.js';
9+
import { newWizardEvent } from '../../../../src/foundation.js';
910

1011
describe('Templates Plugin', () => {
1112
customElements.define(
1213
'templates-plugin',
1314
Wizarding(Editing(TemplatesPlugin))
1415
);
16+
1517
let element: TemplatesPlugin;
18+
let parent: MockWizardEditor;
19+
1620
beforeEach(async () => {
17-
element = await fixture(html`<templates-plugin></templates-plugin>`);
21+
parent = <MockWizardEditor>(
22+
await fixture(
23+
html`<mock-wizard-editor
24+
><templates-plugin></templates-plugin
25+
></mock-wizard-editor>`
26+
)
27+
);
28+
29+
element = parent.querySelector<TemplatesPlugin>('templates-plugin')!;
1830
});
1931

2032
describe('without a doc loaded', () => {
@@ -29,12 +41,150 @@ describe('Templates Plugin', () => {
2941
doc = await fetch('/test/testfiles/templates/datypes.scd')
3042
.then(response => response.text())
3143
.then(str => new DOMParser().parseFromString(str, 'application/xml'));
44+
3245
element.doc = doc;
33-
await element.updateComplete;
46+
await element.requestUpdate();
3447
});
48+
3549
it('looks like the latest snapshot', async () => {
3650
await expect(element).shadowDom.to.equalSnapshot();
3751
});
52+
53+
describe('having a LNodeType element list that', () => {
54+
beforeEach(async () => {
55+
parent.workflow.length = 0;
56+
(<HTMLElement>(
57+
element?.shadowRoot
58+
?.querySelectorAll('filtered-list')[0]
59+
.querySelector('mwc-list-item')
60+
)).click();
61+
62+
await parent.requestUpdate();
63+
});
64+
65+
it('opens a LNodeType edit wizard on list element click', () =>
66+
expect(
67+
parent.wizardUI.dialog?.querySelector(
68+
'wizard-textfield[label="lnClass"]'
69+
)
70+
).to.exist);
71+
72+
it('allows to reopen the LNodeType edit wizard for the same element', async () => {
73+
parent.dispatchEvent(newWizardEvent());
74+
75+
await parent.requestUpdate();
76+
77+
(<HTMLElement>(
78+
element?.shadowRoot?.querySelector(
79+
'filtered-list:nth-of-type(1) > mwc-list-item'
80+
)
81+
)).click();
82+
await parent.requestUpdate();
83+
84+
expect(
85+
parent.wizardUI.dialog?.querySelector(
86+
'wizard-textfield[label="lnClass"]'
87+
)
88+
).to.exist;
89+
});
90+
});
91+
92+
describe('having a DOType element list that', () => {
93+
beforeEach(async () => {
94+
parent.workflow.length = 0;
95+
(<HTMLElement>(
96+
element?.shadowRoot
97+
?.querySelectorAll('filtered-list')[1]
98+
.querySelector('mwc-list-item')
99+
)).click();
100+
101+
await parent.requestUpdate();
102+
});
103+
104+
it('opens a DOType edit wizard on list element click', () =>
105+
expect(
106+
parent.wizardUI.dialog?.querySelector('wizard-textfield[label="CDC"]')
107+
).to.exist);
108+
109+
it('allows to reopen the DOType edit wizard for the same element', async () => {
110+
parent.dispatchEvent(newWizardEvent());
111+
112+
await parent.requestUpdate();
113+
114+
(<HTMLElement>(
115+
element?.shadowRoot
116+
?.querySelectorAll('filtered-list')[1]
117+
.querySelector('mwc-list-item')
118+
)).click();
119+
await parent.requestUpdate();
120+
121+
expect(
122+
parent.wizardUI.dialog?.querySelector('wizard-textfield[label="CDC"]')
123+
).to.exist;
124+
});
125+
});
126+
127+
describe('having a DAType element list that', () => {
128+
beforeEach(async () => {
129+
parent.workflow.length = 0;
130+
(<HTMLElement>(
131+
element?.shadowRoot
132+
?.querySelectorAll('filtered-list')[2]
133+
.querySelector('mwc-list-item')
134+
)).click();
135+
136+
await parent.requestUpdate();
137+
});
138+
139+
it('opens a DAType edit wizard on list element click', () =>
140+
expect(parent.wizardUI.dialog).to.exist);
141+
142+
it('allows to reopen the DAType edit wizard for the same element', async () => {
143+
parent.dispatchEvent(newWizardEvent());
144+
145+
await parent.requestUpdate();
146+
147+
(<HTMLElement>(
148+
element?.shadowRoot
149+
?.querySelectorAll('filtered-list')[3]
150+
.querySelector('mwc-list-item')
151+
)).click();
152+
await parent.requestUpdate();
153+
154+
expect(parent.wizardUI.dialog).to.exist;
155+
});
156+
});
157+
158+
describe('having a EnumType element list that', () => {
159+
beforeEach(async () => {
160+
parent.workflow.length = 0;
161+
(<HTMLElement>(
162+
element?.shadowRoot
163+
?.querySelectorAll('filtered-list')[3]
164+
.querySelector('mwc-list-item')
165+
)).click();
166+
167+
await parent.requestUpdate();
168+
});
169+
170+
it('opens a EnumType edit wizard on list element click', () =>
171+
expect(parent.wizardUI.dialog).to.exist);
172+
173+
it('allows to reopen the EnumType edit wizard for the same element', async () => {
174+
parent.dispatchEvent(newWizardEvent());
175+
176+
await parent.requestUpdate();
177+
178+
(<HTMLElement>(
179+
element?.shadowRoot
180+
?.querySelectorAll('filtered-list')[3]
181+
.querySelector('mwc-list-item')
182+
)).click();
183+
await parent.requestUpdate();
184+
185+
expect(parent.wizardUI.dialog).to.exist;
186+
});
187+
});
38188
});
39189

40190
describe('with a doc loaded missing a datatypetemplates section', () => {
@@ -55,9 +205,11 @@ describe('Templates Plugin', () => {
55205
);
56206
await element.updateComplete;
57207
});
208+
58209
it('has a mwc-fab', () => {
59210
expect(element.shadowRoot?.querySelector('mwc-fab')).to.exist;
60211
});
212+
61213
it('adds a DataTypeTemplates on floating action button click', async () => {
62214
expect(doc.querySelector('DataTypeTemplates')).to.not.exist;
63215
(<HTMLElement>(
@@ -73,6 +225,7 @@ describe('Templates Plugin', () => {
73225
).to.exist;
74226
});
75227
});
228+
76229
describe('with a doc loaded having a datatypetemplates section', () => {
77230
let doc: XMLDocument;
78231
let parent: WizardingElement & EditingElement;
@@ -90,6 +243,7 @@ describe('Templates Plugin', () => {
90243
);
91244
await element.updateComplete;
92245
});
246+
93247
it('opens an add enumtype wizard', async () => {
94248
expect(parent.wizardUI.dialogs.length).to.equal(0);
95249
(<HTMLElement>(
@@ -103,6 +257,7 @@ describe('Templates Plugin', () => {
103257
await new Promise(resolve => setTimeout(resolve, 100)); // await animation
104258
expect(parent.wizardUI.dialogs.length).to.equal(1);
105259
});
260+
106261
it('adding an EnumType with the enumtype wizard', async () => {
107262
expect(doc.querySelectorAll('EnumType').length).to.equal(4);
108263
(<HTMLElement>(

0 commit comments

Comments
 (0)