Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: edit multiple files #22

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
20 changes: 20 additions & 0 deletions localization/de.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,26 @@
<source>Your editing history will be displayed here.</source>
<target>Hier wird Ihre Bearbeitungshistorie angezeigt.</target>
</trans-unit>
<trans-unit id="s690714fde574c188">
<source>Filename</source>
<target>Dateiname</target>
</trans-unit>
<trans-unit id="s1b528387ae29637a">
<source>Extension</source>
<target>Dateiendung</target>
</trans-unit>
<trans-unit id="s737e3dbdf9c08cdf">
<source>Close file</source>
<target>Datei schließen</target>
</trans-unit>
<trans-unit id="s2ceb11be2290bb1b">
<source>Cancel</source>
<target>Abbrechen</target>
</trans-unit>
<trans-unit id="s60320a18282b2b33">
<source>Rename</source>
<target>Umbenennen</target>
</trans-unit>
<trans-unit id="s5e8250fb85d64c23">
<source>Close</source>
<target>Schließen</target>
Expand Down
75 changes: 72 additions & 3 deletions open-scd.editing.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export namespace util {
<SCL version="2007" revision="B" xmlns="http://www.iec.ch/61850/2003/SCL">
<Substation name="A1" desc="test substation"></Substation>
</SCL>`;
const testDocStrings = [
export const testDocStrings = [
sclDocString,
`<?xml version="1.0" encoding="UTF-8"?>
<testDoc1>
Expand Down Expand Up @@ -187,7 +187,13 @@ export namespace util {
}
}

