Skip to content

Commit

Permalink
tests for sld-editor
Browse files Browse the repository at this point in the history
  • Loading branch information
omicron tester committed Mar 19, 2024
1 parent 72f4902 commit bb86b47
Show file tree
Hide file tree
Showing 2 changed files with 341 additions and 1 deletion.
337 changes: 336 additions & 1 deletion oscd-designer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -682,13 +682,348 @@ describe('Designer', () => {
.to.have.property('tagName', 'ConductingEquipment');
await sendMouse({ type: 'click', position: [150, 180] });
expect(element).to.have.property('placing', undefined);
expect(element).to.have.property('resizing', undefined);
const equipment = element.doc.querySelector('ConductingEquipment');
expect(equipment).to.exist;
expect(equipment).to.have.attribute('x', '3');
expect(equipment).to.have.attribute('y', '3');
});

it('allows placing new power transformer equipment (single-winding, auto, within the bay)', async () => {
element
.shadowRoot!.querySelector<Button>(
'[label="Add Single Winding Auto Transformer"]'
)
?.click();
expect(element)
.property('placing')
.to.have.property('tagName', 'PowerTransformer');
await sendMouse({ type: 'click', position: [150, 180] });
expect(element).to.have.property('placing', undefined);
const equipment = element.doc.querySelector('PowerTransformer');
expect(equipment).to.exist;
expect(equipment).to.have.attribute('x', '3');
expect(equipment).to.have.attribute('y', '3');
expect(equipment).to.have.attribute('kind', 'auto');
expect(equipment?.parentElement).to.have.property('tagName', 'Bay');
expect(equipment?.children.length).eq(1);
});

it('allows placing new power transformer equipment (single-winding, auto, within the voltage level)', async () => {
element
.shadowRoot!.querySelector<Button>(
'[label="Add Single Winding Auto Transformer"]'
)
?.click();
expect(element)
.property('placing')
.to.have.property('tagName', 'PowerTransformer');
await sendMouse({ type: 'click', position: [300, 300] });
expect(element).to.have.property('placing', undefined);
const equipment = element.doc.querySelector('PowerTransformer');
expect(equipment).to.exist;

expect(equipment?.parentElement).to.have.property(
'tagName',
'VoltageLevel'
);
});

it('allows placing new power transformer equipment (single-winding, auto, within the substation)', async () => {
element
.shadowRoot!.querySelector<Button>(
'[label="Add Single Winding Auto Transformer"]'
)
?.click();
expect(element)
.property('placing')
.to.have.property('tagName', 'PowerTransformer');
await sendMouse({ type: 'click', position: [50, 300] });
expect(element).to.have.property('placing', undefined);
const equipment = element.doc.querySelector('PowerTransformer');
expect(equipment).to.exist;

expect(equipment?.parentElement).to.have.property(
'tagName',
'Substation'
);
});

it('allows placing new power transformer equipment (two-winding. auto)', async () => {
element
.shadowRoot!.querySelector<Button>(
'[label="Add Two Winding Auto Transformer"]'
)
?.click();
expect(element)
.property('placing')
.to.have.property('tagName', 'PowerTransformer');
await sendMouse({ type: 'click', position: [150, 180] });
expect(element).to.have.property('placing', undefined);
const equipment = element.doc.querySelector('PowerTransformer');
expect(equipment).to.exist;
expect(equipment).to.have.attribute('x', '3');
expect(equipment).to.have.attribute('y', '3');
expect(equipment).to.have.attribute('kind', 'auto');
expect(equipment?.children.length).eq(2);
});

it('allows placing new power transformer equipment (single-winding, earthing)', async () => {
element
.shadowRoot!.querySelector<Button>(
'[label="Add Single Winding Earthing Transformer"]'
)
?.click();
expect(element)
.property('placing')
.to.have.property('tagName', 'PowerTransformer');
await sendMouse({ type: 'click', position: [150, 180] });
expect(element).to.have.property('placing', undefined);
const equipment = element.doc.querySelector('PowerTransformer');
expect(equipment).to.exist;
expect(equipment).to.have.attribute('x', '3');
expect(equipment).to.have.attribute('y', '3');
expect(equipment).to.have.attribute('kind', 'earthing');
expect(equipment?.children.length).eq(1);
});

