From b22af864c233e84af78483feae57d02deecced40 Mon Sep 17 00:00:00 2001 From: Christopher Lepski Date: Wed, 3 Jul 2024 15:38:23 +0200 Subject: [PATCH] Add more tests --- packages/plugins/test/unit/wizards/ln.test.ts | 45 +++++++++--- .../plugins/test/unit/wizards/ln0.test.ts | 70 +++++++++++++++++++ 2 files changed, 107 insertions(+), 8 deletions(-) create mode 100644 packages/plugins/test/unit/wizards/ln0.test.ts diff --git a/packages/plugins/test/unit/wizards/ln.test.ts b/packages/plugins/test/unit/wizards/ln.test.ts index 13f6e773a..a28c41592 100644 --- a/packages/plugins/test/unit/wizards/ln.test.ts +++ b/packages/plugins/test/unit/wizards/ln.test.ts @@ -4,7 +4,8 @@ import { OscdWizards } from '@openscd/open-scd/src/addons/Wizards'; import { editLNWizard } from '../../../src/wizards/ln.js'; import { WizardInputElement } from '@openscd/open-scd/src/foundation.js'; -import { fetchDoc } from './test-support.js'; +import { fetchDoc, setWizardTextFieldValue } from './test-support.js'; +import { WizardTextField } from '@openscd/open-scd/src/wizard-textfield.js'; @@ -12,9 +13,23 @@ describe('ln wizards', () => { let doc: XMLDocument; let element: OscdWizards; let inputs: WizardInputElement[]; + + const values = { + lnType: 'LN-type', + desc: 'LN-description', + prefix: 'LN-prefix', + lnClass: 'LN-class', + inst: '1', + }; + const requiredFields = [ + 'lnType', + 'lnClass', + 'inst', + ]; + const ln = ( new DOMParser().parseFromString( - ``, + ``, 'application/xml' ).documentElement ); @@ -32,11 +47,25 @@ describe('ln wizards', () => { inputs = Array.from(element.wizardUI.inputs); }); - it('contains a wizard-textfield with a non-empty "lnType" value', async () => { - expect( - (inputs).find( - (textField) => textField.label === 'lnType' - )?.value - ).to.equal('LN-type'); + Object.entries(values).forEach(([key, value]) => { + it(`contains a wizard-textfield with a non-empty "${key}" value`, async () => { + expect( + (inputs).find( + (textField) => textField.label === key + )?.value + ).to.equal(value); + }); + }); + + requiredFields.forEach((field) => { + it(`is a required field ${field}`, async () => { + const input = (inputs).find( + (textField) => textField.label === field + ) as WizardTextField; + + await setWizardTextFieldValue(input!, ''); + + expect(input.checkValidity()).to.be.false; + }); }); }); diff --git a/packages/plugins/test/unit/wizards/ln0.test.ts b/packages/plugins/test/unit/wizards/ln0.test.ts new file mode 100644 index 000000000..79545f271 --- /dev/null +++ b/packages/plugins/test/unit/wizards/ln0.test.ts @@ -0,0 +1,70 @@ +import { expect, fixture, html } from '@open-wc/testing'; +import '@openscd/open-scd/src/addons/Wizards.js'; +import { OscdWizards } from '@openscd/open-scd/src/addons/Wizards'; + +import { editLN0Wizard } from '../../../src/wizards/ln0.js'; +import { WizardInputElement } from '@openscd/open-scd/src/foundation.js'; +import { fetchDoc, setWizardTextFieldValue } from './test-support.js'; +import { WizardTextField } from '@openscd/open-scd/src/wizard-textfield.js'; + + + +describe('ln0 wizards', () => { + let doc: XMLDocument; + let element: OscdWizards; + let inputs: WizardInputElement[]; + + const values = { + lnType: 'LN0-type', + desc: 'LN0-description', + lnClass: 'LN0-class', + inst: '1', + }; + const requiredFields = [ + 'lnType', + 'lnClass', + 'inst', + ]; + + const ln = ( + new DOMParser().parseFromString( + ``, + 'application/xml' + ).documentElement + ); + + beforeEach(async () => { + doc = await fetchDoc('/test/testfiles/wizards/ied.scd'); + + element = await fixture( + html`` + ); + const wizard = editLN0Wizard(ln); + + element.workflow.push(() => wizard); + await element.requestUpdate(); + inputs = Array.from(element.wizardUI.inputs); + }); + + Object.entries(values).forEach(([key, value]) => { + it(`contains a wizard-textfield with a non-empty "${key}" value`, async () => { + expect( + (inputs).find( + (textField) => textField.label === key + )?.value + ).to.equal(value); + }); + }); + + requiredFields.forEach((field) => { + it(`is a required field ${field}`, async () => { + const input = (inputs).find( + (textField) => textField.label === field + ) as WizardTextField; + + await setWizardTextFieldValue(input!, ''); + + expect(input.checkValidity()).to.be.false; + }); + }); +});