Skip to content

Commit 53a3ccd

Browse files
author
Dennis Labordus
committed
Fixed Wizard Menu.
Signed-off-by: Dennis Labordus <[email protected]>
1 parent 499c65c commit 53a3ccd

File tree

2 files changed

+74
-88
lines changed
  • src/editors/protocol104/wizards
  • test/unit/editors/protocol104/wizards

2 files changed

+74
-88
lines changed

src/editors/protocol104/wizards/doi.ts

Lines changed: 65 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ import '@material/mwc-textarea';
66
import {
77
ComplexAction,
88
getNameAttribute,
9+
newActionEvent,
910
newWizardEvent,
10-
Wizard, WizardMenuActor
11+
Wizard,
12+
WizardMenuActor,
1113
} from '../../../foundation.js';
1214

1315
import '../../../wizard-textfield.js';
@@ -16,8 +18,8 @@ import {
1618
getCdcValue,
1719
getCtlModel,
1820
getFullPath,
19-
PRIVATE_TYPE_104
20-
} from "../foundation/foundation.js";
21+
PRIVATE_TYPE_104,
22+
} from '../foundation/foundation.js';
2123

2224
export function renderDOIWizard(doiElement: Element): TemplateResult[] {
2325
const iedElement = doiElement.closest('IED');
@@ -26,84 +28,89 @@ export function renderDOIWizard(doiElement: Element): TemplateResult[] {
2628

2729
// Add the basic fields to the list.
2830
const fields: TemplateResult[] = [
29-
html `<wizard-textfield
30-
label="IED"
31-
.maybeValue=${getNameAttribute(iedElement!)}
32-
disabled
33-
readonly>
34-
</wizard-textfield>`,
35-
html `<mwc-textarea
36-
label="DOI"
37-
value="${fullpath}"
38-
rows="2"
39-
cols="40"
40-
readonly
41-
disabled>
42-
</mwc-textarea>`,
43-
html `<wizard-textfield
44-
label="cdc"
45-
.maybeValue=${cdc}
46-
disabled
47-
readonly>
48-
</wizard-textfield>`,
31+
html`<wizard-textfield
32+
label="IED"
33+
.maybeValue=${getNameAttribute(iedElement!)}
34+
disabled
35+
readonly
36+
>
37+
</wizard-textfield>`,
38+
html`<mwc-textarea
39+
label="DOI"
40+
value="${fullpath}"
41+
rows="2"
42+
cols="40"
43+
readonly
44+
disabled
45+
>
46+
</mwc-textarea>`,
47+
html`<wizard-textfield label="cdc" .maybeValue=${cdc} disabled readonly>
48+
</wizard-textfield>`,
4949
];
5050

51-
const firstAddressElement = doiElement.querySelector(`DAI > Private[type="${PRIVATE_TYPE_104}"] > Address`);
51+
const firstAddressElement = doiElement.querySelector(
52+
`DAI > Private[type="${PRIVATE_TYPE_104}"] > Address`
53+
);
5254
if (firstAddressElement) {
5355
const ti = firstAddressElement.getAttribute('ti');
5456

55-
fields.push(html `<wizard-textfield
56-
label="ti"
57-
.maybeValue=${ti}
58-
disabled
59-
readonly>
60-
</wizard-textfield>`
61-
);
57+
fields.push(html`<wizard-textfield
58+
label="ti"
59+
.maybeValue=${ti}
60+
disabled
61+
readonly
62+
>
63+
</wizard-textfield>`);
6264
}
6365

6466
const ctlModel = getCtlModel(doiElement);
6567
if (ctlModel !== null) {
66-
fields.push(html `<wizard-textfield
67-
label="ctlModel"
68-
.maybeValue=${ctlModel}
69-
disabled
70-
readonly>
71-
</wizard-textfield>`);
68+
fields.push(html`<wizard-textfield
69+
label="ctlModel"
70+
.maybeValue=${ctlModel}
71+
disabled
72+
readonly
73+
>
74+
</wizard-textfield>`);
7275
}
7376

7477
return fields;
7578
}
7679

7780
export function remove104Private(doiElement: Element): WizardMenuActor {
78-
// The 104 Private Element only contains Address Elements, so we can remove all the 104 Private Elements
79-
// to remove all the Address Elements also.
80-
const privateElements = doiElement.querySelectorAll(`DAI > Private[type="${PRIVATE_TYPE_104}"]`);
81-
const actions: ComplexAction[] = [];
82-
if (privateElements.length > 0) {
83-
const complexAction: ComplexAction = {
84-
actions: [],
85-
title: get('protocol104.values.removedAddresses',
86-
{ name: getFullPath(doiElement, 'SCL'),
87-
nrOfAddresses: privateElements.length
81+
return (wizard: Element): void => {
82+
// The 104 Private Element only contains Address Elements, so we can remove all the 104 Private Elements
83+
// to remove all the Address Elements also.
84+
const privateElements = doiElement.querySelectorAll(
85+
`DAI > Private[type="${PRIVATE_TYPE_104}"]`
86+
);
87+
if (privateElements.length > 0) {
88+
const complexAction: ComplexAction = {
89+
actions: [],
90+
title: get('protocol104.values.removedAddresses', {
91+
name: getFullPath(doiElement, 'SCL'),
92+
nrOfAddresses: privateElements.length,
8893
}),
89-
};
90-
privateElements.forEach(privateElement => {
91-
complexAction.actions.push({old: {parent: privateElement.parentElement!, element: privateElement}});
92-
});
93-
actions.push(complexAction);
94-
}
94+
};
95+
privateElements.forEach(privateElement => {
96+
complexAction.actions.push({
97+
old: {
98+
parent: privateElement.parentElement!,
99+
element: privateElement,
100+
},
101+
});
102+
});
95103

96-
return (): ComplexAction[] => {
97-
return actions;
104+
wizard.dispatchEvent(newActionEvent(complexAction));
105+
wizard.dispatchEvent(newWizardEvent());
106+
}
98107
};
99108
}
100109

101110
export function showDOIInfoWizard(doiElement: Element): Wizard {
102111
function close() {
103112
return function () {
104-
document
105-
.querySelector('open-scd')!
106-
.dispatchEvent(newWizardEvent());
113+
document.querySelector('open-scd')!.dispatchEvent(newWizardEvent());
107114
return [];
108115
};
109116
}
Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
import { expect, fixture, html } from '@open-wc/testing';
22

3-
import { MockWizard } from "../../../../mock-wizard.js";
3+
import { MockWizard } from '../../../../mock-wizard.js';
44

55
import '../../../../mock-wizard.js';
66

7-
import { ComplexAction, isSimple, WizardInputElement } from "../../../../../src/foundation.js";
7+
import { showDOIInfoWizard } from '../../../../../src/editors/protocol104/wizards/doi.js';
88

9-
import { remove104Private, showDOIInfoWizard } from "../../../../../src/editors/protocol104/wizards/doi.js";
10-
11-
import { fetchDoc } from "../../../wizards/test-support.js";
9+
import { fetchDoc } from '../../../wizards/test-support.js';
1210

1311
describe('Wizards for 104 DOI Element', () => {
1412
let doc: XMLDocument;
1513
let doi: Element;
1614
let element: MockWizard;
17-
let inputs: WizardInputElement[];
1815

1916
beforeEach(async () => {
2017
doc = await fetchDoc('/test/testfiles/104/valid-addresses.scd');
@@ -23,12 +20,13 @@ describe('Wizards for 104 DOI Element', () => {
2320

2421
describe('show 104 DOI Info', () => {
2522
beforeEach(async () => {
26-
doi = doc.querySelector('IED[name="B1"] LN[lnType="SE_GGIO_SET_V002"] DOI[name="CntVal1"]')!;
23+
doi = doc.querySelector(
24+
'IED[name="B1"] LN[lnType="SE_GGIO_SET_V002"] DOI[name="CntVal1"]'
25+
)!;
2726

2827
const wizard = showDOIInfoWizard(doi);
2928
element.workflow.push(() => wizard);
3029
await element.requestUpdate();
31-
inputs = Array.from(element.wizardUI.inputs);
3230
});
3331

3432
it('looks like the latest snapshot', async () => {
@@ -38,36 +36,17 @@ describe('Wizards for 104 DOI Element', () => {
3836

3937
describe('show 104 DOI Info with ctlModel', () => {
4038
beforeEach(async () => {
41-
doi = doc.querySelector('IED[name="B1"] LN[lnType="SE_GGIO_SET_V002"] DOI[name="CmdBlk"]')!;
39+
doi = doc.querySelector(
40+
'IED[name="B1"] LN[lnType="SE_GGIO_SET_V002"] DOI[name="CmdBlk"]'
41+
)!;
4242

4343
const wizard = showDOIInfoWizard(doi);
4444
element.workflow.push(() => wizard);
4545
await element.requestUpdate();
46-
inputs = Array.from(element.wizardUI.inputs);
4746
});
4847

4948
it('looks like the latest snapshot', async () => {
5049
await expect(element.wizardUI.dialog).dom.to.equalSnapshot();
5150
});
5251
});
53-
54-
describe('remove 104 Private elements', () => {
55-
it('return expected number of Delete Actions when there are 104 Private elements', () => {
56-
doi = doc.querySelector('IED[name="B1"] LN[lnType="SE_GGIO_SET_V002"] DOI[name="Mod"]')!;
57-
const actions = remove104Private(doi)();
58-
59-
expect(actions.length).to.equal(1);
60-
expect(actions[0]).to.not.satisfy(isSimple);
61-
62-
const complexAction = <ComplexAction>actions[0];
63-
expect(complexAction.actions.length).to.equal(2);
64-
})
65-
66-
it('return no Delete Actions when there are no 104 Private elements', () => {
67-
doi = doc.querySelector('IED[name="B1"] LN[lnType="SE_GSAL_SET_V001"] DOI[name="OpCntRs"]')!;
68-
const actions = remove104Private(doi)();
69-
70-
expect(actions.length).to.equal(0);
71-
})
72-
});
7352
});

0 commit comments

Comments
 (0)