Skip to content

Commit f389c2c

Browse files
author
Dennis Labordus
authored
feat(plugins/IED): Added Functional Constraint value to DA Container.
1 parent 179cad1 commit f389c2c

File tree

4 files changed

+134
-63
lines changed

4 files changed

+134
-63
lines changed

src/editors/ied/da-container.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { Nsdoc } from '../../foundation/nsdoc.js';
2121
@customElement('da-container')
2222
export class DAContainer extends LitElement {
2323
/**
24-
* The DA itself.
24+
* The (B)DA itself.
2525
*/
2626
@property({ attribute: false })
2727
element!: Element;
@@ -40,17 +40,19 @@ export class DAContainer extends LitElement {
4040

4141
@property()
4242
nsdoc!: Nsdoc;
43-
44-
@query('#toggleButton') toggleButton: IconButtonToggle | undefined;
43+
44+
@query('#toggleButton')
45+
toggleButton: IconButtonToggle | undefined;
4546

4647
private header(): TemplateResult {
4748
const name = getNameAttribute(this.element);
48-
const bType = this.element!.getAttribute('bType') ?? nothing;
49+
const bType = this.element.getAttribute('bType') ?? nothing;
50+
const fc = this.element.getAttribute("fc");
4951

5052
if (this.instanceElement) {
51-
return html`<b>${name}</b> &mdash; ${bType}`;
53+
return html`<b>${name}</b> &mdash; ${bType}${fc ? html` [${fc}]`: ``}`;
5254
} else {
53-
return html`${name} &mdash; ${bType}`;
55+
return html`${name} &mdash; ${bType}${fc ? html` [${fc}]`: ``}`;
5456
}
5557
}
5658

@@ -76,6 +78,7 @@ export class DAContainer extends LitElement {
7678
return element.querySelector('Val') ?? null;
7779
}
7880

81+
7982
/**
8083
* Get the nested (B)DA element(s) if available.
8184
* @returns The nested (B)DA element(s) of this (B)DA container.
@@ -132,4 +135,4 @@ export class DAContainer extends LitElement {
132135
padding-left: 0.3em;
133136
}
134137
`;
135-
}
138+
}

src/editors/ied/ln-container.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ export class LNContainer extends LitElement {
2828

2929
@property()
3030
nsdoc!: Nsdoc;
31-
32-
@query('#toggleButton') toggleButton!: IconButtonToggle | undefined;
31+
32+
@query('#toggleButton')
33+
toggleButton!: IconButtonToggle | undefined;
3334

3435
private async header(): Promise<TemplateResult> {
3536
const prefix = this.element.getAttribute('prefix');
@@ -67,7 +68,7 @@ export class LNContainer extends LitElement {
6768

6869
render(): TemplateResult {
6970
const doElements = this.getDOElements();
70-
71+
7172
return html`<action-pane .label="${until(this.header())}">
7273
${doElements.length > 0 ? html`<abbr slot="action" title="${translate('iededitor.toggleChildElements')}">
7374
<mwc-icon-button-toggle
@@ -77,7 +78,7 @@ export class LNContainer extends LitElement {
7778
@click=${() => this.requestUpdate()}
7879
></mwc-icon-button-toggle>
7980
</abbr>` : nothing}
80-
${this.toggleButton?.on ? this.getDOElements().map(dO => html`<do-container
81+
${this.toggleButton?.on ? doElements.map(dO => html`<do-container
8182
.element=${dO}
8283
.instanceElement=${this.getInstanceElement(dO)}
8384
.nsdoc=${this.nsdoc}
@@ -88,4 +89,4 @@ export class LNContainer extends LitElement {
8889
}
8990

9091
static styles = css``;
91-
}
92+
}

test/unit/editors/ied/__snapshots__/da-container.test.snap.js

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,26 @@
11
/* @web/test-runner snapshot v1 */
22
export const snapshots = {};
33

4-
snapshots["looks like the latest snapshot with a DA element"] =
4+
snapshots["looks like the latest snapshot with a DA element containing and a DAI"] =
5+
`<action-pane
6+
icon="done"
7+
tabindex="0"
8+
>
9+
<abbr slot="action">
10+
<mwc-icon-button
11+
icon="info"
12+
title="ctlModel"
13+
>
14+
</mwc-icon-button>
15+
</abbr>
16+
<h6>
17+
status-only
18+
</h6>
19+
</action-pane>
20+
`;
21+
/* end snapshot looks like the latest snapshot with a DA element containing and a DAI */
22+
23+
snapshots["with a DA element looks like the latest snapshot"] =
524
`<action-pane
625
icon=""
726
tabindex="0"
@@ -17,17 +36,35 @@ snapshots["looks like the latest snapshot with a DA element"] =
1736
</h6>
1837
</action-pane>
1938
`;
20-
/* end snapshot looks like the latest snapshot with a DA element */
39+
/* end snapshot with a DA element looks like the latest snapshot */
2140

22-
snapshots["looks like the latest snapshot with a DA element and child elements are toggled."] =
41+
snapshots["with a BDA element looks like the latest snapshot"] =
2342
`<action-pane
2443
icon=""
2544
tabindex="0"
2645
>
2746
<abbr slot="action">
2847
<mwc-icon-button
2948
icon="info"
30-
title="SBOw"
49+
title="ctlVal"
50+
>
51+
</mwc-icon-button>
52+
</abbr>
53+
<h6>
54+
</h6>
55+
</action-pane>
56+
`;
57+
/* end snapshot with a BDA element looks like the latest snapshot */
58+
59+
snapshots["with a DA element and child elements are toggled looks like the latest snapshot"] =
60+
`<action-pane
61+
icon=""
62+
tabindex="0"
63+
>
64+
<abbr slot="action">
65+
<mwc-icon-button
66+
icon="info"
67+
title="Some SBOw title"
3168
>
3269
</mwc-icon-button>
3370
</abbr>
@@ -59,24 +96,5 @@ snapshots["looks like the latest snapshot with a DA element and child elements a
5996
</da-container>
6097
</action-pane>
6198
`;
62-
/* end snapshot looks like the latest snapshot with a DA element and child elements are toggled. */
63-
64-
snapshots["looks like the latest snapshot with a DA element containing and a DAI."] =
65-
`<action-pane
66-
icon="done"
67-
tabindex="0"
68-
>
69-
<abbr slot="action">
70-
<mwc-icon-button
71-
icon="info"
72-
title="ctlModel"
73-
>
74-
</mwc-icon-button>
75-
</abbr>
76-
<h6>
77-
status-only
78-
</h6>
79-
</action-pane>
80-
`;
81-
/* end snapshot looks like the latest snapshot with a DA element containing and a DAI. */
99+
/* end snapshot with a DA element and child elements are toggled looks like the latest snapshot */
82100

test/unit/editors/ied/da-container.test.ts

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

33
import '../../../../src/editors/ied/da-container.js';
4+
45
import { DAContainer } from '../../../../src/editors/ied/da-container.js';
56
import { initializeNsdoc } from '../../../../src/foundation/nsdoc.js';
7+
import {TemplateResult} from "lit-element";
68

79
describe('da-container', async () => {
810
let element: DAContainer;
@@ -16,38 +18,85 @@ describe('da-container', async () => {
1618
.then(str => new DOMParser().parseFromString(str, 'application/xml'));
1719
});
1820

19-
it('looks like the latest snapshot with a DA element', async () => {
20-
element = await fixture(html`<da-container
21-
.element=${validSCL.querySelector(
22-
'DataTypeTemplates > DOType[id="Dummy.XCBR1.Pos"] > DA[name="ctlModel"]')}
23-
.nsdoc=${nsdoc}
24-
></da-container>`);
25-
expect(element).shadowDom.to.equalSnapshot();
21+
describe('with a DA element', () => {
22+
beforeEach(async () => {
23+
element = await fixture(html`<da-container
24+
.element=${validSCL.querySelector(
25+
'DataTypeTemplates > DOType[id="Dummy.XCBR1.Pos"] > DA[name="ctlModel"]')}
26+
.nsdoc=${nsdoc}
27+
></da-container>`);
28+
});
29+
30+
it('check the values returned for the header', () => {
31+
const header = element['header']();
32+
expect(header.values.length).to.be.equals(3);
33+
expect(header.values[0]).to.be.equals('ctlModel');
34+
expect(header.values[1]).to.be.equals('Enum');
35+
expect((<TemplateResult>header.values[2]).values.length).to.be.equals(1);
36+
expect((<TemplateResult>header.values[2]).values[0]).to.be.equals('CF');
37+
})
38+
39+
it('looks like the latest snapshot', async () => {
40+
expect(element).shadowDom.to.equalSnapshot();
41+
});
2642
});
2743

28-
it('looks like the latest snapshot with a DA element and child elements are toggled.', async () => {
29-
element = await fixture(html`<da-container
30-
.element=${validSCL.querySelector(
31-
'DataTypeTemplates > DOType[id="Dummy.LPHD1.Sim"] > DA[name="SBOw"]')}
32-
.nsdoc=${nsdoc}
33-
></da-container>`);
44+
describe('with a BDA element', () => {
45+
beforeEach(async () => {
46+
element = await fixture(html`<da-container
47+
.element=${validSCL.querySelector(
48+
'DataTypeTemplates > DAType[id="Dummy.LPHD1.Sim.SBOw"] > BDA[name="ctlVal"]')}
49+
.daParent=${validSCL.querySelector(
50+
'DataTypeTemplates > DOType[id="Dummy.LPHD1.Sim"] > DA[name="SBOw"]')}
51+
.ancestors=${[validSCL.querySelector(
52+
'DataTypeTemplates > DOType[id="Dummy.LPHD1.Sim"] > DA[name="SBOw"]')]}
53+
.nsdoc=${nsdoc}
54+
></da-container>`);
55+
});
3456

35-
(<HTMLElement>(
36-
element.shadowRoot!.querySelector('mwc-icon-button-toggle')
37-
)).click();
38-
await element.requestUpdate();
39-
await element.updateComplete;
40-
expect(element).shadowDom.to.equalSnapshot();
41-
42-
(<HTMLElement>(
43-
element.shadowRoot!.querySelector('mwc-icon-button-toggle')
44-
)).click();
45-
await element.requestUpdate();
46-
await element.updateComplete;
47-
expect(element.shadowRoot!.querySelectorAll('do-container').length).to.eql(0);
57+
it('check the values returned for the header', () => {
58+
const header = element['header']();
59+
expect(header.values.length).to.be.equals(3);
60+
expect(header.values[0]).to.be.equals('ctlVal');
61+
expect(header.values[1]).to.be.equals('BOOLEAN');
62+
expect(header.values[2]).to.be.equals('');
63+
})
64+
65+
it('looks like the latest snapshot', async () => {
66+
expect(element).shadowDom.to.equalSnapshot();
67+
});
68+
});
69+
70+
describe('with a DA element and child elements are toggled', () => {
71+
beforeEach(async () => {
72+
element = await fixture(html`<da-container
73+
.element=${validSCL.querySelector(
74+
'DataTypeTemplates > DOType[id="Dummy.LPHD1.Sim"] > DA[name="SBOw"]')}
75+
.nsdoc=${nsdoc}
76+
></da-container>`);
77+
78+
(<HTMLElement>(
79+
element.shadowRoot!.querySelector('mwc-icon-button-toggle')
80+
)).click();
81+
await element.requestUpdate();
82+
await element.updateComplete;
83+
});
84+
85+
it('when closing the container, no elements found', async () => {
86+
(<HTMLElement>(
87+
element.shadowRoot!.querySelector('mwc-icon-button-toggle')
88+
)).click();
89+
await element.requestUpdate();
90+
await element.updateComplete;
91+
expect(element.shadowRoot!.querySelectorAll('do-container').length).to.eql(0);
92+
});
93+
94+
it('looks like the latest snapshot', async () => {
95+
expect(element).shadowDom.to.equalSnapshot();
96+
});
4897
});
4998

50-
it('looks like the latest snapshot with a DA element containing and a DAI.', async () => {
99+
it('looks like the latest snapshot with a DA element containing and a DAI', async () => {
51100
element = await fixture(html`<da-container
52101
.element=${validSCL.querySelector(
53102
'DataTypeTemplates > DOType[id="Dummy.XCBR1.Pos"] > DA[name="ctlModel"]')}

0 commit comments

Comments
 (0)