it('allows placing new power transformer equipment (two-winding. earthing)', async () => {
element
.shadowRoot!.querySelector<Button>(
'[label="Add Two Winding Earthing Transformer"]'
)
?.click();
expect(element)
.property('placing')
.to.have.property('tagName', 'PowerTransformer');
await sendMouse({ type: 'click', position: [150, 180] });
expect(element).to.have.property('placing', undefined);
const equipment = element.doc.querySelector('PowerTransformer');
expect(equipment).to.exist;
expect(equipment).to.have.attribute('x', '3');
expect(equipment).to.have.attribute('y', '3');
expect(equipment).to.have.attribute('kind', 'earthing');
expect(equipment?.children.length).eq(2);
});

it('allows placing new power transformer equipment (three-winding)', async () => {
element
.shadowRoot!.querySelector<Button>(
'[label="Add Three Winding Transformer"]'
)
?.click();
expect(element)
.property('placing')
.to.have.property('tagName', 'PowerTransformer');
await sendMouse({ type: 'click', position: [150, 180] });
expect(element).to.have.property('placing', undefined);
const equipment = element.doc.querySelector('PowerTransformer');
expect(equipment).to.exist;
expect(equipment).to.have.attribute('x', '3');
expect(equipment).to.have.attribute('y', '3');
expect(equipment).to.not.have.attribute('kind');
expect(equipment?.children).to.have.lengthOf(3);
});

it('allows placing new power transformer equipment (two-winding)', async () => {
element
.shadowRoot!.querySelector<Button>(
'[label="Add Two Winding Transformer"]'
)
?.click();
expect(element)
.property('placing')
.to.have.property('tagName', 'PowerTransformer');
await sendMouse({ type: 'click', position: [150, 180] });
expect(element).to.have.property('placing', undefined);
const equipment = element.doc.querySelector('PowerTransformer');
expect(equipment).to.exist;
expect(equipment).to.have.attribute('x', '3');
expect(equipment).to.have.attribute('y', '3');
expect(equipment).to.not.have.attribute('kind');
expect(equipment?.children).to.have.lengthOf(2);
});

