-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(wizards/eqsubfunction): add create wizard (#757)
- Loading branch information
1 parent
322305a
commit 64bf40a
Showing
10 changed files
with
664 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { get } from 'lit-translate'; | ||
|
||
import { | ||
createElement, | ||
getValue, | ||
Wizard, | ||
WizardActor, | ||
WizardInputElement, | ||
} from '../foundation.js'; | ||
import { contentFunctionWizard } from './function.js'; | ||
|
||
function createEqSubFunctionAction(parent: Element): WizardActor { | ||
return (inputs: WizardInputElement[]) => { | ||
const eqSubFunctionAttrs: Record<string, string | null> = {}; | ||
const eqSubFunctionKeys = ['name', 'desc', 'type']; | ||
eqSubFunctionKeys.forEach(key => { | ||
eqSubFunctionAttrs[key] = getValue(inputs.find(i => i.label === key)!); | ||
}); | ||
|
||
const eqSubFunction = createElement( | ||
parent.ownerDocument, | ||
'EqSubFunction', | ||
eqSubFunctionAttrs | ||
); | ||
|
||
return [{ new: { parent, element: eqSubFunction } }]; | ||
}; | ||
} | ||
|
||
export function createEqSubFunctionWizard(parent: Element): Wizard { | ||
const name = ''; | ||
const desc = null; | ||
const type = null; | ||
const reservedNames = Array.from( | ||
parent.querySelectorAll('EqSubFunction') | ||
).map(eqSubFunction => eqSubFunction.getAttribute('name')!); | ||
|
||
return [ | ||
{ | ||
title: get('wizard.title.add', { tagName: 'EqSubFunction' }), | ||
primary: { | ||
icon: 'save', | ||
label: get('save'), | ||
action: createEqSubFunctionAction(parent), | ||
}, | ||
content: [ | ||
...contentFunctionWizard({ | ||
name, | ||
desc, | ||
type, | ||
reservedNames, | ||
}), | ||
], | ||
}, | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
test/integration/editors/substation/eq-function-wizarding-editing.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { fixture, html, expect } from '@open-wc/testing'; | ||
|
||
import '../../../mock-wizard-editor.js'; | ||
import { MockWizardEditor } from '../../../mock-wizard-editor.js'; | ||
|
||
import '../../../../src/editors/substation/eq-function-editor.js'; | ||
import { EqFunctionEditor } from '../../../../src/editors/substation/eq-function-editor.js'; | ||
import { WizardTextField } from '../../../../src/wizard-textfield.js'; | ||
|
||
describe('eq-function-editor wizarding editing integration', () => { | ||
describe('open create wizard for element EqSubFunction', () => { | ||
let doc: XMLDocument; | ||
let parent: MockWizardEditor; | ||
let element: EqFunctionEditor | null; | ||
|
||
let nameField: WizardTextField; | ||
let primaryAction: HTMLElement; | ||
|
||
beforeEach(async () => { | ||
doc = await fetch('/test/testfiles/zeroline/functions.scd') | ||
.then(response => response.text()) | ||
.then(str => new DOMParser().parseFromString(str, 'application/xml')); | ||
parent = <MockWizardEditor>( | ||
await fixture( | ||
html`<mock-wizard-editor | ||
><eq-function-editor | ||
.element=${doc.querySelector( | ||
'ConductingEquipment[name="QA1"] > EqFunction' | ||
)} | ||
></eq-function-editor | ||
></mock-wizard-editor>` | ||
) | ||
); | ||
|
||
element = parent.querySelector('eq-function-editor'); | ||
|
||
(<HTMLElement>( | ||
element?.shadowRoot?.querySelector( | ||
'mwc-list-item[value="EqSubFunction"]' | ||
) | ||
)).click(); | ||
await parent.updateComplete; | ||
|
||
nameField = <WizardTextField>( | ||
parent.wizardUI.dialog?.querySelector('wizard-textfield[label="name"]') | ||
); | ||
|
||
primaryAction = <HTMLElement>( | ||
parent.wizardUI.dialog?.querySelector( | ||
'mwc-button[slot="primaryAction"]' | ||
) | ||
); | ||
}); | ||
|
||
it('does not add EqSubFunction if name attribute is not unique', async () => { | ||
expect( | ||
doc.querySelector( | ||
'ConductingEquipment[name="QA1"] EqSubFunction[name="myEqSubFunc"]' | ||
) | ||
).to.exist; | ||
|
||
nameField.value = 'myEqSubFunc'; | ||
primaryAction.click(); | ||
await parent.updateComplete; | ||
|
||
expect( | ||
doc.querySelectorAll( | ||
'ConductingEquipment[name="QA1"] EqSubFunction[name="myEqSubFunc"]' | ||
).length | ||
).to.equal(1); | ||
}); | ||
|
||
it('does add EqFunction if name attribute is unique', async () => { | ||
expect( | ||
doc.querySelector( | ||
'ConductingEquipment[name="QA1"] EqSubFunction[name="someNewEqSubFunction"]' | ||
) | ||
).to.not.exist; | ||
|
||
nameField.value = 'someNewEqSubFunction'; | ||
await parent.updateComplete; | ||
primaryAction.click(); | ||
|
||
expect( | ||
doc.querySelector( | ||
'ConductingEquipment[name="QA1"] EqSubFunction[name="someNewEqSubFunction"]' | ||
) | ||
).to.exist; | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.