Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(104): validate IOA number in address-wizard #1370

Merged
merged 8 commits into from
Nov 27, 2023
19 changes: 19 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,21 @@ export function editAddressWizard(
const cdc = getCdcValueFromDOIElement(doiElement) ?? '';
const ti = addressElement.getAttribute('ti') ?? '';

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

function validateIOA(value: string, nativeValidity: ValidityState): Partial<ValidityState> {
const existingAddress = iedElement.querySelector(`Address[casdu="${casdu}"][ioa="${value}"]`);
if(existingAddress){
// @ts-ignore
(this as WizardInputElement).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 +151,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
5 changes: 5 additions & 0 deletions packages/open-scd/src/foundation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@ export type WizardInputElement =
| TextField
| (AceEditor & {
checkValidity: () => boolean;
setCustomValidity: (message: string) => void;
validityTransform: (newValue: string, nativeValidity: ValidityState) => ValidityState;
validationMessage: string;
validity: ValidityState;
reportValidity: () => boolean;
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