Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
clepski committed Jul 3, 2024
1 parent 5ec2215 commit b22af86
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 8 deletions.
45 changes: 37 additions & 8 deletions packages/plugins/test/unit/wizards/ln.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,32 @@ 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';



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 = <Element>(
new DOMParser().parseFromString(
`<LN desc="LN-description" lnType="LN-type" inst="1" lnClass="LN-class" prefix="LN-prefix"></LN>`,
`<LN desc="${values.desc}" lnType="${values.lnType}" inst="${values.inst}" lnClass="${values.lnClass}" prefix="${values.prefix}"></LN>`,
'application/xml'
).documentElement
);
Expand All @@ -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(
(<WizardInputElement[]>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(
(<WizardInputElement[]>inputs).find(
(textField) => textField.label === key
)?.value
).to.equal(value);
});
});

requiredFields.forEach((field) => {
it(`is a required field ${field}`, async () => {
const input = (<WizardInputElement[]>inputs).find(
(textField) => textField.label === field
) as WizardTextField;

await setWizardTextFieldValue(input!, '');

expect(input.checkValidity()).to.be.false;
});
});
});
70 changes: 70 additions & 0 deletions packages/plugins/test/unit/wizards/ln0.test.ts
Original file line number Diff line number Diff line change
@@ -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 = <Element>(
new DOMParser().parseFromString(
`<LN0 desc="${values.desc}" lnType="${values.lnType}" inst="${values.inst}" lnClass="${values.lnClass}"></LN0>`,
'application/xml'
).documentElement
);

beforeEach(async () => {
doc = await fetchDoc('/test/testfiles/wizards/ied.scd');

element = await fixture(
html`<oscd-wizards .host=${document}></oscd-wizards>`
);
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(
(<WizardInputElement[]>inputs).find(
(textField) => textField.label === key
)?.value
).to.equal(value);
});
});

requiredFields.forEach((field) => {
it(`is a required field ${field}`, async () => {
const input = (<WizardInputElement[]>inputs).find(
(textField) => textField.label === field
) as WizardTextField;

await setWizardTextFieldValue(input!, '');

expect(input.checkValidity()).to.be.false;
});
});
});

0 comments on commit b22af86

Please sign in to comment.