blob: 6dd31b387c31492ae3b0f8cd06bbd26d9b343fdb [file] [log] [blame]
Akron45308ce2020-08-28 14:10:23 +02001define(['plugin/server','plugin/widget','panel', 'panel/query', 'panel/result', 'plugin/service', 'pipe', 'vc','util'], function (pluginServerClass, widgetClass, panelClass, queryPanelClass, resultPanelClass, serviceClass, pipeClass, vcClass) {
Akronb43c8c62018-07-04 18:27:28 +02002
3 describe('KorAP.Plugin.Server', function () {
4
5 it('should be initializable', function () {
6 var manager = pluginServerClass.create();
7 expect(manager).toBeTruthy();
8 manager.destroy();
9 });
10
11 it('should add a widget', function () {
12 var manager = pluginServerClass.create();
Akron4a703872018-07-26 10:59:41 +020013 var panel = panelClass.create();
Akronbb891982020-10-05 16:07:18 +020014 var id = manager.addWidget(panel, {"name": 'Example 1', "src": 'about:blank'});
Akronb43c8c62018-07-04 18:27:28 +020015 expect(id).toMatch(/^id-/);
Akron4a703872018-07-26 10:59:41 +020016
17 var panelE = panel.element();
18 var widgetE = panelE.firstChild.firstChild;
19 expect(widgetE.classList.contains('widget')).toBeTruthy();
20 expect(widgetE.firstChild.tagName).toEqual("IFRAME");
21 var iframe = widgetE.firstChild;
22 expect(iframe.getAttribute("src")).toEqual("about:blank");
23
24 expect(widgetE.lastChild.firstChild.textContent).toEqual("Close");
25 expect(widgetE.lastChild.lastChild.textContent).toEqual("Example 1");
26
Akronb43c8c62018-07-04 18:27:28 +020027 manager.destroy();
28 });
Akron10a47962018-07-12 21:17:10 +020029
Akron22598cd2019-12-09 14:59:03 +010030 it('should add a service', function () {
31 var manager = pluginServerClass.create();
32
33 var e = manager.element();
34
35 document.body.appendChild(e);
36
37 expect(document.getElementById("services")).toBeTruthy();
38
39 expect(e.getAttribute("id")).toBe("services");
40 expect(e.children.length).toBe(0);
41
Akronbb891982020-10-05 16:07:18 +020042 var id = manager.addService({"name":'Example 1', "src":'about:blank'});
Akron22598cd2019-12-09 14:59:03 +010043 expect(id).toMatch(/^id-/);
44
45 expect(e.children.length).toBe(1);
46
47 manager.destroy();
48
49 expect(document.getElementById("services")).toBeFalsy();
50
51 });
52
Akron4a703872018-07-26 10:59:41 +020053 it('should close a widget', function () {
54 var manager = pluginServerClass.create();
55 var panel = panelClass.create();
Akronbb891982020-10-05 16:07:18 +020056 var id = manager.addWidget(panel, {"name":'Example 2', "src":'about:blank'});
Akron4a703872018-07-26 10:59:41 +020057 expect(id).toMatch(/^id-/);
58
59 var panelE = panel.element();
60 var widgetE = panelE.firstChild.firstChild;
61 expect(widgetE.classList.contains('widget')).toBeTruthy();
62
63 expect(panelE.getElementsByClassName('view').length).toEqual(1);
64
Akron22598cd2019-12-09 14:59:03 +010065 var widget = manager.service(id);
66 expect(widget.isWidget).toBeTruthy();
Akron4a703872018-07-26 10:59:41 +020067 widget.close();
68
69 expect(panelE.getElementsByClassName('view').length).toEqual(0);
Akron4a703872018-07-26 10:59:41 +020070 manager.destroy();
71 });
72
73
74 it('should fail on invalid registrations', function () {
Akron10a47962018-07-12 21:17:10 +020075 var manager = pluginServerClass.create();
76
77 expect(
78 function() { manager.register({}) }
79 ).toThrow(new Error("Missing name of plugin"));
80
81 expect(
82 function() { manager.register({
83 name : 'Example',
84 embed : ''
85 })}
86 ).toThrow(new Error("Embedding of plugin is no list"));
87
88 expect(
89 function() { manager.register({
90 name : 'Example',
91 embed : [{
92 panel : ''
93 }]
94 })}
95 ).toThrow(new Error("Panel for plugin is invalid"));
Akron2d0d96d2019-11-18 19:49:50 +010096 manager.destroy();
97 });
98
99 it('should accept valid registrations for matches', function () {
100 var manager = pluginServerClass.create();
101
102 manager.register({
103 name : 'Check',
104 embed : [{
105 panel : 'match',
106 title : 'Translate',
107 onClick : {
108 template : 'test'
109 }
110 }]
111 });
112
113 expect(manager.buttonGroup('match').length).toEqual(1);
114 manager.destroy();
115 });
Akron3d013802020-10-07 15:03:38 +0200116
Akron2d0d96d2019-11-18 19:49:50 +0100117 it('should accept valid registrations for query temporary', function () {
118 var manager = pluginServerClass.create();
119
120 manager.register({
121 name : 'Check',
122 embed : [{
123 panel : 'query',
124 title : 'Translate',
125 onClick : {
126 template : 'test'
127 }
128 }]
129 });
130
131 expect(manager.buttonGroup('query').length).toEqual(1);
132 manager.destroy();
Akron10a47962018-07-12 21:17:10 +0200133 });
hebasta043e96f2019-11-28 12:33:00 +0100134
135
136 it('should accept valid registrations for result', function () {
137 var manager = pluginServerClass.create();
138
139 manager.register({
140 name : 'Check',
141 embed : [{
142 panel : 'result',
143 title : 'Translate',
144 onClick : {
145 template : 'test'
146 }
147 }]
148 });
149
150 expect(manager.buttonGroup('result').length).toEqual(1);
151 manager.destroy();
152 });
Akronba09ed22020-10-01 16:01:45 +0200153
154 it('should accept valid registrations for addWidget', function () {
155 let p = KorAP.Panel["result"] = panelClass.create();
156
157 let manager = pluginServerClass.create();
158
159 manager.register({
160 name : 'Check',
161 embed : [{
162 panel : 'result',
163 title : 'Add',
164 onClick : {
165 template : 'about:blank',
166 action : 'addWidget'
167 }
168 }]
169 });
170
Akron37ea1192021-07-28 10:40:14 +0200171 let b = p.actions().element().firstChild;
Akronba09ed22020-10-01 16:01:45 +0200172 expect(b.hasAttribute("data-icon")).toBeFalsy();
173 expect(b.hasAttribute("cls")).toBeFalsy();
174 expect(b.getAttribute("title")).toEqual("Add");
175
176 expect(p.element().querySelectorAll("iframe").length).toEqual(0);
177
178 b.click();
179
180 expect(p.element().querySelectorAll("iframe").length).toEqual(1);
181 expect(p.element().querySelectorAll("div.view.widget").length).toEqual(1);
182 expect(p.element().querySelectorAll("div.view.show.widget").length).toEqual(1);
183
184 b.click();
185
186 expect(p.element().querySelectorAll("iframe").length).toEqual(2);
187 expect(p.element().querySelectorAll("div.view.widget").length).toEqual(2);
188 expect(p.element().querySelectorAll("div.view.show.widget").length).toEqual(2);
189
190 manager.destroy();
191
192 KorAP.Panel["result"] = undefined;
193 });
194
Akronba09ed22020-10-01 16:01:45 +0200195 it('should accept valid registrations for setWidget', function () {
196 let p = KorAP.Panel["result"] = panelClass.create();
197
198 let manager = pluginServerClass.create();
199
200 manager.register({
201 name : 'Check',
202 embed : [{
203 panel : 'result',
204 title : 'Add',
205 onClick : {
206 template : 'about:blank',
207 action : 'setWidget'
208 }
209 }]
210 });
211
Akron37ea1192021-07-28 10:40:14 +0200212 let b = p.actions().element().firstChild;
Akronba09ed22020-10-01 16:01:45 +0200213 expect(b.hasAttribute("data-icon")).toBeFalsy();
214 expect(b.hasAttribute("cls")).toBeFalsy();
215 expect(b.getAttribute("title")).toEqual("Add");
216
217 expect(p.element().querySelectorAll("iframe").length).toEqual(0);
218
219 b.click();
220
221 expect(p.element().querySelectorAll("iframe").length).toEqual(1);
222 expect(p.element().querySelectorAll("div.view.show.widget").length).toEqual(1);
223
224 b.click();
225
226 expect(p.element().querySelectorAll("iframe").length).toEqual(1);
227 expect(p.element().querySelectorAll("div.view.widget").length).toEqual(1);
228 expect(p.element().querySelectorAll("div.view.show.widget").length).toEqual(0);
Akronfcf89db2020-10-01 17:40:20 +0200229
230 p.element().querySelector("span.close").click();
231
232 expect(p.element().querySelectorAll("iframe").length).toEqual(0);
Akronda32e7a2021-11-16 17:28:57 +0100233
Akronfcf89db2020-10-01 17:40:20 +0200234 b.click();
235
236 expect(p.element().querySelectorAll("iframe").length).toEqual(1);
237 expect(p.element().querySelectorAll("div.view.widget").length).toEqual(1);
238 expect(p.element().querySelectorAll("div.view.show.widget").length).toEqual(1);
Akronfb11a962020-10-05 12:12:55 +0200239 expect(p.element().querySelector("iframe").getAttribute('sandbox')).toEqual('');
Akronda32e7a2021-11-16 17:28:57 +0100240
Akronba09ed22020-10-01 16:01:45 +0200241 manager.destroy();
242
243 KorAP.Panel["result"] = undefined;
244 });
Akronfb11a962020-10-05 12:12:55 +0200245
Akrona70b6892021-11-04 14:23:24 +0100246 it('should accept valid registrations for toggle', function () {
247 let p = KorAP.Panel["result"] = panelClass.create();
248
249 let manager = pluginServerClass.create();
250
251 manager.register({
252 name : 'Check',
253 embed : [{
254 panel : 'result',
255 title : 'Glemm',
Akron83a58bc2024-11-08 09:55:19 +0100256 desc : 'Start Glemm',
Akrona70b6892021-11-04 14:23:24 +0100257 onClick : {
Akronda32e7a2021-11-16 17:28:57 +0100258 state : 'check',
Akrona70b6892021-11-04 14:23:24 +0100259 template : 'about:blank',
260 action : 'toggle',
261 'default' : false
262 }
263 }]
264 });
265
266 let b = p.actions().element().firstChild;
267 expect(b.hasAttribute("data-icon")).toBeFalsy();
268 expect(b.hasAttribute("cls")).toBeFalsy();
Akron83a58bc2024-11-08 09:55:19 +0100269 expect(b.lastChild.innerText).toEqual("Glemm");
270 expect(b.getAttribute("title")).toEqual("Start Glemm");
Akrona70b6892021-11-04 14:23:24 +0100271 expect(b.firstChild.classList.contains('button-icon')).toBeTruthy();
272 expect(b.firstChild.classList.contains('check')).toBeTruthy();
273 expect(b.firstChild.classList.contains('checked')).toBeFalsy();
274
275 expect(p.element().querySelectorAll("iframe").length).toEqual(0);
276
Akronda32e7a2021-11-16 17:28:57 +0100277 expect(manager.states().toString()).toEqual("");
278
Akrona70b6892021-11-04 14:23:24 +0100279 b.click();
280
Akronda32e7a2021-11-16 17:28:57 +0100281 expect(manager.states().toString()).toEqual("\"check\":true");
282
Akron83a58bc2024-11-08 09:55:19 +0100283 expect(b.getAttribute("title")).toEqual("Start Glemm");
Akrona70b6892021-11-04 14:23:24 +0100284 expect(b.firstChild.classList.contains('button-icon')).toBeTruthy();
285 expect(b.firstChild.classList.contains('check')).toBeTruthy();
286 expect(b.firstChild.classList.contains('checked')).toBeTruthy();
287
288 // Check with true default
289 p = KorAP.Panel["result"] = panelClass.create();
290
291 manager = pluginServerClass.create();
292
293 manager.register({
294 name : 'Check',
295 embed : [{
296 panel : 'result',
297 title : 'Glemm',
298 onClick : {
299 template : 'about:blank',
300 action : 'toggle',
301 'default' : true
302 }
303 }]
304 });
305
306 b = p.actions().element().firstChild;
307 expect(b.hasAttribute("data-icon")).toBeFalsy();
308 expect(b.hasAttribute("cls")).toBeFalsy();
309 expect(b.getAttribute("title")).toEqual("Glemm");
310 expect(b.firstChild.classList.contains('button-icon')).toBeTruthy();
311 expect(b.firstChild.classList.contains('check')).toBeTruthy();
312 expect(b.firstChild.classList.contains('checked')).toBeTruthy();
313
314 manager.destroy();
315 KorAP.Panel["result"] = undefined;
316 });
317
318
Akron3d013802020-10-07 15:03:38 +0200319 it('should alert on plugin info (1)', function () {
320
321 let alertMsg;
322 spyOn(window, 'alert').and.callFake(function(msg) {
323 alertMsg = msg;
324 });
325
326 let p = KorAP.Panel["result"] = panelClass.create();
327
328 let manager = pluginServerClass.create();
329
330 manager.register({
331 name : 'Check',
332 embed : [{
333 panel : 'result',
334 title : 'Add',
335 onClick : {
336 template : 'about:blank',
337 action : 'setWidget'
338 }
339 }]
340 });
341
342 expect(alertMsg).toBeUndefined();
343
Akron37ea1192021-07-28 10:40:14 +0200344 let b = p.actions().element().firstChild;
Akron3d013802020-10-07 15:03:38 +0200345 b.click();
346
347 // This may only be temporary and should open the plugin window instead
348 p.element().querySelector("span.plugin").click();
349
350 expect(alertMsg).toEqual('Check');
351
352 manager.destroy();
353 KorAP.Panel["result"] = undefined;
354 });
355
356
357 it('should alert on plugin info (2)', function () {
358
359 let alertMsg;
360 spyOn(window, 'alert').and.callFake(function(msg) {
361 alertMsg = msg;
362 });
363
364 let p = KorAP.Panel["result"] = panelClass.create();
365
366 let manager = pluginServerClass.create();
367
368 manager.register({
369 name : 'Check',
370 desc : 'Simple Check plugin',
371 embed : [{
372 panel : 'result',
373 title : 'Add',
374 onClick : {
375 template : 'about:blank',
376 action : 'setWidget'
377 }
378 }]
379 });
380
381 expect(alertMsg).toBeUndefined();
382
Akron37ea1192021-07-28 10:40:14 +0200383 let b = p.actions().element().firstChild;
Akron3d013802020-10-07 15:03:38 +0200384 b.click();
385
386 // This may only be temporary and should open the plugin window instead
387 p.element().querySelector("span.plugin").click();
388
389 expect(alertMsg).toEqual("Check\n\nSimple Check plugin");
390
391 manager.destroy();
392 KorAP.Panel["result"] = undefined;
393 });
394
395
Akronfb11a962020-10-05 12:12:55 +0200396 it('should accept widget permissions', function () {
397 let p = KorAP.Panel["result"] = panelClass.create();
398
399 let manager = pluginServerClass.create();
400
401 manager.register({
402 name : 'Check',
403 embed : [{
404 panel : 'result',
405 title : 'Add',
Akron83a58bc2024-11-08 09:55:19 +0100406 desc : 'Add something',
Akronfb11a962020-10-05 12:12:55 +0200407 onClick : {
408 template : 'about:blank',
409 action : 'addWidget',
Akronce0d8822020-10-05 16:25:40 +0200410 permissions: ['scripts', 'forms', 'all']
Akronfb11a962020-10-05 12:12:55 +0200411 }
412 }]
413 });
414
Akron37ea1192021-07-28 10:40:14 +0200415 let b = p.actions().element().firstChild;
Akron83a58bc2024-11-08 09:55:19 +0100416 expect(b.lastChild.innerText).toEqual("Add");
417 expect(b.getAttribute("title")).toEqual("Add something");
Akronfb11a962020-10-05 12:12:55 +0200418 b.click();
419 expect(p.element().querySelectorAll("iframe").length).toEqual(1);
420 expect(p.element().querySelector("iframe").getAttribute('sandbox')).toEqual('allow-forms allow-scripts');
421 });
Akronb43c8c62018-07-04 18:27:28 +0200422 });
Akron2d0d96d2019-11-18 19:49:50 +0100423
Akronb43c8c62018-07-04 18:27:28 +0200424 describe('KorAP.Plugin.Widget', function () {
425 it('should be initializable', function () {
Akron22598cd2019-12-09 14:59:03 +0100426 expect(function () { widgetClass.create() }).toThrow(new Error("Service not well defined"));
Akron56a11af2018-07-27 18:28:45 +0200427
Akronbb891982020-10-05 16:07:18 +0200428 widget = widgetClass.create({"name" : "Test", "src":"https://example", "id":56});
Akronb43c8c62018-07-04 18:27:28 +0200429 expect(widget).toBeTruthy();
Akron56a11af2018-07-27 18:28:45 +0200430 expect(widget.id).toEqual(56);
431 expect(widget.name).toEqual("Test");
432 expect(widget.src).toEqual("https://example");
433 });
434
435 it('should create a view element', function () {
Akronbb891982020-10-05 16:07:18 +0200436 var widget = widgetClass.create({
437 "name":"Test",
438 "src":"https://example",
439 "id":56,
Akronce0d8822020-10-05 16:25:40 +0200440 "permissions":["scripts","forms"]
Akronbb891982020-10-05 16:07:18 +0200441 });
Akron56a11af2018-07-27 18:28:45 +0200442 var we = widget.element();
443
444 expect(we.tagName).toEqual("DIV");
445 expect(we.classList.contains('view')).toBeTruthy();
446 expect(we.classList.contains('widget')).toBeTruthy();
447
448 var iframe = we.firstChild;
449 expect(iframe.tagName).toEqual("IFRAME");
Akronfb11a962020-10-05 12:12:55 +0200450 expect(iframe.getAttribute("sandbox")).toEqual("allow-forms allow-scripts");
Akron56a11af2018-07-27 18:28:45 +0200451 expect(iframe.getAttribute("src")).toEqual("https://example");
452 expect(iframe.getAttribute("name")).toEqual("56");
Akronfb11a962020-10-05 12:12:55 +0200453
Akron56a11af2018-07-27 18:28:45 +0200454 var btn = we.lastChild;
455 expect(btn.classList.contains("button-group")).toBeTruthy();
456 expect(btn.classList.contains("button-view")).toBeTruthy();
457 expect(btn.classList.contains("widget")).toBeTruthy();
458
459 expect(btn.firstChild.tagName).toEqual("SPAN");
460 expect(btn.firstChild.classList.contains("button-icon")).toBeTruthy();
461 expect(btn.firstChild.classList.contains("close")).toBeTruthy();
462 expect(btn.firstChild.firstChild.tagName).toEqual("SPAN");
463
464 expect(btn.lastChild.tagName).toEqual("SPAN");
465 expect(btn.lastChild.classList.contains("button-icon")).toBeTruthy();
466 expect(btn.lastChild.classList.contains("plugin")).toBeTruthy();
467 expect(btn.lastChild.firstChild.tagName).toEqual("SPAN");
468 expect(btn.lastChild.textContent).toEqual("Test");
469 })
Akronfb11a962020-10-05 12:12:55 +0200470
Akron56a11af2018-07-27 18:28:45 +0200471 it('should be resizable', function () {
Akronbb891982020-10-05 16:07:18 +0200472 var widget = widgetClass.create({"name":"Test", "src":"https://example", "id":56});
Akron56a11af2018-07-27 18:28:45 +0200473 var iframe = widget.show();
474 expect(iframe.style.height).toEqual('0px');
475 widget.resize({ height : 9 });
476 expect(iframe.style.height).toEqual('9px');
Akronb43c8c62018-07-04 18:27:28 +0200477 });
Akron3d9ce5e2020-10-01 15:18:36 +0200478
479 it('should be minimizable', function () {
Akronbb891982020-10-05 16:07:18 +0200480 var widget = widgetClass.create({"name":"Test", "src":"https://example", "id":56});
Akron3d9ce5e2020-10-01 15:18:36 +0200481 var we = widget.element();
482 expect(we.classList.contains('show')).toBeTruthy();
483 widget.minimize();
484 expect(we.classList.contains('show')).toBeFalsy();
485 });
Akronb43c8c62018-07-04 18:27:28 +0200486 });
Akron2d0d96d2019-11-18 19:49:50 +0100487
Akron22598cd2019-12-09 14:59:03 +0100488 describe('KorAP.Plugin.Service', function () {
489 it('should be initializable', function () {
490 expect(function () { serviceClass.create() }).toThrow(new Error("Service not well defined"));
491
Akronbb891982020-10-05 16:07:18 +0200492 let service = serviceClass.create({"name":"Test", "src":"https://example", "id":56});
Akron22598cd2019-12-09 14:59:03 +0100493 expect(service).toBeTruthy();
494 expect(service.id).toEqual(56);
495 expect(service.name).toEqual("Test");
496 expect(service.src).toEqual("https://example");
497 });
498
499 it('should be loadable', function () {
Akronbb891982020-10-05 16:07:18 +0200500 let service = serviceClass.create({"name":"Test", "src":"https://example", "id":56});
Akron22598cd2019-12-09 14:59:03 +0100501 expect(service).toBeTruthy();
502
503 let i = service.load();
504 expect(i.tagName).toEqual("IFRAME");
505 expect(i.getAttribute("allowTransparency")).toEqual("true");
506 expect(i.getAttribute("frameborder")).toEqual(''+0);
507 expect(i.getAttribute("name")).toEqual(''+service.id);
508 expect(i.getAttribute("src")).toEqual(service.src);
509 });
510 });
511
Akron2d0d96d2019-11-18 19:49:50 +0100512 describe('KorAP.Plugin.QueryPanel', function () {
513 it('should establish a query plugin', function () {
514 var queryPanel = queryPanelClass.create();
515
516 var div = document.createElement('div');
517
518 div.appendChild(queryPanel.element());
519 KorAP.Panel = KorAP.Panel || {};
520 KorAP.Panel['query'] = queryPanel;
521
522 // Register plugin afterwards
523 var manager = pluginServerClass.create();
524
525 manager.register({
526 name : 'Check',
527 embed : [{
528 panel : 'query',
529 title : 'Translate',
530 onClick : {
531 template : 'test'
532 }
533 }]
534 });
535
536 expect(manager.buttonGroup('query').length).toEqual(0);
537
538 // Clean up
539 KorAP.Panel['query'] = undefined;
540 manager.destroy();
541 });
hebastaf6adf8d2019-11-26 14:04:10 +0100542
543 it('Plugin buttons should be cleared after adding to panel', function () {
544
545 // Register plugin first
546 KorAP.Plugin = pluginServerClass.create();
547
548 KorAP.Plugin.register({
549 name : 'Check',
550 embed : [{
551 panel : 'query',
552 title : 'Translate',
553 onClick : {
554 template : 'test'
555 }
556 }]
557 });
558
559
560 var queryPanel = queryPanelClass.create();
561 var div = document.createElement('div');
562
563 div.appendChild(queryPanel.element());
564 KorAP.Panel = KorAP.Panel || {};
565 KorAP.Panel['query'] = queryPanel;
566 expect(KorAP.Plugin.buttonGroup('query').length).toEqual(0);
567
568 // Clean up
569 KorAP.Panel['query'] = undefined;
570 KorAP.Plugin.destroy();
571 KorAP.Plugin = undefined;
572 });
Akron2d0d96d2019-11-18 19:49:50 +0100573 });
hebasta043e96f2019-11-28 12:33:00 +0100574
Akron45308ce2020-08-28 14:10:23 +0200575 describe('KorAP.Plugin.ResultPanel', function () {
hebasta043e96f2019-11-28 12:33:00 +0100576 it('Plugin is registered second: buttons should be added to panel', function () {
577
578 var resultPanel = resultPanelClass.create();
579 resultPanel.addAlignAction();
580 var div = document.createElement('div');
581
582 div.appendChild(resultPanel.element());
583 KorAP.Panel = KorAP.Panel || {};
584 KorAP.Panel['result'] = resultPanel;
585
586 // Register plugin afterwards
587 var manager = pluginServerClass.create();
588
589 manager.register({
590 name : 'ResultPlugin',
591 embed : [{
592 panel : 'result',
593 title : 'Dosomething',
594 onClick : {
595 template : 'test'
596 }
597 }]
598 });
599
600 expect(manager.buttonGroup('result').length).toEqual(0);
Akron37ea1192021-07-28 10:40:14 +0200601 expect(KorAP.Panel['result'].actions().element().innerHTML).toContain('Dosomething');
hebasta043e96f2019-11-28 12:33:00 +0100602
603 // Clean up
604 KorAP.Panel['result'] = undefined;
605 manager.destroy();
Akron45308ce2020-08-28 14:10:23 +0200606 });
hebasta043e96f2019-11-28 12:33:00 +0100607
608 it('Plugin is registered first: Buttons should be added to panel and cleared', function () {
609
610 // Register plugin first
611 KorAP.Plugin = pluginServerClass.create();
612
613 KorAP.Plugin.register({
614 name : 'ResultPlugin',
615 embed : [{
616 panel : 'result',
617 title : 'Dosomething',
618 onClick : {
619 template : 'test'
620 }
621 }]
622 });
623
624 expect(KorAP.Plugin.buttonGroup('result').length).toEqual(1);
625
626 var resultPanel = resultPanelClass.create();
627 var div = document.createElement('div');
628 div.appendChild(resultPanel.element());
629 KorAP.Panel = KorAP.Panel || {};
630 KorAP.Panel['result'] = resultPanel;
631 expect(KorAP.Plugin.buttonGroup('result').length).toEqual(0);
Akron37ea1192021-07-28 10:40:14 +0200632 expect(KorAP.Panel['result'].actions().element().innerHTML).toContain('Dosomething');
hebasta043e96f2019-11-28 12:33:00 +0100633
634 // Clean up
635 KorAP.Panel['result'] = undefined;
636 KorAP.Plugin.destroy();
637 KorAP.Plugin = undefined;
638 });
639 });
Akronfec66a32020-08-28 13:01:14 +0200640
641 describe('KorAP.Plugin communications', function () {
642 it('should receive messages', function () {
643 var manager = pluginServerClass.create();
Akronbb891982020-10-05 16:07:18 +0200644 var id = manager.addService({"name":'Example 1', "src":'about:blank'});
Akronfec66a32020-08-28 13:01:14 +0200645 expect(id).toMatch(/^id-/);
Akronfec66a32020-08-28 13:01:14 +0200646 var temp = KorAP.koralQuery;
647 KorAP.koralQuery = { "@type" : "koral:test" };
Akronfec66a32020-08-28 13:01:14 +0200648 let data = {
649 "originID" : id,
650 "action" : "get",
651 "key" : "KQ"
652 };
Akronfec66a32020-08-28 13:01:14 +0200653 manager._receiveMsg({
654 "data" : data
655 });
Akronfec66a32020-08-28 13:01:14 +0200656 manager.destroy();
Akronfec66a32020-08-28 13:01:14 +0200657 expect(data.value["@type"]).toEqual("koral:test");
Akronfec66a32020-08-28 13:01:14 +0200658 // Recreate initial state
659 KorAP.koralQuery = temp;
660 });
661
Akronfec66a32020-08-28 13:01:14 +0200662 it('should add to pipe', function () {
663 var manager = pluginServerClass.create();
Akronfec66a32020-08-28 13:01:14 +0200664 var temp = KorAP.Pipe;
665 KorAP.Pipe = pipeClass.create();
Akronfec66a32020-08-28 13:01:14 +0200666 expect(KorAP.Pipe.toString()).toEqual("");
667
Akronbb891982020-10-05 16:07:18 +0200668 var id = manager.addService({"name":'Example 2', "src":'about:blank'});
Akronfec66a32020-08-28 13:01:14 +0200669 expect(id).toMatch(/^id-/);
Akronfec66a32020-08-28 13:01:14 +0200670 manager._receiveMsg({
671 "data" : {
672 "originID" : id,
673 "action" : "pipe",
674 "job" : "add",
675 "service" : "https://pipe-service.de"
676 }
677 });
Akronfec66a32020-08-28 13:01:14 +0200678 expect(KorAP.Pipe.toString()).toEqual("https://pipe-service.de");
Akronfec66a32020-08-28 13:01:14 +0200679 manager._receiveMsg({
680 "data" : {
681 "originID" : id,
682 "action" : "pipe",
683 "job" : "add",
684 "service" : "https://pipe-service-2.de"
685 }
686 });
Akronfec66a32020-08-28 13:01:14 +0200687 expect(KorAP.Pipe.toString()).toEqual("https://pipe-service.de,https://pipe-service-2.de");
Akronfec66a32020-08-28 13:01:14 +0200688 manager._receiveMsg({
689 "data" : {
690 "originID" : id,
691 "action" : "pipe",
692 "job" : "del",
693 "service" : "https://pipe-service.de"
694 }
695 });
Akronfec66a32020-08-28 13:01:14 +0200696 expect(KorAP.Pipe.toString()).toEqual("https://pipe-service-2.de");
Akronfec66a32020-08-28 13:01:14 +0200697 manager.destroy();
Akronfec66a32020-08-28 13:01:14 +0200698 // Recreate initial state
699 KorAP.Pipe = temp;
700 });
Akron45308ce2020-08-28 14:10:23 +0200701
Akron26d57f22021-09-10 16:48:57 +0200702 it('should reply to query information requests (queryform)', function () {
Akron45308ce2020-08-28 14:10:23 +0200703 var manager = pluginServerClass.create();
Akronbb891982020-10-05 16:07:18 +0200704 var id = manager.addService({"name":'Service', "src":'about:blank'});
Akron45308ce2020-08-28 14:10:23 +0200705 expect(id).toMatch(/^id-/);
706 var temp = KorAP.vc;
707 // Create form for query form information
708 let f = document.createElement('form');
709 var qfield = f.addE('input');
710 qfield.setAttribute("id", "q-field");
711 qfield.value = "[orth=Baum]";
712 var qlfield = f.addE('select');
713 qlfield.setAttribute("id", "ql-field");
714 qlfield.addE('option').setAttribute('value', 'cosmas-2');
715 qlfield.addE('option').setAttribute('value', 'poliqarp');
716 qlfield.selectedIndex = 1;
717
718 KorAP.vc = vcClass.create().fromJson({
719 "key" : "title",
720 "type" : "type:regex",
721 "value" : "[^b]ee.+?",
722 "@type" : "koral:doc"
723 });
724 // console.log(KorAP.vc.toQuery());
725
726 document.body.appendChild(f);
727 let data = {
728 "originID" : id,
729 "action" : "get",
730 "key" : "QueryForm"
731 };
732 manager._receiveMsg({
733 "data" : data
734 });
735 manager.destroy();
736 expect(data.value["q"]).toEqual("[orth=Baum]");
737 expect(data.value["ql"]).toEqual("poliqarp");
738 expect(data.value["cq"]).toEqual("title = /[^b]ee.+?/");
Akron26d57f22021-09-10 16:48:57 +0200739
Akron45308ce2020-08-28 14:10:23 +0200740 // Recreate initial state
741 KorAP.vc = temp;
742 document.body.removeChild(f);
743 });
Akron26d57f22021-09-10 16:48:57 +0200744
745 it('should reply to query information requests (pagination)', function () {
746 var manager = pluginServerClass.create();
747 var id = manager.addService({"name":'Service', "src":'about:blank'});
748 expect(id).toMatch(/^id-/);
749
750 // Create pagination element for pagination information
751 let p = document.createElement('div');
752 p.setAttribute('id', 'pagination')
753 p.setAttribute('data-page',3);
754 p.setAttribute('data-total',30);
755 p.setAttribute('data-count',25);
756
757 document.body.appendChild(p);
758
759 let data = {
760 "originID" : id,
761 "action" : "get",
762 "key" : "Pagination"
763 };
764 manager._receiveMsg({
765 "data" : data
766 });
767 manager.destroy();
768 expect(data.value["count"]).toEqual(25);
769 expect(data.value["page"]).toEqual(3);
770 expect(data.value["total"]).toEqual(30);
771
772 // Recreate initial state
773 document.body.removeChild(p);
774 });
Akronfec66a32020-08-28 13:01:14 +0200775 });
Akronb43c8c62018-07-04 18:27:28 +0200776});