-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(wizards/subfunction): add create wizard (#733)
* feat(wizards/subfunction): add create wizard * feat(editors/substation/sub-function-editor): add add button
- Loading branch information
1 parent
5663acb
commit f154ae1
Showing
13 changed files
with
707 additions
and
10 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
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 createSubFunctionAction(parent: Element): WizardActor { | ||
return (inputs: WizardInputElement[]) => { | ||
const subFunctionAttrs: Record<string, string | null> = {}; | ||
const subFunctionKeys = ['name', 'desc', 'type']; | ||
subFunctionKeys.forEach(key => { | ||
subFunctionAttrs[key] = getValue(inputs.find(i => i.label === key)!); | ||
}); | ||
|
||
const subFunction = createElement( | ||
parent.ownerDocument, | ||
'SubFunction', | ||
subFunctionAttrs | ||
); | ||
|
||
return [{ new: { parent, element: subFunction } }]; | ||
}; | ||
} | ||
|
||
export function createSubFunctionWizard(parent: Element): Wizard { | ||
const name = ''; | ||
const desc = null; | ||
const type = null; | ||
const reservedNames = Array.from(parent.querySelectorAll('SubFunction')).map( | ||
fUnction => fUnction.getAttribute('name')! | ||
); | ||
|
||
return [ | ||
{ | ||
title: get('wizard.title.add', { tagName: 'SubFunction' }), | ||
primary: { | ||
icon: 'save', | ||
label: get('save'), | ||
action: createSubFunctionAction(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
87 changes: 87 additions & 0 deletions
87
test/integration/editors/substation/function-editor.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,87 @@ | ||
import { fixture, html, expect } from '@open-wc/testing'; | ||
|
||
import '../../../mock-wizard-editor.js'; | ||
import { MockWizardEditor } from '../../../mock-wizard-editor.js'; | ||
|
||
import '../../../../src/editors/substation/function-editor.js'; | ||
import { FunctionEditor } from '../../../../src/editors/substation/function-editor.js'; | ||
import { WizardTextField } from '../../../../src/wizard-textfield.js'; | ||
|
||
describe('function-editor wizarding editing integration', () => { | ||
describe('open create wizard for element SubFunction', () => { | ||
let doc: XMLDocument; | ||
let parent: MockWizardEditor; | ||
let element: FunctionEditor | 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 | ||
><function-editor | ||
.element=${doc.querySelector('Function')} | ||
></function-editor | ||
></mock-wizard-editor>` | ||
) | ||
); | ||
|
||
element = parent.querySelector('function-editor'); | ||
|
||
(<HTMLElement>( | ||
element?.shadowRoot?.querySelector('mwc-list-item[value="SubFunction"]') | ||
)).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 SubFunction if name attribute is not unique', async () => { | ||
expect( | ||
doc.querySelector( | ||
'Substation > Function > SubFunction[name="mySubFunc"]' | ||
) | ||
).to.exist; | ||
|
||
nameField.value = 'mySubFunc'; | ||
primaryAction.click(); | ||
await parent.updateComplete; | ||
|
||
expect( | ||
doc.querySelectorAll( | ||
'Substation > Function > SubFunction[name="mySubFunc"]' | ||
).length | ||
).to.equal(1); | ||
}); | ||
|
||
it('does add SubFunction if name attribute is unique', async () => { | ||
expect( | ||
doc.querySelector( | ||
'Substation > Function > SubFunction[name="someNewFunction"]' | ||
) | ||
).to.not.exist; | ||
|
||
nameField.value = 'someNewFunction'; | ||
await parent.updateComplete; | ||
primaryAction.click(); | ||
|
||
expect( | ||
doc.querySelector( | ||
'Substation > Function > SubFunction[name="someNewFunction"]' | ||
) | ||
).to.exist; | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.