Skip to content

Commit

Permalink
feat(wizards/reportcontrol): add select wizard
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakob Vogelsang committed Dec 16, 2021
1 parent d30df48 commit 0233edc
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 43 deletions.
27 changes: 27 additions & 0 deletions src/wizards/reportcontrol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
EditorAction,
getReference,
getValue,
identity,
isPublic,
SimpleAction,
Wizard,
WizardActor,
Expand Down Expand Up @@ -217,3 +219,28 @@ export function editReportControlWizard(element: Element): Wizard {
},
];
}

export function selectReportControlWizard(element: Element): Wizard {
const reportControls = Array.from(
element.querySelectorAll('ReportControl')
).filter(isPublic);

return [
{
title: get('wizard.title.select', { tagName: 'ReportControl' }),
content: [
html`<filtered-list
>${reportControls.map(
reportControl =>
html`<mwc-list-item twoline value="${identity(reportControl)}"
><span>${reportControl.getAttribute('name')}</span
><span slot="secondary"
>${identity(reportControl)}</span
></mwc-list-item
>`
)}</filtered-list
>`,
],
},
];
}
16 changes: 15 additions & 1 deletion src/zeroline-pane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ import './zeroline/substation-editor.js';
import './zeroline/ied-editor.js';
import { Settings } from './Setting.js';
import { communicationMappingWizard } from './wizards/commmap-wizards.js';
import { gooseIcon } from './icons.js';
import { gooseIcon, reportIcon } from './icons.js';
import { isPublic, newWizardEvent } from './foundation.js';
import { selectGseControlWizard } from './wizards/gsecontrol.js';
import { wizards } from './wizards/wizard-library.js';
import { getAttachedIeds } from './zeroline/foundation.js';
import { selectReportControlWizard } from './wizards/reportcontrol.js';