describe('Editing Element', () => {
function newTestDoc() {
const docString =
util.testDocStrings[Math.floor(Math.random() * util.testDocStrings.length)];
return new DOMParser().parseFromString(docString, 'application/xml');
}

describe('open-scd', () => {
let editor: OpenSCD;
let sclDoc: XMLDocument;

Expand All @@ -199,13 +205,76 @@ describe('Editing Element', () => {
);
});

it('loads a document on OpenDocEvent', async () => {
it('loads a non-SCL document on OpenDocEvent', async () => {
editor.dispatchEvent(newOpenEvent(sclDoc, 'test.xml'));
await editor.updateComplete;
expect(editor.docs).to.have.property('test.xml', sclDoc);
});

it('opens an SCL document for editing on OpenDocEvent', async () => {
editor.dispatchEvent(newOpenEvent(sclDoc, 'test.scd'));
await editor.updateComplete;
expect(editor.doc).to.equal(sclDoc);
expect(editor.docName).to.equal('test.scd');
});

describe('with an SCL document loaded', () => {
beforeEach(async () => {
editor.dispatchEvent(newOpenEvent(sclDoc, 'test.scd'));
await editor.updateComplete;
});

it('allows the user to change the current doc name', async () => {
editor.shadowRoot
?.querySelector<HTMLButtonElement>('mwc-icon-button[icon=edit]')
?.click();
const dialog = editor.editFileUI;
await dialog.updateComplete;
const textfield = dialog.querySelector('mwc-textfield')!;
textfield.value = 'newName';
const select = dialog.querySelector('mwc-select')!;
select.value = 'cid';
await textfield.updateComplete;
await select.updateComplete;
dialog
.querySelector<HTMLButtonElement>('mwc-button[slot="primaryAction"]')
?.click();
await editor.updateComplete;
expect(editor).to.have.property('docName', 'newName.cid');
expect(editor).to.have.property('doc', sclDoc);
});
});

it('allows the user to close the current doc', async () => {
editor.shadowRoot
?.querySelector<HTMLButtonElement>('mwc-icon-button[icon=edit]')
?.click();
const dialog = editor.editFileUI;
await dialog.updateComplete;
dialog
.querySelector<HTMLButtonElement>('mwc-button[icon="delete"]')
?.click();
await editor.updateComplete;
expect(editor).to.have.property('docName');
expect(editor).to.have.property('doc');
});

describe('with several documents loaded', () => {
beforeEach(async () => {
for (let i = 0; i < Math.floor(Math.random() * 10) + 1; i += 1)
editor.dispatchEvent(newOpenEvent(newTestDoc(), `test${i}.scd`));
});

it('allows the user to switch documents', async () => {
const oldDocName = editor.docName;
editor.fileMenuButtonUI?.click();
await editor.fileMenuUI.updateComplete;
(editor.fileMenuUI.firstElementChild as HTMLButtonElement).click();
await editor.updateComplete;
expect(editor).to.not.have.property('docName', oldDocName);
});
});

it('inserts an element on Insert', () => {
const parent = sclDoc.documentElement;
const node = sclDoc.createElement('test');
Expand Down
32 changes: 16 additions & 16 deletions open-scd.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,31 +48,31 @@ describe('with editor plugins loaded', () => {
});

it('passes attribute docname', async () => {
editor.dispatchEvent(newOpenEvent(doc, 'test.xml'));
editor.dispatchEvent(newOpenEvent(doc, 'test.scd'));
await editor.updateComplete;

const plugin = editor.shadowRoot?.querySelector('*[docName="test.xml"]');
const plugin = editor.shadowRoot?.querySelector('*[docName="test.scd"]');
expect(plugin?.tagName).to.exist.and.to.satisfy(isOscdPlugin);
});

it('passes property doc', async () => {
editor.dispatchEvent(newOpenEvent(doc, 'test.xml'));
editor.dispatchEvent(newOpenEvent(doc, 'test.scd'));
await editor.updateComplete;

const plugin = editor.shadowRoot?.querySelector('*[docname="test.xml"]');
const plugin = editor.shadowRoot?.querySelector('*[docname="test.scd"]');
expect(plugin).to.have.property('docs');
});

it('passes property editCount', async () => {
editor.dispatchEvent(newOpenEvent(doc, 'test.xml'));
editor.dispatchEvent(newOpenEvent(doc, 'test.scd'));
await editor.updateComplete;

const plugin = editor.shadowRoot?.querySelector('*[docname="test.xml"]');
const plugin = editor.shadowRoot?.querySelector('*[docname="test.scd"]');
expect(plugin).to.have.property('editCount', 0);
});

it('updated passed editCount property on edit events', async () => {
editor.dispatchEvent(newOpenEvent(doc, 'test.xml'));
editor.dispatchEvent(newOpenEvent(doc, 'test.scd'));
await editor.updateComplete;

editor.dispatchEvent(
Expand All @@ -83,7 +83,7 @@ describe('with editor plugins loaded', () => {
);
await editor.updateComplete;

const plugin = editor.shadowRoot?.querySelector('*[docname="test.xml"]');
const plugin = editor.shadowRoot?.querySelector('*[docname="test.scd"]');
expect(plugin).to.have.property('editCount', 1);
});

Expand Down Expand Up @@ -151,31 +151,31 @@ describe('with menu plugins loaded', () => {
});

it('passes attribute docname', async () => {
editor.dispatchEvent(newOpenEvent(doc, 'test.xml'));
editor.dispatchEvent(newOpenEvent(doc, 'test.scd'));
await editor.updateComplete;

const plugin = editor.shadowRoot?.querySelector('*[docName="test.xml"]');
const plugin = editor.shadowRoot?.querySelector('*[docName="test.scd"]');
expect(plugin?.tagName).to.exist.and.to.satisfy(isOscdPlugin);
});

it('passes property doc', async () => {
editor.dispatchEvent(newOpenEvent(doc, 'test.xml'));
editor.dispatchEvent(newOpenEvent(doc, 'test.scd'));
await editor.updateComplete;

const plugin = editor.shadowRoot?.querySelector('*[docname="test.xml"]');
const plugin = editor.shadowRoot?.querySelector('*[docname="test.scd"]');
expect(plugin).to.have.property('docs');
});

it('passes property editCount', async () => {
editor.dispatchEvent(newOpenEvent(doc, 'test.xml'));
editor.dispatchEvent(newOpenEvent(doc, 'test.scd'));
await editor.updateComplete;

const plugin = editor.shadowRoot?.querySelector('*[docname="test.xml"]');
const plugin = editor.shadowRoot?.querySelector('*[docname="test.scd"]');
expect(plugin).to.have.property('editCount', 0);
});

it('updated passed editCount property on edit events', async () => {
editor.dispatchEvent(newOpenEvent(doc, 'test.xml'));
editor.dispatchEvent(newOpenEvent(doc, 'test.scd'));
await editor.updateComplete;

editor.dispatchEvent(
Expand All @@ -186,7 +186,7 @@ describe('with menu plugins loaded', () => {
);
await editor.updateComplete;

const plugin = editor.shadowRoot?.querySelector('*[docname="test.xml"]');
const plugin = editor.shadowRoot?.querySelector('*[docname="test.scd"]');
expect(plugin).to.have.property('editCount', 1);
});

Expand Down
8 changes: 4 additions & 4 deletions open-scd.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ allLocales.forEach(lang =>
it(`displays a current document title`, async () => {
await editor.updateComplete;

editor.dispatchEvent(newOpenEvent(doc, 'test.xml'));
editor.dispatchEvent(newOpenEvent(doc, 'test.scd'));
await editor.updateComplete;
await timeout(20);
await visualDiff(editor, `document-name-${lang}`);
Expand Down Expand Up @@ -213,7 +213,7 @@ allLocales.forEach(lang =>
},
{
name: 'Test Menu Plugin 2',
src: 'data:text/javascript;charset=utf-8,export%20default%20class%20TestPlugin%20extends%20HTMLElement%20%7B%0D%0A%20%20async%20run%28%29%20%7B%0D%0A%20%20%20%20this.dispatchEvent%28new%20CustomEvent%28%27oscd-open%27%2C%20%7Bdetail%3A%20%7BdocName%3A%20%27testDoc%27%2C%20doc%3A%20window.document%7D%2C%20bubbles%3A%20true%2C%20composed%3A%20true%7D%29%29%3B%0D%0A%20%20%7D%0D%0A%7D',
src: 'data:text/javascript;charset=utf-8,export%20default%20class%20TestPlugin%20extends%20HTMLElement%20%7B%0D%0A%20%20async%20run%28%29%20%7B%0D%0A%20%20%20%20this.dispatchEvent%28new%20CustomEvent%28%27oscd-open%27%2C%20%7Bdetail%3A%20%7BdocName%3A%20%27testDoc.scd%27%2C%20doc%3A%20window.document%7D%2C%20bubbles%3A%20true%2C%20composed%3A%20true%7D%29%29%3B%0D%0A%20%20%7D%0D%0A%7D',
icon: 'polymer',
active: true,
requireDoc: false,
Expand Down Expand Up @@ -264,7 +264,7 @@ allLocales.forEach(lang =>

await editor.updateComplete;
await timeout(200);
expect(editor.docName).to.equal('testDoc');
expect(editor.docName).to.equal('testDoc.scd');
await editor.updateComplete;
await visualDiff(editor, `menu-plugins-triggered-${lang}`);
});
Expand Down Expand Up @@ -316,7 +316,7 @@ allLocales.forEach(lang =>
});

it('displays more tabs with a doc loaded', async () => {
editor.dispatchEvent(newOpenEvent(doc, 'test.xml'));
editor.dispatchEvent(newOpenEvent(doc, 'test.scd'));
await editor.updateComplete;
await visualDiff(editor, `editor-plugins-with-doc-${lang}`);
});
Expand Down
Loading
Loading