Skip to content

Commit

Permalink
chore: add automatic ti selection
Browse files Browse the repository at this point in the history
Signed-off-by: Stef3st <[email protected]>
  • Loading branch information
Stef3st committed Dec 20, 2023
1 parent d2afab0 commit 7a0fd5f
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import '@material/mwc-switch';

import '../../../wizard-textfield.js';
import '../../../WizardDivider.js';
import { WizardSelect } from '../../../wizard-select.js';

import {
ComplexAction,
Expand Down Expand Up @@ -212,6 +213,21 @@ export function createAddressesWizard(
);
}

function setMonitorControlValue(
e: SelectedEvent,
isMonitor: boolean
): void {
const selectedTi = (<Select>e.target).selected!.value;
const counterType = isMonitor ? 'controlTi' : 'monitorTi';
const availableTis = (<Select>e.target).parentElement!.querySelector(
`wizard-select[label="${counterType}"]`
) as WizardSelect;

if (isMonitor)
availableTis.maybeValue = selectedTi === '30' ? '58' : '62';
else availableTis.maybeValue = selectedTi === '58' ? '30' : '35';
}

// Add the basic fields to the list.
const fields = [
html`<wizard-textfield
Expand Down Expand Up @@ -258,6 +274,7 @@ export function createAddressesWizard(
required
@selected=${(e: SelectedEvent) => {
setMonitorInvertedSwitch(e);
if (cdc === 'ENC') setMonitorControlValue(e, true);
}}
>
${monitorTis.map(
Expand Down Expand Up @@ -332,6 +349,9 @@ export function createAddressesWizard(
helper="${translate('protocol104.wizard.controlTiHelper')}"
fixedMenuPosition
required
@selected=${(e: SelectedEvent) => {
if (cdc === 'ENC') setMonitorControlValue(e, false);
}}
>
${controlTis.map(
controlTi =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
WizardInputElement,
} from '../../../../../src/foundation.js';

import { WizardTextField } from '../../../../../src/wizard-textfield.js';
import { WizardSelect } from '../../../../../src/wizard-select.js';
import '../../../../mock-wizard.js';

import {
Expand Down Expand Up @@ -119,6 +121,47 @@ describe('Wizards for preparing 104 Address Creation', () => {
});
});

describe('show prepare 104 Address creation with enc cdc value', () => {
let monitorTi: WizardSelect;
let controlTi: WizardSelect;

beforeEach(async () => {
await prepareWizard(
'IED[name="B1"] LN[lnType="SE_GGIO_SET_V002"]',
'Mod'
);
const cdc = element.wizardUI.dialog!.querySelector(
'wizard-textfield[label="Common Data Class"]'
) as WizardTextField;
expect(cdc).to.exist;
expect(cdc.maybeValue).to.equal('ENC');
monitorTi = element.wizardUI.dialog!.querySelector(
'wizard-select[label="monitorTi"]'
) as WizardSelect;
controlTi = element.wizardUI.dialog!.querySelector(
'wizard-select[label="controlTi"]'
) as WizardSelect;
expect(monitorTi).to.exist;
expect(controlTi).to.exist;
});
it('controlTi should change to correct value when selecting monitorTi', async () => {
monitorTi.value = '30';
await element.requestUpdate();
expect(controlTi.maybeValue).to.equal('58');
monitorTi.value = '35';
await element.requestUpdate();
expect(controlTi.maybeValue).to.equal('62');
});
it('monitorTi should change to correct value when selecting controlTi', async () => {
controlTi.value = '58';
await element.requestUpdate();
expect(monitorTi.maybeValue).to.equal('30');
controlTi.value = '62';
await element.requestUpdate();
expect(monitorTi.maybeValue).to.equal('35');
});
});

describe('show prepare 104 Address creation (single monitor TI with CtlModel)', () => {
beforeEach(async () => {
await prepareWizard(
Expand Down

0 comments on commit 7a0fd5f

Please sign in to comment.