function shouldShowIEDs(): boolean {
return localStorage.getItem('showieds') === 'on';
Expand All @@ -47,6 +48,7 @@ export class ZerolinePane extends LitElement {
@query('#commmap') commmap!: IconButton;
@query('#showieds') showieds!: IconButtonToggle;
@query('#gsecontrol') gsecontrol!: IconButton;
@query('#reportcontrol') reportcontrol!: IconButton;
@query('#createsubstation') createsubstation!: IconButton;

openCommunicationMapping(): void {
Expand All @@ -60,6 +62,11 @@ export class ZerolinePane extends LitElement {
if (wizard) this.dispatchEvent(newWizardEvent(wizard));
}

openReportControlSelection(): void {
const wizard = selectReportControlWizard(this.doc.documentElement);
if (wizard) this.dispatchEvent(newWizardEvent(wizard));
}

openGseControlSelection(): void {
const wizard = selectGseControlWizard(this.doc.documentElement);
if (wizard) this.dispatchEvent(newWizardEvent(wizard));
Expand Down Expand Up @@ -112,6 +119,13 @@ export class ZerolinePane extends LitElement {
@click=${() => this.openCommunicationMapping()}
></mwc-icon-button>
</abbr>
<abbr title="${translate('zeroline.gsecontrol')}"
><mwc-icon-button
id="reportcontrol"
@click="${() => this.openReportControlSelection()}"
>${reportIcon}</mwc-icon-button
></abbr
>
<abbr title="${translate('zeroline.gsecontrol')}"
><mwc-icon-button
id="gsecontrol"
Expand Down
13 changes: 13 additions & 0 deletions test/integration/zeroline-pane.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@ describe('zeroline-pane wizarding editing integration', () => {
);
});

it('opens select wizard for SCL element ReportControl for the complete project', async () => {
zeroline.reportcontrol.click();
await parent.updateComplete;
expect(parent.wizardUI.dialog).to.exist;
const reportControlList = <FilteredList>(
parent.wizardUI.dialog?.querySelector('filtered-list')
);
await reportControlList.updateComplete;
expect(reportControlList.items.length).to.equal(
doc.querySelectorAll('ReportControl').length
);
});

it('add Substation element with createSubstationWizard', async () => {
expect(doc.querySelector('Substation[name="newSubstation"]')).to.not.exist;
zeroline.createsubstation.click();
Expand Down
48 changes: 7 additions & 41 deletions test/unit/__snapshots__/zeroline-pane.test.snap.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ snapshots["zeroline-pane per default looks like the latest snapshot"] =
>
</mwc-icon-button>
</abbr>
<abbr title="[zeroline.gsecontrol]">
<mwc-icon-button id="reportcontrol">
</mwc-icon-button>
</abbr>
<abbr title="[zeroline.gsecontrol]">
<mwc-icon-button id="gsecontrol">
</mwc-icon-button>
Expand All @@ -43,7 +47,7 @@ snapshots["zeroline-pane per default looks like the latest snapshot"] =
`;
/* end snapshot zeroline-pane per default looks like the latest snapshot */

snapshots["zeroline-pane readonly looks like the latest snapshot"] =
snapshots["zeroline-pane showieds looks like the latest snapshot"] =
`<h1>
<nav>
<abbr title="[add]">
Expand All @@ -59,6 +63,7 @@ snapshots["zeroline-pane readonly looks like the latest snapshot"] =
<mwc-icon-button-toggle
id="showieds"
officon="developer_board_off"
on=""
onicon="developer_board"
>
</mwc-icon-button-toggle>
Expand All @@ -71,46 +76,7 @@ snapshots["zeroline-pane readonly looks like the latest snapshot"] =
</mwc-icon-button>
</abbr>
<abbr title="[zeroline.gsecontrol]">
<mwc-icon-button id="gsecontrol">
</mwc-icon-button>
</abbr>
</nav>
</h1>
<section>
<substation-editor readonly="">
</substation-editor>
<substation-editor readonly="">
</substation-editor>
</section>
`;
/* end snapshot zeroline-pane readonly looks like the latest snapshot */

snapshots["zeroline-pane showieds looks like the latest snapshot"] =
`<h1>
<nav>
<abbr title="[add]">
<mwc-icon-button
icon="playlist_add"
id="createsubstation"
>
</mwc-icon-button>
</abbr>
</nav>
<nav>
<abbr title="[zeroline.commmap]">
<mwc-icon-button-toggle
id="showieds"
officon="developer_board_off"
on=""
onicon="developer_board"
>
</mwc-icon-button-toggle>
</abbr>
<abbr title="[zeroline.commmap]">
<mwc-icon-button
icon="link"
id="commmap"
>
<mwc-icon-button id="reportcontrol">
</mwc-icon-button>
</abbr>
<abbr title="[zeroline.gsecontrol]">
Expand Down
63 changes: 63 additions & 0 deletions test/unit/wizards/__snapshots__/reportcontrol.test.snap.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,66 @@ snapshots["Wizards for SCL ReportControl element define an edit wizard that look
`;
/* end snapshot Wizards for SCL ReportControl element define an edit wizard that looks like the latest snapshot */

snapshots["Wizards for SCL ReportControl element define a select wizard that looks like the latest snapshot"] =
`<mwc-dialog
defaultaction="close"
heading="[wizard.title.select]"
open=""
>
<div id="wizard-content">
<filtered-list>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
tabindex="0"
twoline=""
value="IED2>>CBSW>ReportCb"
>
<span>
ReportCb
</span>
<span slot="secondary">
IED2>>CBSW>ReportCb
</span>
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
tabindex="-1"
twoline=""
value="IED2>>CBSW> XSWI 1>ReportCb2"
>
<span>
ReportCb2
</span>
<span slot="secondary">
IED2>>CBSW> XSWI 1>ReportCb2
</span>
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
tabindex="-1"
twoline=""
value="IED2>>CBSW> XSWI 2>ReportCb3"
>
<span>
ReportCb3
</span>
<span slot="secondary">
IED2>>CBSW> XSWI 2>ReportCb3
</span>
</mwc-list-item>
</filtered-list>
</div>
<mwc-button
dialogaction="close"
label="[cancel]"
slot="secondaryAction"
style="--mdc-theme-primary: var(--mdc-theme-error)"
>
</mwc-button>
</mwc-dialog>
`;
/* end snapshot Wizards for SCL ReportControl element define a select wizard that looks like the latest snapshot */

19 changes: 18 additions & 1 deletion test/unit/wizards/reportcontrol.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import {
WizardInput,
} from '../../../src/foundation.js';
import { WizardTextField } from '../../../src/wizard-textfield.js';
import { editReportControlWizard } from '../../../src/wizards/reportcontrol.js';
import {
editReportControlWizard,
selectReportControlWizard,
} from '../../../src/wizards/reportcontrol.js';
import { inverseRegExp, regExp, regexString } from '../../foundation.js';

describe('Wizards for SCL ReportControl element', () => {
Expand Down Expand Up @@ -311,4 +314,18 @@ describe('Wizards for SCL ReportControl element', () => {
});
});
});

describe('define a select wizard that', () => {
beforeEach(async () => {
const wizard = selectReportControlWizard(doc.documentElement);
element.workflow.push(wizard);
await element.requestUpdate();

await element.wizardUI.requestUpdate(); // make sure wizard is rendered
});

it('looks like the latest snapshot', async () => {
await expect(element.wizardUI.dialog).dom.to.equalSnapshot();
}).timeout(5000);
});
});

0 comments on commit 0233edc

Please sign in to comment.