describe('with a two-winding power transformer', () => {
beforeEach(async () => {
element
.shadowRoot!.querySelector<Button>(
'[label="Add Two Winding Transformer"]'
)
?.click();
await sendMouse({ type: 'click', position: [150, 180] });
await element.updateComplete;
});

it('opens a menu on a two-winding power transformer with a right click', async () => {
await sendMouse({
type: 'click',
button: 'right',
position: middleOf(
queryUI({
scl: 'PowerTransformer',
})
),
});

await element.updateComplete;
expect(queryUI({ ui: 'menu' })).to.exist;
});

it('menu-item delete: deletes PowerTransformer', async () => {
const equipment = element.doc.querySelector('PowerTransformer');

const sldEditor =
element.shadowRoot!.querySelector<SLDEditor>('sld-editor')!;

expect(equipment).to.exist;

await sendMouse({
type: 'click',
button: 'right',
position: middleOf(
queryUI({
scl: 'PowerTransformer',
})
),
});

await element.updateComplete;

sldEditor.shadowRoot!.querySelector<ListItem>(
'mwc-list-item:nth-last-of-type(1)'
)!.selected = true;
await element.updateComplete;

expect(equipment?.parentElement).to.be.null;
expect(element.doc.querySelector('PowerTransformer')).to.not.exist;
});

it('opens edit wizard on menut-item-edit click', async () => {
await sendMouse({
type: 'click',
button: 'right',
position: middleOf(
queryUI({
scl: 'PowerTransformer',
})
),
});

const sldEditor =
element.shadowRoot!.querySelector<SLDEditor>('sld-editor')!;
await element.updateComplete;

sldEditor.shadowRoot!.querySelector<ListItem>(
'mwc-list-item:nth-last-of-type(2)'
)!.selected = true;
await sldEditor.updateComplete;
expect(lastCalledWizard).to.equal(
element.doc.querySelector('PowerTransformer')
);
});

it('opens edit wizard for different windings on menut-item-edit click, Winding = W1', async () => {
await sendMouse({
type: 'click',
button: 'right',
position: middleOf(
queryUI({
scl: 'TransformerWinding[name=W1]',
})
),
});

const sldEditor =
element.shadowRoot!.querySelector<SLDEditor>('sld-editor')!;
await element.updateComplete;

sldEditor.shadowRoot!.querySelector<ListItem>(
'mwc-list-item:nth-of-type(3)'
)!.selected = true;
await sldEditor.updateComplete;

expect(lastCalledWizard).to.equal(
element.doc.querySelector('TransformerWinding[name=W1]')
);
});

it('opens edit wizard for different windings on menu-item-edit click, Winding = W2', async () => {
await sendMouse({
type: 'click',
button: 'right',
position: middleOf(
queryUI({
scl: 'TransformerWinding[name=W2]',
})
),
});

const sldEditor =
element.shadowRoot!.querySelector<SLDEditor>('sld-editor')!;
await element.updateComplete;

sldEditor.shadowRoot!.querySelector<ListItem>(
'mwc-list-item:nth-of-type(3)'
)!.selected = true;
await sldEditor.updateComplete;

expect(lastCalledWizard).to.equal(
element.doc.querySelector('TransformerWinding[name=W2]')
);
});

it('rotates PowerTransformer on menu-item-rotate click', async () => {
await sendMouse({
type: 'click',
button: 'right',
position: middleOf(
queryUI({
scl: 'TransformerWinding',
})
),
});

const sldEditor =
element.shadowRoot!.querySelector<SLDEditor>('sld-editor')!;
await element.updateComplete;

sldEditor.shadowRoot!.querySelector<ListItem>(
'mwc-list-item:nth-last-of-type(6)'
)!.selected = true;
await sldEditor.updateComplete;

const equipment = element.doc.querySelector('PowerTransformer');
expect(equipment).to.have.attribute('esld:rot', '1');
});

it('copies PowerTransformer on menu-item-copy click', async () => {
await sendMouse({
type: 'click',
button: 'right',
position: middleOf(
queryUI({
scl: 'TransformerWinding',
})
),
});

const sldEditor =
element.shadowRoot!.querySelector<SLDEditor>('sld-editor')!;
await element.updateComplete;

sldEditor.shadowRoot!.querySelector<ListItem>(
'mwc-list-item:nth-last-of-type(5)'
)!.selected = true;
await sldEditor.updateComplete;

await sendMouse({ type: 'click', position: [200, 180] });
await element.updateComplete;

const equipment = element.doc.querySelectorAll('PowerTransformer');
expect(equipment.length).eq(2);
});
});

describe('with a sibling bus bar', () => {
beforeEach(async () => {
element
Expand Down
5 changes: 5 additions & 0 deletions sld-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2023,7 +2023,10 @@ export class SLDEditor extends LitElement {
}"
stroke="black" stroke-width="0.06" marker-end="url(#arrow)" />`
: nothing;

const id = winding.closest('Substation') ? identity(winding) : nothing;
return svg`<g class="winding"
id="${id}"
@contextmenu=${(e: MouseEvent) => this.openMenu(winding, e)}
><circle cx="${cx}" cy="${cy}" r="${size}" stroke="black" stroke-width="0.06" />${arcPath}${ltcArrow}${ports}</g>`;
}
Expand All @@ -2036,8 +2039,10 @@ export class SLDEditor extends LitElement {
const windings = Array.from(transformer.children).filter(
c => c.tagName === 'TransformerWinding'
);
const id = transformer.parentElement ? identity(transformer) : nothing;
const [x, y] = this.renderedPosition(transformer);
return svg`<g class="${classMap({ transformer: true, preview })}"
id="${id}"
pointer-events="all"
@mousedown=${preventDefault}
@auxclick=${(e: MouseEvent) => {
Expand Down

0 comments on commit bb86b47

Please sign in to comment.