Skip to content

Commit

Permalink
chore(104): validate IOA number in address-wizard (#1370)
Browse files Browse the repository at this point in the history
* chore(104): validate IOA number in address-wizard

Signed-off-by: Juan Munoz <juancho0202@gmail.com>

* test: added test for validation

Signed-off-by: Juan Munoz <juancho0202@gmail.com>

* chore(104): update validation message

Signed-off-by: Juan Munoz <juancho0202@gmail.com>

* test: updating validation message test

Signed-off-by: Juan Munoz <juancho0202@gmail.com>

* chore: adding typed `this`param to validateIOA fn

Signed-off-by: Juan Munoz <juancho0202@gmail.com>

* chore: removing unused attributes

Signed-off-by: Juan Munoz <juancho0202@gmail.com>

---------

Signed-off-by: Juan Munoz <juancho0202@gmail.com>
  • Loading branch information
juancho0202 authored Nov 27, 2023
1 parent 754c301 commit dff67ba
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages/open-scd/src/editors/protocol104/wizards/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,20 @@ export function editAddressWizard(
const cdc = getCdcValueFromDOIElement(doiElement) ?? '';
const ti = addressElement.getAttribute('ti') ?? '';

let casdu = addressElement.getAttribute('casdu') ?? '';

function validateIOA(this: WizardInputElement, value: string): Partial<ValidityState> {
const existingAddress = iedElement.querySelector(`Address[casdu="${casdu}"][ioa="${value}"]`);
if(existingAddress){
this.validationMessage = get('protocol104.wizard.error.ioaConflict');
return {
valid: false,
customError: true,
}
}
return {}
}

// Add the basic fields to the list.
const fields: TemplateResult[] = [
html`<wizard-textfield
Expand Down Expand Up @@ -136,12 +150,16 @@ export function editAddressWizard(
</mwc-textarea>`,
html`<wizard-textfield
label="casdu"
@change="${(evt: Event) => {
casdu = (<WizardInputElement>evt.target).value ?? '';
}}}"
.maybeValue="${live(addressElement.getAttribute('casdu') ?? '')}"
helper="${translate('protocol104.wizard.casduHelper')}"
required
>
</wizard-textfield>`,
html`<wizard-textfield
.validityTransform="${validateIOA}"
label="ioa"
.maybeValue="${live(addressElement.getAttribute('ioa') ?? '')}"
helper="${translate('protocol104.wizard.ioaHelper')}"
Expand Down
3 changes: 3 additions & 0 deletions packages/open-scd/src/foundation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ export type WizardInputElement =
| TextField
| (AceEditor & {
checkValidity: () => boolean;
validityTransform: (newValue: string, nativeValidity: ValidityState) => ValidityState;
validationMessage: string;
validity: ValidityState;
label: string;
requestUpdate(name?: PropertyKey, oldValue?: unknown): Promise<unknown>;
})
Expand Down
1 change: 1 addition & 0 deletions packages/open-scd/src/translations/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@ export const de: Translations = {
addAddress: '104-Adresse hinzufügen',
},
error: {
ioaConflict: 'IOA-Konflikt innerhalb der CASDU-Nummer gefunden',
addAddressError:
'Invalide Template Struktur, DAI kann nicht hinzugefügt werden (DO: "{{ doType }}", CDC: "{{ cdc }}", Structure: "{{ structure }}")',
},
Expand Down
1 change: 1 addition & 0 deletions packages/open-scd/src/translations/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@ export const en = {
addAddress: 'Add 104 Address',
},
error: {
ioaConflict: 'IOA conflict found within CASDU number',
addAddressError:
'Invalid Template Structure, unable to create DAI Element. (DO: "{{ doType }}", CDC: "{{ cdc }}", DAI: "{{ structure }}")',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,21 @@ describe('Wizards for 104 Address Element', () => {
inputs = Array.from(element.wizardUI.inputs);
}

describe('when adding a 104 Address', () => {
beforeEach(async () => {
await prepareWizard('IED[name="B1"] LN[lnType="SE_GGIO_SET_V002"] DOI[name="Mod"] DAI[name="ctlVal"] Address');
});

it('shows a validation error message if the combination of casdu and ioa is already in use', async () => {
await setWizardTextFieldValue(<WizardTextField>inputs[2], '208'); // Casdu Field
await setWizardTextFieldValue(<WizardTextField>inputs[3], '2'); // IOA Field
await element.updateComplete;
expect(inputs[3].checkValidity()).to.be.false;
expect(inputs[3].validity.customError).to.be.true;
expect(inputs[3].validationMessage).to.include('ioaConflict');
});
});

describe('edit basic 104 Address', () => {
beforeEach(async () => {
await prepareWizard(
Expand Down Expand Up @@ -80,6 +95,8 @@ describe('Wizards for 104 Address Element', () => {
it('looks like the latest snapshot', async () => {
await expect(element.wizardUI.dialog).dom.to.equalSnapshot();
});


});

describe('edit 104 Address with expected value', () => {
Expand Down

0 comments on commit dff67ba

Please sign in to comment.