Skip to content

Commit 38911fd

Browse files
author
Dennis Labordus
authored
chore(refactor/unittest): Refactor Wizard UnitTests openscd#1003
1 parent 342c30f commit 38911fd

File tree

9 files changed

+147
-55
lines changed

9 files changed

+147
-55
lines changed

test/unit/editors/protocol104/wizards/address.test.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ describe('Wizards for 104 Address Element', () => {
6060

6161
const updateAction = executeWizardReplaceAction(
6262
updateAddressValue(doi, dai, address),
63+
element.wizardUI,
6364
inputs
6465
);
6566
expect(updateAction.old.element).to.have.attribute('casdu', '1');
@@ -69,7 +70,11 @@ describe('Wizards for 104 Address Element', () => {
6970
});
7071

7172
it('when no fields changed there will be no update action', async function () {
72-
expectWizardNoUpdateAction(updateAddressValue(doi, dai, address), inputs);
73+
expectWizardNoUpdateAction(
74+
updateAddressValue(doi, dai, address),
75+
element.wizardUI,
76+
inputs
77+
);
7378
});
7479

7580
it('looks like the latest snapshot', async () => {
@@ -101,6 +106,7 @@ describe('Wizards for 104 Address Element', () => {
101106

102107
const updateAction = executeWizardReplaceAction(
103108
updateAddressValue(doi, dai, address),
109+
element.wizardUI,
104110
inputs
105111
);
106112
expect(updateAction.old.element).to.not.have.attribute('unitMultiplier');
@@ -125,6 +131,7 @@ describe('Wizards for 104 Address Element', () => {
125131

126132
const updateAction = executeWizardReplaceAction(
127133
updateAddressValue(doi, dai, address),
134+
element.wizardUI,
128135
inputs
129136
);
130137
expect(updateAction.old.element).to.not.have.attribute('scaleMultiplier');

test/unit/editors/singlelinediagram/wizards/bay.test.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ describe('Wizards for SCL element Bay (X/Y)', () => {
3636

3737
const updateAction = executeWizardReplaceAction(
3838
updateNamingAndCoordinatesAction(bay),
39+
element.wizardUI,
3940
inputs
4041
);
4142
expect(updateAction.old.element).to.have.attribute('name', 'BusBar A');
@@ -50,6 +51,7 @@ describe('Wizards for SCL element Bay (X/Y)', () => {
5051

5152
const updateAction = executeWizardReplaceAction(
5253
updateNamingAndCoordinatesAction(bay),
54+
element.wizardUI,
5355
inputs
5456
);
5557
expect(updateAction.old.element).to.not.have.attribute('desc');
@@ -64,6 +66,7 @@ describe('Wizards for SCL element Bay (X/Y)', () => {
6466

6567
const updateAction = executeWizardReplaceAction(
6668
updateNamingAndCoordinatesAction(bay),
69+
element.wizardUI,
6770
inputs
6871
);
6972
expect(updateAction.old.element).to.have.attribute('sxy:x', '1');
@@ -75,6 +78,7 @@ describe('Wizards for SCL element Bay (X/Y)', () => {
7578

7679
const updateAction = executeWizardReplaceAction(
7780
updateNamingAndCoordinatesAction(bay),
81+
element.wizardUI,
7882
inputs
7983
);
8084
expect(updateAction.old.element).to.have.attribute('sxy:y', '1');
@@ -86,14 +90,19 @@ describe('Wizards for SCL element Bay (X/Y)', () => {
8690

8791
const updateAction = executeWizardReplaceAction(
8892
updateNamingAndCoordinatesAction(bay),
93+
element.wizardUI,
8994
inputs
9095
);
9196
expect(updateAction.old.element).to.have.attribute('sxy:y', '1');
9297
expect(updateAction.new.element).to.not.have.attribute('sxy:y');
9398
});
9499

95100
it('when no fields changed there will be no update action', async function () {
96-
expectWizardNoUpdateAction(updateNamingAndCoordinatesAction(bay), inputs);
101+
expectWizardNoUpdateAction(
102+
updateNamingAndCoordinatesAction(bay),
103+
element.wizardUI,
104+
inputs
105+
);
97106
});
98107

99108
it('looks like the latest snapshot', async () => {

test/unit/editors/singlelinediagram/wizards/conductingequipment.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ describe('Wizards for SCL element Conducting Equipment (X/Y)', () => {
3636

3737
const updateAction = executeWizardReplaceAction(
3838
updateNamingAndCoordinatesAction(conductingEquipment),
39+
element.wizardUI,
3940
inputs
4041
);
4142
expect(updateAction.old.element).to.have.attribute('name', 'QB1');
@@ -50,6 +51,7 @@ describe('Wizards for SCL element Conducting Equipment (X/Y)', () => {
5051

5152
const updateAction = executeWizardReplaceAction(
5253
updateNamingAndCoordinatesAction(conductingEquipment),
54+
element.wizardUI,
5355
inputs
5456
);
5557
expect(updateAction.old.element).to.not.have.attribute('desc');
@@ -64,6 +66,7 @@ describe('Wizards for SCL element Conducting Equipment (X/Y)', () => {
6466

6567
const updateAction = executeWizardReplaceAction(
6668
updateNamingAndCoordinatesAction(conductingEquipment),
69+
element.wizardUI,
6770
inputs
6871
);
6972
expect(updateAction.old.element).to.have.attribute('sxy:x', '1');
@@ -75,6 +78,7 @@ describe('Wizards for SCL element Conducting Equipment (X/Y)', () => {
7578

7679
const updateAction = executeWizardReplaceAction(
7780
updateNamingAndCoordinatesAction(conductingEquipment),
81+
element.wizardUI,
7882
inputs
7983
);
8084
expect(updateAction.old.element).to.have.attribute('sxy:y', '1');
@@ -86,6 +90,7 @@ describe('Wizards for SCL element Conducting Equipment (X/Y)', () => {
8690

8791
const updateAction = executeWizardReplaceAction(
8892
updateNamingAndCoordinatesAction(conductingEquipment),
93+
element.wizardUI,
8994
inputs
9095
);
9196
expect(updateAction.old.element).to.have.attribute('sxy:y', '1');
@@ -95,6 +100,7 @@ describe('Wizards for SCL element Conducting Equipment (X/Y)', () => {
95100
it('when no fields changed there will be no update action', async function () {
96101
expectWizardNoUpdateAction(
97102
updateNamingAndCoordinatesAction(conductingEquipment),
103+
element.wizardUI,
98104
inputs
99105
);
100106
});

test/unit/editors/singlelinediagram/wizards/powertransformer.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ describe('Wizards for SCL element Power Transformer (X/Y)', () => {
3636

3737
const updateAction = executeWizardReplaceAction(
3838
updateNamingAndCoordinatesAction(powerTransformer),
39+
element.wizardUI,
3940
inputs
4041
);
4142
expect(updateAction.old.element).to.have.attribute('name', 'TA1');
@@ -50,6 +51,7 @@ describe('Wizards for SCL element Power Transformer (X/Y)', () => {
5051

5152
const updateAction = executeWizardReplaceAction(
5253
updateNamingAndCoordinatesAction(powerTransformer),
54+
element.wizardUI,
5355
inputs
5456
);
5557
expect(updateAction.old.element).to.not.have.attribute('desc');
@@ -64,6 +66,7 @@ describe('Wizards for SCL element Power Transformer (X/Y)', () => {
6466

6567
const updateAction = executeWizardReplaceAction(
6668
updateNamingAndCoordinatesAction(powerTransformer),
69+
element.wizardUI,
6770
inputs
6871
);
6972
expect(updateAction.old.element).to.have.attribute('sxy:x', '1');
@@ -75,6 +78,7 @@ describe('Wizards for SCL element Power Transformer (X/Y)', () => {
7578

7679
const updateAction = executeWizardReplaceAction(
7780
updateNamingAndCoordinatesAction(powerTransformer),
81+
element.wizardUI,
7882
inputs
7983
);
8084
expect(updateAction.old.element).to.have.attribute('sxy:y', '9');
@@ -86,6 +90,7 @@ describe('Wizards for SCL element Power Transformer (X/Y)', () => {
8690

8791
const updateAction = executeWizardReplaceAction(
8892
updateNamingAndCoordinatesAction(powerTransformer),
93+
element.wizardUI,
8994
inputs
9095
);
9196
expect(updateAction.old.element).to.have.attribute('sxy:y', '9');
@@ -95,6 +100,7 @@ describe('Wizards for SCL element Power Transformer (X/Y)', () => {
95100
it('when no fields changed there will be no update action', async function () {
96101
expectWizardNoUpdateAction(
97102
updateNamingAndCoordinatesAction(powerTransformer),
103+
element.wizardUI,
98104
inputs
99105
);
100106
});

test/unit/wizards/dai.test.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import {
1616

1717
import {
1818
fetchDoc,
19-
newWizard,
2019
setWizardSelectValue,
2120
setWizardTextFieldValue,
2221
} from './test-support.js';
@@ -61,7 +60,7 @@ describe('Wizards for SCL element DAI', () => {
6160
da,
6261
dai,
6362
dai
64-
)(inputs, newWizard());
63+
)(inputs, element.wizardUI);
6564
expectCreateComplexAction(complexActions, '24');
6665
});
6766

@@ -97,7 +96,7 @@ describe('Wizards for SCL element DAI', () => {
9796
da,
9897
dai,
9998
dai
100-
)(inputs, newWizard());
99+
)(inputs, element.wizardUI);
101100
expectCreateComplexAction(complexActions, '0000-00-00T00:00:00.000');
102101
});
103102

@@ -126,7 +125,7 @@ describe('Wizards for SCL element DAI', () => {
126125
it('update value should be updated in document', async function () {
127126
await setWizardTextFieldValue(<WizardTextField>inputs[0], '8');
128127

129-
const complexActions = updateValue(da, dai)(inputs, newWizard());
128+
const complexActions = updateValue(da, dai)(inputs, element.wizardUI);
130129
expectUpdateComplexAction(complexActions);
131130

132131
const replace = <Replace>(<ComplexAction>complexActions[0]).actions[0];
@@ -159,7 +158,7 @@ describe('Wizards for SCL element DAI', () => {
159158
it('update value should be updated in document', async function () {
160159
await setWizardSelectValue(<WizardSelect>inputs[0], 'blocked');
161160

162-
const complexActions = updateValue(da, dai)(inputs, newWizard());
161+
const complexActions = updateValue(da, dai)(inputs, element.wizardUI);
163162
expectUpdateComplexAction(complexActions);
164163

165164
const create = <Create>(<ComplexAction>complexActions[0]).actions[0];

test/unit/wizards/ied.test.ts

Lines changed: 62 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
import {
1313
editIEDWizard,
1414
removeIEDAndReferences,
15-
removeIEDWizard
15+
removeIEDWizard,
1616
} from '../../../src/wizards/ied.js';
1717

1818
import {
@@ -21,10 +21,9 @@ import {
2121
expectUpdateAction,
2222
expectWizardNoUpdateAction,
2323
fetchDoc,
24-
newWizard,
2524
setWizardTextFieldValue,
2625
} from './test-support.js';
27-
import { updateNamingAttributeWithReferencesAction } from "../../../src/wizards/foundation/actions.js";
26+
import { updateNamingAttributeWithReferencesAction } from '../../../src/wizards/foundation/actions.js';
2827

2928
describe('Wizards for SCL element IED', () => {
3029
let doc: XMLDocument;
@@ -47,41 +46,67 @@ describe('Wizards for SCL element IED', () => {
4746
inputs = Array.from(element.wizardUI.inputs);
4847
});
4948
it('contains a wizard-textfield with a non-empty "type" value', async () => {
50-
expect((<WizardTextField[]>inputs).find(textField => textField.label == 'type')?.value).to
51-
.be.equal(ied.getAttribute('type') || '-');
49+
expect(
50+
(<WizardTextField[]>inputs).find(textField => textField.label == 'type')
51+
?.value
52+
).to.be.equal(ied.getAttribute('type') || '-');
5253
});
5354
it('contains a wizard-textfield with a non-empty "manufacturer" value', async () => {
54-
expect((<WizardTextField[]>inputs).find(textField => textField.label == 'manufacturer')?.value).to
55-
.be.equal(ied.getAttribute('manufacturer') || '-');
55+
expect(
56+
(<WizardTextField[]>inputs).find(
57+
textField => textField.label == 'manufacturer'
58+
)?.value
59+
).to.be.equal(ied.getAttribute('manufacturer') || '-');
5660
});
5761
it('contains a wizard-textfield with a non-empty "configVersion" value', async () => {
58-
expect((<WizardTextField[]>inputs).find(textField => textField.label == 'configVersion')?.value).to
59-
.be.equal(ied.getAttribute('configVersion') || '-');
62+
expect(
63+
(<WizardTextField[]>inputs).find(
64+
textField => textField.label == 'configVersion'
65+
)?.value
66+
).to.be.equal(ied.getAttribute('configVersion') || '-');
6067
});
6168
it('contains a wizard-textfield with a non-empty "originalSclVersion" value', async () => {
62-
expect((<WizardTextField[]>inputs).find(textField => textField.label == 'originalSclVersion')?.value).to
63-
.contain(ied.getAttribute('originalSclVersion') || '-');
69+
expect(
70+
(<WizardTextField[]>inputs).find(
71+
textField => textField.label == 'originalSclVersion'
72+
)?.value
73+
).to.contain(ied.getAttribute('originalSclVersion') || '-');
6474
});
6575
it('contains a wizard-textfield with an empty "engRight" value', async () => {
66-
expect((<WizardTextField[]>inputs).find(textField => textField.label == 'engRight')?.value).to
67-
.be.equal(ied.getAttribute('engRight') || '-');
76+
expect(
77+
(<WizardTextField[]>inputs).find(
78+
textField => textField.label == 'engRight'
79+
)?.value
80+
).to.be.equal(ied.getAttribute('engRight') || '-');
6881
});
6982
it('contains a wizard-textfield with a non-empty "owner" value', async () => {
70-
expect((<WizardTextField[]>inputs).find(textField => textField.label == 'owner')?.value).to
71-
.be.equal(ied.getAttribute('owner') || '-');
83+
expect(
84+
(<WizardTextField[]>inputs).find(
85+
textField => textField.label == 'owner'
86+
)?.value
87+
).to.be.equal(ied.getAttribute('owner') || '-');
7288
});
7389
it('update name should be updated in document', async function () {
7490
await setWizardTextFieldValue(<WizardTextField>inputs[0], 'OtherIED3');
7591

76-
const complexAction = updateNamingAttributeWithReferencesAction(ied, 'ied.action.updateied')(inputs, newWizard());
92+
const complexAction = updateNamingAttributeWithReferencesAction(
93+
ied,
94+
'ied.action.updateied'
95+
)(inputs, element.wizardUI);
7796
expect(complexAction.length).to.equal(1);
7897
expect(complexAction[0]).to.not.satisfy(isSimple);
7998

8099
const simpleActions = (<ComplexAction>complexAction[0]).actions;
81100
expect(simpleActions.length).to.equal(2);
82101

83102
expectUpdateAction(simpleActions[0], 'IED', 'name', 'IED3', 'OtherIED3');
84-
expectReplaceAction(simpleActions[1], 'ConnectedAP', 'iedName', 'IED3', 'OtherIED3');
103+
expectReplaceAction(
104+
simpleActions[1],
105+
'ConnectedAP',
106+
'iedName',
107+
'IED3',
108+
'OtherIED3'
109+
);
85110
});
86111

87112
it('update name should be unique in document', async function () {
@@ -95,18 +120,31 @@ describe('Wizards for SCL element IED', () => {
95120
'Some description'
96121
);
97122

98-
const complexAction = updateNamingAttributeWithReferencesAction(ied, 'ied.action.updateied')(inputs, newWizard());
123+
const complexAction = updateNamingAttributeWithReferencesAction(
124+
ied,
125+
'ied.action.updateied'
126+
)(inputs, element.wizardUI);
99127
expect(complexAction.length).to.equal(1);
100128
expect(complexAction[0]).to.not.satisfy(isSimple);
101129

102130
const simpleActions = (<ComplexAction>complexAction[0]).actions;
103131
expect(simpleActions.length).to.equal(1);
104132

105-
expectUpdateAction(simpleActions[0], 'IED', 'desc', null, 'Some description');
133+
expectUpdateAction(
134+
simpleActions[0],
135+
'IED',
136+
'desc',
137+
null,
138+
'Some description'
139+
);
106140
});
107141

108142
it('when no fields changed there will be no update action', async function () {
109-
expectWizardNoUpdateAction(updateNamingAttributeWithReferencesAction(ied, 'ied.action.updateied'), inputs);
143+
expectWizardNoUpdateAction(
144+
updateNamingAttributeWithReferencesAction(ied, 'ied.action.updateied'),
145+
element.wizardUI,
146+
inputs
147+
);
110148
});
111149

112150
it('looks like the latest snapshot', async () => {
@@ -126,7 +164,10 @@ describe('Wizards for SCL element IED', () => {
126164
});
127165

128166
it('remove IED should return expected actions', async function () {
129-
const complexAction = removeIEDAndReferences(ied)(inputs, newWizard());
167+
const complexAction = removeIEDAndReferences(ied)(
168+
inputs,
169+
element.wizardUI
170+
);
130171

131172
expect(complexAction.length).to.equal(1);
132173
expect(complexAction[0]).to.not.satisfy(isSimple);

0 commit comments

Comments
 (0)