Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .github/workflows/pr-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ jobs:
- name: Build (PR Preview)
run: npm run build:preview

- name: Prepare preview directory
run: |
cp -r dist preview/
rsync -av --exclude='plugins.js' demo/ preview/
sed -i "s|../dist/bay-template-editor.js|./bay-template-editor.js|g" preview/plugins.js

- name: Deploy preview
uses: rossjrw/pr-preview-action@ffa7509e91a3ec8dfc2e5536c4d5c1acdf7a6de9 #v1
with:
Expand Down
112 changes: 8 additions & 104 deletions bay-template-editor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -665,99 +665,6 @@ describe('Bay Template Editor Plugin', () => {
});
});

describe('preprocessEdits method', () => {
it('assigns unique names to elements without names when inserted', async () => {
const doc = new DOMParser().parseFromString(
docWithBay,
'application/xml'
);
element.doc = doc;
await element.updateComplete;

const bay = doc.querySelector('Bay')!;
const newEquipment = doc.createElementNS(
doc.documentElement.namespaceURI,
'ConductingEquipment'
);
newEquipment.setAttribute('type', 'CBR');

const editEvent = new CustomEvent('oscd-edit-v2', {
detail: {
node: newEquipment,
parent: bay,
reference: null,
},
bubbles: true,
composed: true,
});

element.dispatchEvent(editEvent);

expect(newEquipment.getAttribute('name')).to.equal('CBR1');
});

it('preserves existing names on elements', async () => {
const doc = new DOMParser().parseFromString(
docWithBay,
'application/xml'
);
element.doc = doc;
await element.updateComplete;

const bay = doc.querySelector('Bay')!;
const newEquipment = doc.createElementNS(
doc.documentElement.namespaceURI,
'ConductingEquipment'
);
newEquipment.setAttribute('type', 'CBR');
newEquipment.setAttribute('name', 'MyCustomName');

const editEvent = new CustomEvent('oscd-edit-v2', {
detail: {
node: newEquipment,
parent: bay,
},
});

element.dispatchEvent(editEvent);

expect(newEquipment.getAttribute('name')).to.equal('MyCustomName');
});

it('handles SLD attributes in edits', async () => {
const doc = new DOMParser().parseFromString(
docWithBay,
'application/xml'
);
element.doc = doc;
await element.updateComplete;

const testElement = doc.createElementNS(
doc.documentElement.namespaceURI,
'Bay'
);

const editEvent = new CustomEvent('oscd-edit-v2', {
detail: {
element: testElement,
attributesNS: {
'https://openscd.org/SCL/SSD/SLD/v0': {
w: '10',
h: '20',
},
},
},
});

element.dispatchEvent(editEvent);

const sldAttrs = testElement.querySelector(
'Private[type="OpenSCD-SLD-Layout"] > SLDAttributes'
);
expect(sldAttrs).to.exist;
});
});

describe('function placement', () => {
it('starts placing function when handleStartPlaceFunction is called', async () => {
const doc = new DOMParser().parseFromString(
Expand Down Expand Up @@ -801,31 +708,28 @@ describe('Bay Template Editor Plugin', () => {
expect(element.functionsInAction).to.be.false;
});

it('resets placing function after edit event', async () => {
it('resets placing function when functions-layer calls onDonePlaceFunction', async () => {
const doc = new DOMParser().parseFromString(
docWithBay,
'application/xml'
);
element.doc = doc;
element.showFunctions = true;
await element.updateComplete;

const functionElement = doc.createElement('Function');
element.placingFunction = functionElement;
element.functionsInAction = true;
await element.updateComplete;

const editEvent = new CustomEvent('oscd-edit-v2', {
bubbles: true,
composed: true,
detail: {
parent: doc.querySelector('Bay'),
node: functionElement,
},
});

element.dispatchEvent(editEvent);
const functionsLayer = element.shadowRoot?.querySelector(
'functions-layer'
) as any;
functionsLayer.onDonePlaceFunction();
await element.updateComplete;

expect(element.placingFunction).to.be.undefined;
expect(element.functionsInAction).to.be.false;
});
});

Expand Down
Loading
Loading