From 327d095384eb737f06245e4fca6bfd2e2b3f3ebb Mon Sep 17 00:00:00 2001 From: Stef3st Date: Thu, 11 Jan 2024 16:31:44 +0100 Subject: [PATCH] chore: add requested changes from @juancho0202 Signed-off-by: Stef3st --- .../__snapshots__/ldevice.test.snap.js | 4 +- .../test/unit/wizards/ldevice.test.ts | 44 ++++++++++++++++--- 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/packages/open-scd/test/unit/wizards/__snapshots__/ldevice.test.snap.js b/packages/open-scd/test/unit/wizards/__snapshots__/ldevice.test.snap.js index 6f9dd08532..8739657908 100644 --- a/packages/open-scd/test/unit/wizards/__snapshots__/ldevice.test.snap.js +++ b/packages/open-scd/test/unit/wizards/__snapshots__/ldevice.test.snap.js @@ -1,7 +1,7 @@ /* @web/test-runner snapshot v1 */ export const snapshots = {}; -snapshots["Wizards for SCL element LDevice Allowing ldName editing looks like the latest snapshot"] = +snapshots["Wizards for SCL element LDevice Allowing/Disallowing ldName editing looks like the latest snapshot"] = ` `; -/* end snapshot Wizards for SCL element LDevice Allowing ldName editing looks like the latest snapshot */ +/* end snapshot Wizards for SCL element LDevice Allowing/Disallowing ldName editing looks like the latest snapshot */ diff --git a/packages/open-scd/test/unit/wizards/ldevice.test.ts b/packages/open-scd/test/unit/wizards/ldevice.test.ts index 01595b3bee..372fb07565 100644 --- a/packages/open-scd/test/unit/wizards/ldevice.test.ts +++ b/packages/open-scd/test/unit/wizards/ldevice.test.ts @@ -4,10 +4,17 @@ import '../../mock-wizard.js'; import { MockWizard } from '../../mock-wizard.js'; import { WizardTextField } from '../../../src/wizard-textfield.js'; -import { WizardInputElement } from '../../../src/foundation.js'; +import { + WizardInputElement, + createUpdateAction, + getValue, +} from '../../../src/foundation.js'; import { editLDeviceWizard } from '../../../src/wizards/ldevice.js'; - -import { fetchDoc, setWizardTextFieldValue } from './test-support.js'; +import { + fetchDoc, + setWizardTextFieldValue, + expectUpdateAction, +} from './test-support.js'; describe('Wizards for SCL element LDevice', () => { let doc: XMLDocument; @@ -48,7 +55,7 @@ describe('Wizards for SCL element LDevice', () => { ).to.be.equal(''); }); - describe('Allowing ldName editing', () => { + describe('Allowing/Disallowing ldName editing', () => { it('ConfLdName should not be present and therefore ldName should be readonly', async function () { expect(services.querySelector('ConfLdName')).to.not.exist; expect(inputs[0]).to.have.attribute('readonly'); @@ -58,7 +65,7 @@ describe('Wizards for SCL element LDevice', () => { await expect(element.wizardUI.dialog).dom.to.equalSnapshot(); }); - it('ConfLdName should be present in IED1 and therefore ldName should be readonly', async function () { + it('ConfLdName should be present in IED1 and therefore ldName should not be readonly', async function () { ied = doc.querySelector('IED[name="IED1"]')!; services = ied.querySelector('Services')!; ldevice = ied.querySelectorAll('AccessPoint > Server > LDevice')[0]; @@ -70,6 +77,33 @@ describe('Wizards for SCL element LDevice', () => { expect(services.querySelector('ConfLdName')).to.exist; expect(inputs[0]).to.not.have.attribute('readonly'); + + describe('Modify ldName', () => { + it('should be registered as an update action', async () => { + const newValue = 'LDevice1'; + const ldeviceTextField = (inputs).find( + textField => textField.label == 'ldName' + )!; + + expect(ldeviceTextField?.value).to.be.equal(''); + await setWizardTextFieldValue(ldeviceTextField, newValue); + + const ldNameVal = getValue(inputs.find(i => i.label === 'ldName')!)!; + expect(ldNameVal).to.not.be.equal(ldevice.getAttribute('ldName')); + + const simpleAction = createUpdateAction(ldevice, { + ldName: ldNameVal, + }); + + expectUpdateAction( + simpleAction, + ldevice.tagName, + ldeviceTextField.label, + null, + newValue + ); + }); + }); }); }); });