forked from ca-d/open-scd-core
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathopen-scd.plugging.spec.ts
155 lines (122 loc) · 5.65 KB
/
open-scd.plugging.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import { expect, fixture } from '@open-wc/testing';
import { html } from 'lit';
import type { OpenSCD } from './open-scd.js';
import './open-scd.js';
import { newConfigurePluginEvent } from './foundation/plugin-event.js';
const menuPlugin1 = {
name: 'Test Menu Plugin',
translations: { de: 'Test Menu Erweiterung' },
src: 'data:text/javascript;charset=utf-8,export%20default%20class%20TestPlugin1%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',
icon: 'margin',
active: true,
requireDoc: false,
};
const menuPlugin2 = {
name: 'Test Menu Plugin 2',
src: 'data:text/javascript;charset=utf-8,export%20default%20class%20TestPlugin2%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',
icon: 'margin',
active: true,
requireDoc: false,
};
const menuPlugin3 = {
name: 'Test Menu Plugin 2',
src: 'data:text/javascript;charset=utf-8,export%20default%20class%20TestPlugin3%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',
icon: 'margin',
active: true,
requireDoc: false,
};
const editorPlugin1 = {
name: 'Test Editor Plugin',
translations: { de: 'Test Editor Erweiterung' },
src: 'data:text/javascript;charset=utf-8,export%20default%20class%20TestEditorPlugin1%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',
icon: 'coronavirus',
active: true,
};
const editorPlugin2 = {
name: 'Test Editor Plugin 2',
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%20Plugin%3C%2Fp%3E%60%3B%20%7D%0D%0A%7D',
icon: 'coronavirus',
active: true,
};
const editorPlugin3 = {
name: 'Test Editor Plugin 2',
src: 'data:text/javascript;charset=utf-8,export%20default%20class%20TestEditorPlugin3%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',
icon: 'coronavirus',
active: true,
};
describe('Plugging Element', () => {
let editor: OpenSCD;
beforeEach(async () => {
editor = <OpenSCD>await fixture(html`<open-scd></open-scd>`);
});
it('loads menu plugins', () => {
editor.plugins = { menu: [menuPlugin1, menuPlugin1, menuPlugin2] };
expect(editor).property('plugins').property('menu').to.have.lengthOf(3);
expect(editor).property('loadedPlugins').to.have.length(2);
});
it('loads menu plugin through config-plugin event', () => {
editor.plugins = {
menu: [menuPlugin1, menuPlugin2],
editor: [editorPlugin1, editorPlugin2],
};
const name = 'Test Menu Plugin 3';
const kind = 'menu';
editor.dispatchEvent(newConfigurePluginEvent(name, kind, menuPlugin3));
expect(editor).property('loadedPlugins').to.have.length(5);
expect(editor).property('plugins').property('editor').to.have.lengthOf(2);
expect(editor).property('plugins').property('menu').to.have.lengthOf(3);
});
it('removes menu plugin through config-plugin event', () => {
editor.plugins = {
menu: [menuPlugin1, menuPlugin2],
editor: [editorPlugin1, editorPlugin2],
};
const name = 'Test Menu Plugin';
const kind = 'menu';
editor.dispatchEvent(newConfigurePluginEvent(name, kind, null));
expect(editor).property('loadedPlugins').to.have.length(3);
expect(editor).property('plugins').property('menu').to.have.lengthOf(1);
expect(editor).property('plugins').property('editor').to.have.lengthOf(2);
});
it('loads editor plugins', () => {
editor.plugins = { editor: [editorPlugin1, editorPlugin2] };
expect(editor).property('loadedPlugins').to.have.length(2);
expect(editor).property('plugins').property('editor').to.have.lengthOf(2);
});
it('loads editor plugin through config-plugin event', async () => {
editor.plugins = {
menu: [menuPlugin1, menuPlugin2],
editor: [editorPlugin1, editorPlugin2],
};
const name = 'Test Menu Plugin 3';
const kind = 'editor';
editor.dispatchEvent(newConfigurePluginEvent(name, kind, editorPlugin3));
expect(editor).property('loadedPlugins').to.have.length(5);
expect(editor).property('plugins').property('menu').to.have.lengthOf(2);
expect(editor).property('plugins').property('editor').to.have.lengthOf(3);
});
it('removes editor plugin through config-plugin event', () => {
editor.plugins = {
menu: [menuPlugin1, menuPlugin2],
editor: [editorPlugin1, editorPlugin2],
};
const name = 'Test Editor Plugin 2';
const kind = 'editor';
editor.dispatchEvent(newConfigurePluginEvent(name, kind, null));
expect(editor).property('loadedPlugins').to.have.length(3);
expect(editor).property('plugins').property('menu').to.have.lengthOf(2);
expect(editor).property('plugins').property('editor').to.have.lengthOf(1);
});
it('ignores remove config-plugin event with incorrect name', () => {
editor.plugins = {
menu: [menuPlugin1, menuPlugin2],
editor: [editorPlugin1, editorPlugin2],
};
const name = 'Test Editor Plugin 4';
const kind = 'editor';
editor.dispatchEvent(newConfigurePluginEvent(name, kind, null));
expect(editor).property('loadedPlugins').to.have.length(4);
expect(editor).property('plugins').property('menu').to.have.lengthOf(2);
expect(editor).property('plugins').property('editor').to.have.lengthOf(2);
});
});