@omicronenergy/oscd-shell 0.0.5 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/foundation/cyrb64.d.ts +6 -0
- package/dist/foundation/cyrb64.js +26 -0
- package/dist/foundation/cyrb64.js.map +1 -0
- package/dist/foundation.d.ts +1 -0
- package/dist/foundation.js +2 -0
- package/dist/foundation.js.map +1 -0
- package/dist/locales/de.d.ts +10 -0
- package/dist/locales/de.js +15 -0
- package/dist/locales/de.js.map +1 -0
- package/dist/locales.d.ts +13 -0
- package/dist/locales.js +21 -0
- package/dist/locales.js.map +1 -0
- package/dist/oscd-shell.d.ts +115 -0
- package/dist/oscd-shell.js +732 -0
- package/dist/oscd-shell.js.map +1 -0
- package/package.json +32 -29
- package/.editorconfig +0 -22
- package/.github/actions/setup-node-env/action.yml +0 -49
- package/.github/workflows/release-please.yml +0 -84
- package/.github/workflows/test.yml +0 -18
- package/.github/workflows/update-screenshots.yml +0 -29
- package/.husky/commit-msg +0 -1
- package/.husky/pre-commit +0 -1
- package/.release-please-manifest.json +0 -1
- package/CHANGELOG.md +0 -73
- package/CONTRIBUTING.md +0 -393
- package/commitlint.config.js +0 -1
- package/demo/AddPlugins.js +0 -42
- package/demo/DemoPluginSrc.js +0 -9
- package/demo/embedded.html +0 -17
- package/demo/index.html +0 -95
- package/foundation/cyrb64.ts +0 -27
- package/foundation/edit-event.ts +0 -273
- package/foundation/open-event.ts +0 -21
- package/foundation.ts +0 -28
- package/lit-localize.json +0 -15
- package/localization/de.xlf +0 -75
- package/oscd-shell.editing.spec.ts +0 -813
- package/oscd-shell.plugging.spec.ts +0 -78
- package/oscd-shell.spec.ts +0 -431
- package/oscd-shell.test.ts +0 -382
- package/oscd-shell.ts +0 -906
- package/release-please-config.json +0 -21
- package/rollup.config.js +0 -51
- package/screenshots/Chromium/baseline/app-bar-de.png +0 -0
- package/screenshots/Chromium/baseline/app-bar-en.png +0 -0
- package/screenshots/Chromium/baseline/document-name-de.png +0 -0
- package/screenshots/Chromium/baseline/document-name-en.png +0 -0
- package/screenshots/Chromium/baseline/editor-plugins-de.png +0 -0
- package/screenshots/Chromium/baseline/editor-plugins-en.png +0 -0
- package/screenshots/Chromium/baseline/editor-plugins-selected-de.png +0 -0
- package/screenshots/Chromium/baseline/editor-plugins-selected-en.png +0 -0
- package/screenshots/Chromium/baseline/editor-plugins-with-doc-de.png +0 -0
- package/screenshots/Chromium/baseline/editor-plugins-with-doc-en.png +0 -0
- package/screenshots/Chromium/baseline/log-entries-de.png +0 -0
- package/screenshots/Chromium/baseline/log-entries-en.png +0 -0
- package/screenshots/Chromium/baseline/log-entries-redone-de.png +0 -0
- package/screenshots/Chromium/baseline/log-entries-redone-en.png +0 -0
- package/screenshots/Chromium/baseline/log-entries-undone-de.png +0 -0
- package/screenshots/Chromium/baseline/log-entries-undone-en.png +0 -0
- package/screenshots/Chromium/baseline/log-screen-de.png +0 -0
- package/screenshots/Chromium/baseline/log-screen-en.png +0 -0
- package/screenshots/Chromium/baseline/menu-drawer-de.png +0 -0
- package/screenshots/Chromium/baseline/menu-drawer-en.png +0 -0
- package/screenshots/Chromium/baseline/menu-plugins-de.png +0 -0
- package/screenshots/Chromium/baseline/menu-plugins-en.png +0 -0
- package/screenshots/Chromium/baseline/menu-plugins-triggered-de.png +0 -0
- package/screenshots/Chromium/baseline/menu-plugins-triggered-en.png +0 -0
- package/screenshots/Firefox/baseline/app-bar-de.png +0 -0
- package/screenshots/Firefox/baseline/app-bar-en.png +0 -0
- package/screenshots/Firefox/baseline/document-name-de.png +0 -0
- package/screenshots/Firefox/baseline/document-name-en.png +0 -0
- package/screenshots/Firefox/baseline/editor-plugins-de.png +0 -0
- package/screenshots/Firefox/baseline/editor-plugins-en.png +0 -0
- package/screenshots/Firefox/baseline/editor-plugins-selected-de.png +0 -0
- package/screenshots/Firefox/baseline/editor-plugins-selected-en.png +0 -0
- package/screenshots/Firefox/baseline/editor-plugins-with-doc-de.png +0 -0
- package/screenshots/Firefox/baseline/editor-plugins-with-doc-en.png +0 -0
- package/screenshots/Firefox/baseline/log-entries-de.png +0 -0
- package/screenshots/Firefox/baseline/log-entries-en.png +0 -0
- package/screenshots/Firefox/baseline/log-entries-redone-de.png +0 -0
- package/screenshots/Firefox/baseline/log-entries-redone-en.png +0 -0
- package/screenshots/Firefox/baseline/log-entries-undone-de.png +0 -0
- package/screenshots/Firefox/baseline/log-entries-undone-en.png +0 -0
- package/screenshots/Firefox/baseline/log-screen-de.png +0 -0
- package/screenshots/Firefox/baseline/log-screen-en.png +0 -0
- package/screenshots/Firefox/baseline/menu-drawer-de.png +0 -0
- package/screenshots/Firefox/baseline/menu-drawer-en.png +0 -0
- package/screenshots/Firefox/baseline/menu-plugins-de.png +0 -0
- package/screenshots/Firefox/baseline/menu-plugins-en.png +0 -0
- package/screenshots/Firefox/baseline/menu-plugins-triggered-de.png +0 -0
- package/screenshots/Firefox/baseline/menu-plugins-triggered-en.png +0 -0
- package/screenshots/Webkit/baseline/app-bar-de.png +0 -0
- package/screenshots/Webkit/baseline/app-bar-en.png +0 -0
- package/screenshots/Webkit/baseline/document-name-de.png +0 -0
- package/screenshots/Webkit/baseline/document-name-en.png +0 -0
- package/screenshots/Webkit/baseline/editor-plugins-de.png +0 -0
- package/screenshots/Webkit/baseline/editor-plugins-en.png +0 -0
- package/screenshots/Webkit/baseline/editor-plugins-selected-de.png +0 -0
- package/screenshots/Webkit/baseline/editor-plugins-selected-en.png +0 -0
- package/screenshots/Webkit/baseline/editor-plugins-with-doc-de.png +0 -0
- package/screenshots/Webkit/baseline/editor-plugins-with-doc-en.png +0 -0
- package/screenshots/Webkit/baseline/log-entries-de.png +0 -0
- package/screenshots/Webkit/baseline/log-entries-en.png +0 -0
- package/screenshots/Webkit/baseline/log-entries-redone-de.png +0 -0
- package/screenshots/Webkit/baseline/log-entries-redone-en.png +0 -0
- package/screenshots/Webkit/baseline/log-entries-undone-de.png +0 -0
- package/screenshots/Webkit/baseline/log-entries-undone-en.png +0 -0
- package/screenshots/Webkit/baseline/log-screen-de.png +0 -0
- package/screenshots/Webkit/baseline/log-screen-en.png +0 -0
- package/screenshots/Webkit/baseline/menu-drawer-de.png +0 -0
- package/screenshots/Webkit/baseline/menu-drawer-en.png +0 -0
- package/screenshots/Webkit/baseline/menu-plugins-de.png +0 -0
- package/screenshots/Webkit/baseline/menu-plugins-en.png +0 -0
- package/screenshots/Webkit/baseline/menu-plugins-triggered-de.png +0 -0
- package/screenshots/Webkit/baseline/menu-plugins-triggered-en.png +0 -0
- package/tsconfig.json +0 -23
- package/utils/testing.spec.ts +0 -210
- package/utils/testing.ts +0 -65
- package/web-dev-server.config.js +0 -24
- package/web-test-runner.config.js +0 -180
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { expect, fixture } from '@open-wc/testing';
|
|
2
|
-
|
|
3
|
-
import { html } from 'lit';
|
|
4
|
-
|
|
5
|
-
import './oscd-shell.js';
|
|
6
|
-
import type { OpenSCD, Plugin } from './oscd-shell.js';
|
|
7
|
-
|
|
8
|
-
const sampleMenuPlugins: Plugin[] = [
|
|
9
|
-
{
|
|
10
|
-
name: 'Test Menu Plugin',
|
|
11
|
-
translations: { de: 'Test Menu Erweiterung' },
|
|
12
|
-
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%20return%20true%3B%0D%0A%20%20%7D%0D%0A%7D',
|
|
13
|
-
icon: 'margin',
|
|
14
|
-
active: true,
|
|
15
|
-
requireDoc: false,
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
name: 'Test Menu Plugin 2',
|
|
19
|
-
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%20return%20true%3B%0D%0A%20%20%7D%0D%0A%7D',
|
|
20
|
-
icon: 'margin',
|
|
21
|
-
active: true,
|
|
22
|
-
requireDoc: false,
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
name: 'Test Menu Plugin 3',
|
|
26
|
-
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%20return%20true%3B%0D%0A%20%20%7D%0D%0A%7D',
|
|
27
|
-
icon: 'margin',
|
|
28
|
-
active: false,
|
|
29
|
-
requireDoc: false,
|
|
30
|
-
},
|
|
31
|
-
];
|
|
32
|
-
|
|
33
|
-
describe('Plugging Element', () => {
|
|
34
|
-
let editor: OpenSCD;
|
|
35
|
-
|
|
36
|
-
beforeEach(async () => {
|
|
37
|
-
editor = <OpenSCD>await fixture(html`<oscd-shell></oscd-shell>`);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('loads menu plugins', () => {
|
|
41
|
-
editor.plugins = {
|
|
42
|
-
menu: sampleMenuPlugins,
|
|
43
|
-
};
|
|
44
|
-
expect(editor).property('plugins').property('menu').to.have.lengthOf(3);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('loading the same plugins twice does not result in duplicates', () => {
|
|
48
|
-
editor.plugins = {
|
|
49
|
-
menu: sampleMenuPlugins,
|
|
50
|
-
};
|
|
51
|
-
expect(editor).property('plugins').property('menu').to.have.lengthOf(3);
|
|
52
|
-
editor.plugins = {
|
|
53
|
-
menu: sampleMenuPlugins,
|
|
54
|
-
};
|
|
55
|
-
expect(editor).property('plugins').property('menu').to.have.lengthOf(3);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('loads editor plugins', () => {
|
|
59
|
-
editor.plugins = {
|
|
60
|
-
editor: [
|
|
61
|
-
{
|
|
62
|
-
name: 'Test Editor Plugin',
|
|
63
|
-
translations: { de: 'Test Editor Erweiterung' },
|
|
64
|
-
src: 'data:text/javascript;charset=utf-8,export%20default%20class%20TestEditorPlugin%20extends%20HTMLElement%20%7B%0D%0A%20%20constructor%20%28%29%20%7B%20super%28%29%3B%20this.innerHTML%20%3D%20%60%3Cp%3ETest%20Editor%20Plugin%3C%2Fp%3E%60%3B%20%7D%0D%0A%7D',
|
|
65
|
-
icon: 'coronavirus',
|
|
66
|
-
active: true,
|
|
67
|
-
},
|
|
68
|
-
{
|
|
69
|
-
name: 'Test Editor Plugin 2',
|
|
70
|
-
src: 'data:text/javascript;charset=utf-8,export%20default%20class%20TestEditorPlugin%20extends%20HTMLElement%20%7B%0D%0A%20%20constructor%20%28%29%20%7B%20super%28%29%3B%20this.innerHTML%20%3D%20%60%3Cp%3ETest%20Editor%20Plugin%3C%2Fp%3E%60%3B%20%7D%0D%0A%7D',
|
|
71
|
-
icon: 'coronavirus',
|
|
72
|
-
active: true,
|
|
73
|
-
},
|
|
74
|
-
],
|
|
75
|
-
};
|
|
76
|
-
expect(editor).property('plugins').property('editor').to.have.lengthOf(2);
|
|
77
|
-
});
|
|
78
|
-
});
|
package/oscd-shell.spec.ts
DELETED
|
@@ -1,431 +0,0 @@
|
|
|
1
|
-
import { expect, waitUntil } from '@open-wc/testing';
|
|
2
|
-
|
|
3
|
-
import './oscd-shell.js';
|
|
4
|
-
|
|
5
|
-
import { OscdListItem } from '@omicronenergy/oscd-ui/list/OscdListItem.js';
|
|
6
|
-
import { OscdTabs } from '@omicronenergy/oscd-ui/tabs/OscdTabs.js';
|
|
7
|
-
import Sinon from 'sinon';
|
|
8
|
-
|
|
9
|
-
import { OscdSecondaryTab } from '@omicronenergy/oscd-ui/tabs/OscdSecondaryTab.js';
|
|
10
|
-
|
|
11
|
-
import type { OpenSCD } from './oscd-shell.js';
|
|
12
|
-
|
|
13
|
-
import { cyrb64, newEditEvent, newOpenEvent } from './foundation.js';
|
|
14
|
-
import {
|
|
15
|
-
getFirstTextNodeContent,
|
|
16
|
-
querySelectorContainingText,
|
|
17
|
-
} from './utils/testing.js';
|
|
18
|
-
import { util } from './oscd-shell.editing.spec.js';
|
|
19
|
-
|
|
20
|
-
function isOscdPlugin(tag: string): boolean {
|
|
21
|
-
return tag.toLocaleLowerCase().startsWith('oscd-p');
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const doc = new DOMParser().parseFromString(
|
|
25
|
-
`<testdoc></testdoc>`,
|
|
26
|
-
'application/xml',
|
|
27
|
-
);
|
|
28
|
-
|
|
29
|
-
const testMenuPlugin = {
|
|
30
|
-
name: 'Test Undo Menu Plugin',
|
|
31
|
-
translations: { de: 'Test Rückgängig-Menü-Plugin' },
|
|
32
|
-
src: 'data:text/javascript;charset=utf-8,export%20default%20class%20TestPlugin%20extends%20HTMLElement%20%7B%0D%0A%20%20async%20run()%20%7B%0D%0A%20%20const%20editor%20=%20(this.getRootNode()).host;%20%0D%0A%20editor.undo();%0D%0A%20return%20true;%0D%0A%20%20%7D%0D%0A%7D',
|
|
33
|
-
icon: 'undo',
|
|
34
|
-
active: true,
|
|
35
|
-
requireDoc: false,
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
const testEditorPlugin = {
|
|
39
|
-
name: 'Test Editor Plugin',
|
|
40
|
-
translations: { de: 'Test Editor Erweiterung' },
|
|
41
|
-
src: 'data:text/javascript;charset=utf-8,export%20default%20class%20TestEditorPlugin%20extends%20HTMLElement%20%7B%0D%0A%20%20constructor%20%28%29%20%7B%20super%28%29%3B%20this.innerHTML%20%3D%20%60%3Cp%3ETest%20Editor%20Plugin%3C%2Fp%3E%60%3B%20%7D%0D%0A%7D',
|
|
42
|
-
icon: 'edit',
|
|
43
|
-
active: true,
|
|
44
|
-
requireDoc: false,
|
|
45
|
-
};
|
|
46
|
-
const testEditorPlugin2 = {
|
|
47
|
-
name: 'Test Editor Plugin 2',
|
|
48
|
-
translations: { de: 'Test Editor Erweiterung 2' },
|
|
49
|
-
src: 'data:text/javascript;charset=utf-8,export%20default%20class%20TestEditorPlugin2%20extends%20HTMLElement%20%7B%0D%0A%20%20constructor%20%28%29%20%7B%20super%28%29%3B%20this.innerHTML%20%3D%20%60%3Cp%3ETest%20Editor%20Plugin2%3C%2Fp%3E%60%3B%20%7D%0D%0A%7D',
|
|
50
|
-
icon: 'edit',
|
|
51
|
-
active: true,
|
|
52
|
-
requireDoc: false,
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
let editor: OpenSCD;
|
|
56
|
-
beforeEach(() => {
|
|
57
|
-
editor = document.createElement('oscd-shell');
|
|
58
|
-
document.body.prepend(editor);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
afterEach(() => {
|
|
62
|
-
editor.remove();
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
describe('with editor plugins loaded', () => {
|
|
66
|
-
beforeEach(async () => {
|
|
67
|
-
editor.plugins = {
|
|
68
|
-
menu: [],
|
|
69
|
-
editor: [testEditorPlugin, testEditorPlugin2],
|
|
70
|
-
};
|
|
71
|
-
await editor.updateComplete;
|
|
72
|
-
|
|
73
|
-
await waitUntil(
|
|
74
|
-
() =>
|
|
75
|
-
editor.shadowRoot!.querySelectorAll('oscd-secondary-tab').length === 2,
|
|
76
|
-
'Custom Plugin did not load',
|
|
77
|
-
);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it('changes editor plugin when clicking on the editor tab', async () => {
|
|
81
|
-
const editorTabBar = editor.shadowRoot?.querySelector(
|
|
82
|
-
'oscd-tabs',
|
|
83
|
-
) as OscdTabs;
|
|
84
|
-
expect(editorTabBar).to.exist;
|
|
85
|
-
expect(editorTabBar.activeTabIndex).to.equal(0);
|
|
86
|
-
expect(editorTabBar.querySelectorAll('oscd-secondary-tab').length).to.equal(
|
|
87
|
-
2,
|
|
88
|
-
);
|
|
89
|
-
const tabs =
|
|
90
|
-
editorTabBar.querySelectorAll<OscdSecondaryTab>('oscd-secondary-tab');
|
|
91
|
-
expect(getFirstTextNodeContent(tabs[0])).to.equal(testEditorPlugin.name);
|
|
92
|
-
expect(getFirstTextNodeContent(tabs[1])).to.equal(testEditorPlugin2.name);
|
|
93
|
-
|
|
94
|
-
const lastTab = editorTabBar.querySelectorAll(
|
|
95
|
-
'oscd-secondary-tab:last-child',
|
|
96
|
-
)[0] as OscdSecondaryTab;
|
|
97
|
-
expect(lastTab).to.exist;
|
|
98
|
-
lastTab!.click();
|
|
99
|
-
|
|
100
|
-
await editor.updateComplete;
|
|
101
|
-
await waitUntil(
|
|
102
|
-
() => editor.shadowRoot!.querySelector(editor!.editor),
|
|
103
|
-
'second editor plugin did not load',
|
|
104
|
-
);
|
|
105
|
-
const secondEditorPluginContent = editor.shadowRoot!.querySelector(
|
|
106
|
-
editor!.editor,
|
|
107
|
-
);
|
|
108
|
-
expect(
|
|
109
|
-
secondEditorPluginContent?.querySelector('p')?.textContent?.trim(),
|
|
110
|
-
).to.equal('Test Editor Plugin2');
|
|
111
|
-
expect(editorTabBar.activeTabIndex).to.equal(1);
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
it('passes attribute locale', () => {
|
|
115
|
-
const plugin = editor.shadowRoot?.querySelector('*[locale="en"]');
|
|
116
|
-
expect(plugin?.tagName).to.exist.and.to.satisfy(isOscdPlugin);
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
it('passes attribute docname', async () => {
|
|
120
|
-
editor.dispatchEvent(newOpenEvent(doc, 'test.scd'));
|
|
121
|
-
await editor.updateComplete;
|
|
122
|
-
|
|
123
|
-
const plugin = editor.shadowRoot?.querySelector('*[docName="test.scd"]');
|
|
124
|
-
expect(plugin?.tagName).to.exist.and.to.satisfy(isOscdPlugin);
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
it('passes property doc', async () => {
|
|
128
|
-
editor.dispatchEvent(newOpenEvent(doc, 'test.scd'));
|
|
129
|
-
await editor.updateComplete;
|
|
130
|
-
|
|
131
|
-
const plugin = editor.shadowRoot?.querySelector('*[docname="test.scd"]');
|
|
132
|
-
expect(plugin).to.have.property('docs');
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
it('passes property editCount', async () => {
|
|
136
|
-
editor.dispatchEvent(newOpenEvent(doc, 'test.scd'));
|
|
137
|
-
await editor.updateComplete;
|
|
138
|
-
|
|
139
|
-
const plugin = editor.shadowRoot?.querySelector('*[docname="test.scd"]');
|
|
140
|
-
expect(plugin).to.have.property('editCount', 0);
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
it('updated passed editCount property on edit events', async () => {
|
|
144
|
-
editor.dispatchEvent(newOpenEvent(doc, 'test.scd'));
|
|
145
|
-
await editor.updateComplete;
|
|
146
|
-
|
|
147
|
-
editor.dispatchEvent(
|
|
148
|
-
newEditEvent({
|
|
149
|
-
element: doc.querySelector('testdoc')!,
|
|
150
|
-
attributes: { name: 'someName' },
|
|
151
|
-
}),
|
|
152
|
-
);
|
|
153
|
-
await editor.updateComplete;
|
|
154
|
-
|
|
155
|
-
const plugin = editor.shadowRoot?.querySelector('*[docname="test.scd"]');
|
|
156
|
-
expect(plugin).to.have.property('editCount', 1);
|
|
157
|
-
});
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
describe('with menu plugins loaded', () => {
|
|
161
|
-
beforeEach(async () => {
|
|
162
|
-
editor.plugins = {
|
|
163
|
-
menu: [testMenuPlugin],
|
|
164
|
-
};
|
|
165
|
-
await editor.updateComplete;
|
|
166
|
-
await waitUntil(
|
|
167
|
-
() =>
|
|
168
|
-
querySelectorContainingText(
|
|
169
|
-
editor.menuUI,
|
|
170
|
-
'oscd-list-item > span',
|
|
171
|
-
testMenuPlugin.name,
|
|
172
|
-
),
|
|
173
|
-
'Custom Plugin did not load',
|
|
174
|
-
);
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
it('passes attribute locale', () => {
|
|
178
|
-
const plugin = editor.shadowRoot?.querySelector('*[locale="en"]');
|
|
179
|
-
expect(plugin?.tagName).to.exist.and.to.satisfy(isOscdPlugin);
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
it('passes attribute docname', async () => {
|
|
183
|
-
editor.dispatchEvent(newOpenEvent(doc, 'test.scd'));
|
|
184
|
-
await editor.updateComplete;
|
|
185
|
-
|
|
186
|
-
const plugin = editor.shadowRoot?.querySelector('*[docName="test.scd"]');
|
|
187
|
-
expect(plugin?.tagName).to.exist.and.to.satisfy(isOscdPlugin);
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
it('passes property doc', async () => {
|
|
191
|
-
editor.dispatchEvent(newOpenEvent(doc, 'test.scd'));
|
|
192
|
-
await editor.updateComplete;
|
|
193
|
-
|
|
194
|
-
const plugin = editor.shadowRoot?.querySelector('*[docname="test.scd"]');
|
|
195
|
-
expect(plugin).to.have.property('docs');
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
it('passes property editCount', async () => {
|
|
199
|
-
editor.dispatchEvent(newOpenEvent(doc, 'test.scd'));
|
|
200
|
-
await editor.updateComplete;
|
|
201
|
-
|
|
202
|
-
const plugin = editor.shadowRoot?.querySelector('*[docname="test.scd"]');
|
|
203
|
-
expect(plugin).to.have.property('editCount', 0);
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
it('updated passed editCount property on edit events', async () => {
|
|
207
|
-
editor.dispatchEvent(newOpenEvent(doc, 'test.scd'));
|
|
208
|
-
await editor.updateComplete;
|
|
209
|
-
|
|
210
|
-
editor.dispatchEvent(
|
|
211
|
-
newEditEvent({
|
|
212
|
-
element: doc.querySelector('testdoc')!,
|
|
213
|
-
attributes: { name: 'someName' },
|
|
214
|
-
}),
|
|
215
|
-
);
|
|
216
|
-
await editor.updateComplete;
|
|
217
|
-
|
|
218
|
-
const plugin = editor.shadowRoot?.querySelector('*[docname="test.scd"]');
|
|
219
|
-
expect(plugin).to.have.property('editCount', 1);
|
|
220
|
-
});
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
describe('Custom plugins', () => {
|
|
224
|
-
beforeEach(async () => {
|
|
225
|
-
editor.plugins = {
|
|
226
|
-
menu: [testMenuPlugin],
|
|
227
|
-
editor: [testEditorPlugin],
|
|
228
|
-
};
|
|
229
|
-
await editor.updateComplete;
|
|
230
|
-
|
|
231
|
-
await waitUntil(
|
|
232
|
-
() =>
|
|
233
|
-
querySelectorContainingText(
|
|
234
|
-
editor.menuUI,
|
|
235
|
-
'oscd-list-item > span',
|
|
236
|
-
testMenuPlugin.name,
|
|
237
|
-
),
|
|
238
|
-
'Custom Plugin did not load',
|
|
239
|
-
);
|
|
240
|
-
});
|
|
241
|
-
|
|
242
|
-
it('executes the plugin upon menu item click', async () => {
|
|
243
|
-
const sclDoc = new DOMParser().parseFromString(
|
|
244
|
-
util.sclDocString,
|
|
245
|
-
'application/xml',
|
|
246
|
-
);
|
|
247
|
-
editor.dispatchEvent(newOpenEvent(sclDoc, 'test.scd'));
|
|
248
|
-
await editor.updateComplete;
|
|
249
|
-
const node = editor.doc.querySelector('Substation')!;
|
|
250
|
-
editor.dispatchEvent(newEditEvent({ node }));
|
|
251
|
-
await editor.updateComplete;
|
|
252
|
-
expect(sclDoc.querySelector('Substation')).to.not.exist;
|
|
253
|
-
|
|
254
|
-
editor.menuUI.opened = true;
|
|
255
|
-
await editor.menuUI.updateComplete;
|
|
256
|
-
const pluginMenuItem = querySelectorContainingText(
|
|
257
|
-
editor.menuUI,
|
|
258
|
-
'oscd-list-item > span',
|
|
259
|
-
'Test Undo Menu Plugin',
|
|
260
|
-
)?.closest('oscd-list-item') as OscdListItem;
|
|
261
|
-
expect(pluginMenuItem).to.exist;
|
|
262
|
-
expect(pluginMenuItem).to.have.property('disabled', false);
|
|
263
|
-
pluginMenuItem?.click();
|
|
264
|
-
await editor.updateComplete;
|
|
265
|
-
expect(sclDoc.querySelector('Substation')).to.exist;
|
|
266
|
-
});
|
|
267
|
-
|
|
268
|
-
it('does not attempt to call customElements.define if the plugin has already been defined', async () => {
|
|
269
|
-
const customEditorPlugin = {
|
|
270
|
-
name: 'Test 123 Editor Plugin',
|
|
271
|
-
src: 'data:text/javascript;charset=utf-8,export%20default%20class%20TestEditorPlugin%20extends%20HTMLElement%20%7B%0D%0A%20%20constructor%20%28%29%20%7B%20super%28%29%3B%20this.innerHTML%20%3D%20%60%3Cp%3ETest123%20Editor%20Plugin%3C%2Fp%3E%60%3B%20%7D%0D%0A%7D',
|
|
272
|
-
icon: 'edit',
|
|
273
|
-
active: true,
|
|
274
|
-
requireDoc: false,
|
|
275
|
-
};
|
|
276
|
-
|
|
277
|
-
const customEditorPluginTagName = `oscd-p${cyrb64(customEditorPlugin.src)}`;
|
|
278
|
-
|
|
279
|
-
customElements.define(
|
|
280
|
-
customEditorPluginTagName,
|
|
281
|
-
class extends HTMLElement {},
|
|
282
|
-
);
|
|
283
|
-
|
|
284
|
-
const customElementDefineSpy = Sinon.spy(window.customElements, 'define');
|
|
285
|
-
|
|
286
|
-
editor.plugins = { menu: [], editor: [customEditorPlugin] };
|
|
287
|
-
await editor.updateComplete;
|
|
288
|
-
|
|
289
|
-
expect(customElementDefineSpy.called).to.be.false;
|
|
290
|
-
});
|
|
291
|
-
|
|
292
|
-
it('does not allow the loading of a duplicate plugin', async () => {
|
|
293
|
-
const { menu } = editor.plugins;
|
|
294
|
-
const currentMenuPluginCount = editor.loadedPlugins.menu.length;
|
|
295
|
-
editor.plugins = {
|
|
296
|
-
menu: [...menu, ...menu],
|
|
297
|
-
editor: [],
|
|
298
|
-
};
|
|
299
|
-
await editor.updateComplete;
|
|
300
|
-
expect(editor.loadedPlugins.menu.length).to.equal(currentMenuPluginCount);
|
|
301
|
-
});
|
|
302
|
-
});
|
|
303
|
-
|
|
304
|
-
describe('localization', () => {
|
|
305
|
-
let menuItemStrings: string[] = [];
|
|
306
|
-
let editorTabStrings: string[] = [];
|
|
307
|
-
|
|
308
|
-
let logDialogStrings = {
|
|
309
|
-
title: '',
|
|
310
|
-
message: '',
|
|
311
|
-
undo: '',
|
|
312
|
-
redo: '',
|
|
313
|
-
close: '',
|
|
314
|
-
};
|
|
315
|
-
|
|
316
|
-
beforeEach(async () => {
|
|
317
|
-
editor.plugins = {
|
|
318
|
-
menu: [testMenuPlugin],
|
|
319
|
-
editor: [testEditorPlugin],
|
|
320
|
-
};
|
|
321
|
-
await editor.updateComplete;
|
|
322
|
-
await waitUntil(
|
|
323
|
-
() =>
|
|
324
|
-
querySelectorContainingText(
|
|
325
|
-
editor.menuUI,
|
|
326
|
-
'oscd-list-item > span',
|
|
327
|
-
testMenuPlugin.name,
|
|
328
|
-
),
|
|
329
|
-
`Custom menu plugin (${testMenuPlugin.name}) did not load`,
|
|
330
|
-
);
|
|
331
|
-
await waitUntil(
|
|
332
|
-
() =>
|
|
333
|
-
querySelectorContainingText(
|
|
334
|
-
editor.shadowRoot!.querySelector('oscd-tabs')!,
|
|
335
|
-
'oscd-secondary-tab',
|
|
336
|
-
testEditorPlugin.name,
|
|
337
|
-
),
|
|
338
|
-
`Custom editor plugin (${testEditorPlugin.name}) did not load`,
|
|
339
|
-
);
|
|
340
|
-
|
|
341
|
-
menuItemStrings = Array.from(
|
|
342
|
-
editor.menuUI.querySelectorAll('oscd-list-item > span'),
|
|
343
|
-
).map((span: Element) => span.textContent?.trim() || '');
|
|
344
|
-
|
|
345
|
-
editorTabStrings = Array.from(
|
|
346
|
-
editor?.shadowRoot?.querySelectorAll('oscd-secondary-tab') || [],
|
|
347
|
-
).map(
|
|
348
|
-
(tab: Element) =>
|
|
349
|
-
Array.from(tab.childNodes)
|
|
350
|
-
.filter(node => node.nodeType === Node.TEXT_NODE)
|
|
351
|
-
.map(node => node.textContent?.trim() ?? '')[0] || '',
|
|
352
|
-
);
|
|
353
|
-
|
|
354
|
-
logDialogStrings = {
|
|
355
|
-
title: editor.logUI.shadowRoot?.querySelector('h2')?.textContent || '',
|
|
356
|
-
message:
|
|
357
|
-
editor.logUI.querySelector('oscd-list-item > span')?.textContent || '',
|
|
358
|
-
undo:
|
|
359
|
-
getFirstTextNodeContent(
|
|
360
|
-
editor.logUI.querySelector('oscd-text-button[icon="undo"]'),
|
|
361
|
-
) || '',
|
|
362
|
-
redo:
|
|
363
|
-
getFirstTextNodeContent(
|
|
364
|
-
editor.logUI.querySelector('oscd-text-button[icon="redo"]'),
|
|
365
|
-
) || '',
|
|
366
|
-
close:
|
|
367
|
-
getFirstTextNodeContent(
|
|
368
|
-
editor.logUI.querySelector('oscd-text-button[icon="close"]'),
|
|
369
|
-
) || '',
|
|
370
|
-
};
|
|
371
|
-
|
|
372
|
-
// we only change the locale after waiting for the plugins to load and getting their default strings
|
|
373
|
-
editor.locale = 'de';
|
|
374
|
-
await waitUntil(() => editor.locale === 'de', 'Locale failed to change');
|
|
375
|
-
});
|
|
376
|
-
|
|
377
|
-
afterEach(async () => {
|
|
378
|
-
// reset to en so we can find the loaded plugins by their name
|
|
379
|
-
editor.locale = 'en';
|
|
380
|
-
await editor.updateComplete;
|
|
381
|
-
});
|
|
382
|
-
|
|
383
|
-
it('the menu items appear in german', () => {
|
|
384
|
-
const untranslatedStrings = Array.from(
|
|
385
|
-
editor.menuUI.querySelectorAll('oscd-list-item > span'),
|
|
386
|
-
)
|
|
387
|
-
.map((span: Element) => span.textContent?.trim() || '')
|
|
388
|
-
.filter((text: string) => menuItemStrings.includes(text));
|
|
389
|
-
|
|
390
|
-
expect(untranslatedStrings).to.be.empty;
|
|
391
|
-
});
|
|
392
|
-
|
|
393
|
-
it('the editor plugin appears in german', () => {
|
|
394
|
-
const untranslatedStrings = Array.from(
|
|
395
|
-
editor.shadowRoot?.querySelectorAll('oscd-secondary-tab') || [],
|
|
396
|
-
)
|
|
397
|
-
.map((span: Element) => span.textContent?.trim() || '')
|
|
398
|
-
.filter((text: string) => editorTabStrings.includes(text));
|
|
399
|
-
|
|
400
|
-
expect(untranslatedStrings).to.be.empty;
|
|
401
|
-
});
|
|
402
|
-
|
|
403
|
-
it('the log dialog appears in german', () => {
|
|
404
|
-
const localizedStrings = {
|
|
405
|
-
title: editor.logUI.shadowRoot?.querySelector('h2')?.textContent || '',
|
|
406
|
-
message:
|
|
407
|
-
editor.logUI.querySelector('oscd-list-item > span')?.textContent || '',
|
|
408
|
-
undo:
|
|
409
|
-
editor.logUI
|
|
410
|
-
.querySelector('oscd-text-button[value="undo"]')
|
|
411
|
-
?.getAttribute('label') || '',
|
|
412
|
-
redo:
|
|
413
|
-
editor.logUI
|
|
414
|
-
.querySelector('oscd-text-button[value="redo"]')
|
|
415
|
-
?.getAttribute('label') || '',
|
|
416
|
-
close:
|
|
417
|
-
editor.logUI.querySelector('oscd-text-button[value="close"]')
|
|
418
|
-
?.textContent || '',
|
|
419
|
-
};
|
|
420
|
-
|
|
421
|
-
expect(localizedStrings).not.to.deep.equal(logDialogStrings);
|
|
422
|
-
});
|
|
423
|
-
|
|
424
|
-
it('it remains in english after attempting to load a non-existing locale', async () => {
|
|
425
|
-
editor.locale = 'en';
|
|
426
|
-
// @ts-ignore
|
|
427
|
-
editor.locale = 'xx';
|
|
428
|
-
await waitUntil(() => editor.locale === 'en', 'Locale failed to change');
|
|
429
|
-
expect(editor.locale).to.equal('en');
|
|
430
|
-
});
|
|
431
|
-
});
|