blob: 973ad16dfc261a20c9760165f2de516c4b87393e [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);
233
234 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('');
Akronba09ed22020-10-01 16:01:45 +0200240
241 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',
256 onClick : {
257 template : 'about:blank',
258 action : 'toggle',
259 'default' : false
260 }
261 }]
262 });
263
264 let b = p.actions().element().firstChild;
265 expect(b.hasAttribute("data-icon")).toBeFalsy();
266 expect(b.hasAttribute("cls")).toBeFalsy();
267 expect(b.getAttribute("title")).toEqual("Glemm");
268 expect(b.firstChild.classList.contains('button-icon')).toBeTruthy();
269 expect(b.firstChild.classList.contains('check')).toBeTruthy();
270 expect(b.firstChild.classList.contains('checked')).toBeFalsy();
271
272 expect(p.element().querySelectorAll("iframe").length).toEqual(0);
273
274 b.click();
275
276 expect(b.getAttribute("title")).toEqual("Glemm");
277 expect(b.firstChild.classList.contains('button-icon')).toBeTruthy();
278 expect(b.firstChild.classList.contains('check')).toBeTruthy();
279 expect(b.firstChild.classList.contains('checked')).toBeTruthy();
280
281 // Check with true default
282 p = KorAP.Panel["result"] = panelClass.create();
283
284 manager = pluginServerClass.create();
285
286 manager.register({
287 name : 'Check',
288 embed : [{
289 panel : 'result',
290 title : 'Glemm',
291 onClick : {
292 template : 'about:blank',
293 action : 'toggle',
294 'default' : true
295 }
296 }]
297 });
298
299 b = p.actions().element().firstChild;
300 expect(b.hasAttribute("data-icon")).toBeFalsy();
301 expect(b.hasAttribute("cls")).toBeFalsy();
302 expect(b.getAttribute("title")).toEqual("Glemm");
303 expect(b.firstChild.classList.contains('button-icon')).toBeTruthy();
304 expect(b.firstChild.classList.contains('check')).toBeTruthy();
305 expect(b.firstChild.classList.contains('checked')).toBeTruthy();
306
307 manager.destroy();
308 KorAP.Panel["result"] = undefined;
309 });
310
311
Akron3d013802020-10-07 15:03:38 +0200312 it('should alert on plugin info (1)', function () {
313
314 let alertMsg;
315 spyOn(window, 'alert').and.callFake(function(msg) {
316 alertMsg = msg;
317 });
318
319 let p = KorAP.Panel["result"] = panelClass.create();
320
321 let manager = pluginServerClass.create();
322
323 manager.register({
324 name : 'Check',
325 embed : [{
326 panel : 'result',
327 title : 'Add',
328 onClick : {
329 template : 'about:blank',
330 action : 'setWidget'
331 }
332 }]
333 });
334
335 expect(alertMsg).toBeUndefined();
336
Akron37ea1192021-07-28 10:40:14 +0200337 let b = p.actions().element().firstChild;
Akron3d013802020-10-07 15:03:38 +0200338 b.click();
339
340 // This may only be temporary and should open the plugin window instead
341 p.element().querySelector("span.plugin").click();
342
343 expect(alertMsg).toEqual('Check');
344
345 manager.destroy();
346 KorAP.Panel["result"] = undefined;
347 });
348
349
350 it('should alert on plugin info (2)', function () {
351
352 let alertMsg;
353 spyOn(window, 'alert').and.callFake(function(msg) {
354 alertMsg = msg;
355 });
356
357 let p = KorAP.Panel["result"] = panelClass.create();
358
359 let manager = pluginServerClass.create();
360
361 manager.register({
362 name : 'Check',
363 desc : 'Simple Check plugin',
364 embed : [{
365 panel : 'result',
366 title : 'Add',
367 onClick : {
368 template : 'about:blank',
369 action : 'setWidget'
370 }
371 }]
372 });
373
374 expect(alertMsg).toBeUndefined();
375
Akron37ea1192021-07-28 10:40:14 +0200376 let b = p.actions().element().firstChild;
Akron3d013802020-10-07 15:03:38 +0200377 b.click();
378
379 // This may only be temporary and should open the plugin window instead
380 p.element().querySelector("span.plugin").click();
381
382 expect(alertMsg).toEqual("Check\n\nSimple Check plugin");
383
384 manager.destroy();
385 KorAP.Panel["result"] = undefined;
386 });
387
388
Akronfb11a962020-10-05 12:12:55 +0200389 it('should accept widget permissions', function () {
390 let p = KorAP.Panel["result"] = panelClass.create();
391
392 let manager = pluginServerClass.create();
393
394 manager.register({
395 name : 'Check',
396 embed : [{
397 panel : 'result',
398 title : 'Add',
399 onClick : {
400 template : 'about:blank',
401 action : 'addWidget',
Akronce0d8822020-10-05 16:25:40 +0200402 permissions: ['scripts', 'forms', 'all']
Akronfb11a962020-10-05 12:12:55 +0200403 }
404 }]
405 });
406
Akron37ea1192021-07-28 10:40:14 +0200407 let b = p.actions().element().firstChild;
Akronfb11a962020-10-05 12:12:55 +0200408 b.click();
409 expect(p.element().querySelectorAll("iframe").length).toEqual(1);
410 expect(p.element().querySelector("iframe").getAttribute('sandbox')).toEqual('allow-forms allow-scripts');
411 });
Akronb43c8c62018-07-04 18:27:28 +0200412 });
Akron2d0d96d2019-11-18 19:49:50 +0100413
Akronb43c8c62018-07-04 18:27:28 +0200414 describe('KorAP.Plugin.Widget', function () {
415 it('should be initializable', function () {
Akron22598cd2019-12-09 14:59:03 +0100416 expect(function () { widgetClass.create() }).toThrow(new Error("Service not well defined"));
Akron56a11af2018-07-27 18:28:45 +0200417
Akronbb891982020-10-05 16:07:18 +0200418 widget = widgetClass.create({"name" : "Test", "src":"https://example", "id":56});
Akronb43c8c62018-07-04 18:27:28 +0200419 expect(widget).toBeTruthy();
Akron56a11af2018-07-27 18:28:45 +0200420 expect(widget.id).toEqual(56);
421 expect(widget.name).toEqual("Test");
422 expect(widget.src).toEqual("https://example");
423 });
424
425 it('should create a view element', function () {
Akronbb891982020-10-05 16:07:18 +0200426 var widget = widgetClass.create({
427 "name":"Test",
428 "src":"https://example",
429 "id":56,
Akronce0d8822020-10-05 16:25:40 +0200430 "permissions":["scripts","forms"]
Akronbb891982020-10-05 16:07:18 +0200431 });
Akron56a11af2018-07-27 18:28:45 +0200432 var we = widget.element();
433
434 expect(we.tagName).toEqual("DIV");
435 expect(we.classList.contains('view')).toBeTruthy();
436 expect(we.classList.contains('widget')).toBeTruthy();
437
438 var iframe = we.firstChild;
439 expect(iframe.tagName).toEqual("IFRAME");
Akronfb11a962020-10-05 12:12:55 +0200440 expect(iframe.getAttribute("sandbox")).toEqual("allow-forms allow-scripts");
Akron56a11af2018-07-27 18:28:45 +0200441 expect(iframe.getAttribute("src")).toEqual("https://example");
442 expect(iframe.getAttribute("name")).toEqual("56");
Akronfb11a962020-10-05 12:12:55 +0200443
Akron56a11af2018-07-27 18:28:45 +0200444 var btn = we.lastChild;
445 expect(btn.classList.contains("button-group")).toBeTruthy();
446 expect(btn.classList.contains("button-view")).toBeTruthy();
447 expect(btn.classList.contains("widget")).toBeTruthy();
448
449 expect(btn.firstChild.tagName).toEqual("SPAN");
450 expect(btn.firstChild.classList.contains("button-icon")).toBeTruthy();
451 expect(btn.firstChild.classList.contains("close")).toBeTruthy();
452 expect(btn.firstChild.firstChild.tagName).toEqual("SPAN");
453
454 expect(btn.lastChild.tagName).toEqual("SPAN");
455 expect(btn.lastChild.classList.contains("button-icon")).toBeTruthy();
456 expect(btn.lastChild.classList.contains("plugin")).toBeTruthy();
457 expect(btn.lastChild.firstChild.tagName).toEqual("SPAN");
458 expect(btn.lastChild.textContent).toEqual("Test");
459 })
Akronfb11a962020-10-05 12:12:55 +0200460
Akron56a11af2018-07-27 18:28:45 +0200461 it('should be resizable', function () {
Akronbb891982020-10-05 16:07:18 +0200462 var widget = widgetClass.create({"name":"Test", "src":"https://example", "id":56});
Akron56a11af2018-07-27 18:28:45 +0200463 var iframe = widget.show();
464 expect(iframe.style.height).toEqual('0px');
465 widget.resize({ height : 9 });
466 expect(iframe.style.height).toEqual('9px');
Akronb43c8c62018-07-04 18:27:28 +0200467 });
Akron3d9ce5e2020-10-01 15:18:36 +0200468
469 it('should be minimizable', function () {
Akronbb891982020-10-05 16:07:18 +0200470 var widget = widgetClass.create({"name":"Test", "src":"https://example", "id":56});
Akron3d9ce5e2020-10-01 15:18:36 +0200471 var we = widget.element();
472 expect(we.classList.contains('show')).toBeTruthy();
473 widget.minimize();
474 expect(we.classList.contains('show')).toBeFalsy();
475 });
Akronb43c8c62018-07-04 18:27:28 +0200476 });
Akron2d0d96d2019-11-18 19:49:50 +0100477
Akron22598cd2019-12-09 14:59:03 +0100478 describe('KorAP.Plugin.Service', function () {
479 it('should be initializable', function () {
480 expect(function () { serviceClass.create() }).toThrow(new Error("Service not well defined"));
481
Akronbb891982020-10-05 16:07:18 +0200482 let service = serviceClass.create({"name":"Test", "src":"https://example", "id":56});
Akron22598cd2019-12-09 14:59:03 +0100483 expect(service).toBeTruthy();
484 expect(service.id).toEqual(56);
485 expect(service.name).toEqual("Test");
486 expect(service.src).toEqual("https://example");
487 });
488
489 it('should be loadable', function () {
Akronbb891982020-10-05 16:07:18 +0200490 let service = serviceClass.create({"name":"Test", "src":"https://example", "id":56});
Akron22598cd2019-12-09 14:59:03 +0100491 expect(service).toBeTruthy();
492
493 let i = service.load();
494 expect(i.tagName).toEqual("IFRAME");
495 expect(i.getAttribute("allowTransparency")).toEqual("true");
496 expect(i.getAttribute("frameborder")).toEqual(''+0);
497 expect(i.getAttribute("name")).toEqual(''+service.id);
498 expect(i.getAttribute("src")).toEqual(service.src);
499 });
500 });
501
Akron2d0d96d2019-11-18 19:49:50 +0100502 describe('KorAP.Plugin.QueryPanel', function () {
503 it('should establish a query plugin', function () {
504 var queryPanel = queryPanelClass.create();
505
506 var div = document.createElement('div');
507
508 div.appendChild(queryPanel.element());
509 KorAP.Panel = KorAP.Panel || {};
510 KorAP.Panel['query'] = queryPanel;
511
512 // Register plugin afterwards
513 var manager = pluginServerClass.create();
514
515 manager.register({
516 name : 'Check',
517 embed : [{
518 panel : 'query',
519 title : 'Translate',
520 onClick : {
521 template : 'test'
522 }
523 }]
524 });
525
526 expect(manager.buttonGroup('query').length).toEqual(0);
527
528 // Clean up
529 KorAP.Panel['query'] = undefined;
530 manager.destroy();
531 });
hebastaf6adf8d2019-11-26 14:04:10 +0100532
533 it('Plugin buttons should be cleared after adding to panel', function () {
534
535 // Register plugin first
536 KorAP.Plugin = pluginServerClass.create();
537
538 KorAP.Plugin.register({
539 name : 'Check',
540 embed : [{
541 panel : 'query',
542 title : 'Translate',
543 onClick : {
544 template : 'test'
545 }
546 }]
547 });
548
549
550 var queryPanel = queryPanelClass.create();
551 var div = document.createElement('div');
552
553 div.appendChild(queryPanel.element());
554 KorAP.Panel = KorAP.Panel || {};
555 KorAP.Panel['query'] = queryPanel;
556 expect(KorAP.Plugin.buttonGroup('query').length).toEqual(0);
557
558 // Clean up
559 KorAP.Panel['query'] = undefined;
560 KorAP.Plugin.destroy();
561 KorAP.Plugin = undefined;
562 });
Akron2d0d96d2019-11-18 19:49:50 +0100563 });
hebasta043e96f2019-11-28 12:33:00 +0100564
Akron45308ce2020-08-28 14:10:23 +0200565 describe('KorAP.Plugin.ResultPanel', function () {
hebasta043e96f2019-11-28 12:33:00 +0100566 it('Plugin is registered second: buttons should be added to panel', function () {
567
568 var resultPanel = resultPanelClass.create();
569 resultPanel.addAlignAction();
570 var div = document.createElement('div');
571
572 div.appendChild(resultPanel.element());
573 KorAP.Panel = KorAP.Panel || {};
574 KorAP.Panel['result'] = resultPanel;
575
576 // Register plugin afterwards
577 var manager = pluginServerClass.create();
578
579 manager.register({
580 name : 'ResultPlugin',
581 embed : [{
582 panel : 'result',
583 title : 'Dosomething',
584 onClick : {
585 template : 'test'
586 }
587 }]
588 });
589
590 expect(manager.buttonGroup('result').length).toEqual(0);
Akron37ea1192021-07-28 10:40:14 +0200591 expect(KorAP.Panel['result'].actions().element().innerHTML).toContain('Dosomething');
hebasta043e96f2019-11-28 12:33:00 +0100592
593 // Clean up
594 KorAP.Panel['result'] = undefined;
595 manager.destroy();
Akron45308ce2020-08-28 14:10:23 +0200596 });
hebasta043e96f2019-11-28 12:33:00 +0100597
598 it('Plugin is registered first: Buttons should be added to panel and cleared', function () {
599
600 // Register plugin first
601 KorAP.Plugin = pluginServerClass.create();
602
603 KorAP.Plugin.register({
604 name : 'ResultPlugin',
605 embed : [{
606 panel : 'result',
607 title : 'Dosomething',
608 onClick : {
609 template : 'test'
610 }
611 }]
612 });
613
614 expect(KorAP.Plugin.buttonGroup('result').length).toEqual(1);
615
616 var resultPanel = resultPanelClass.create();
617 var div = document.createElement('div');
618 div.appendChild(resultPanel.element());
619 KorAP.Panel = KorAP.Panel || {};
620 KorAP.Panel['result'] = resultPanel;
621 expect(KorAP.Plugin.buttonGroup('result').length).toEqual(0);
Akron37ea1192021-07-28 10:40:14 +0200622 expect(KorAP.Panel['result'].actions().element().innerHTML).toContain('Dosomething');
hebasta043e96f2019-11-28 12:33:00 +0100623
624 // Clean up
625 KorAP.Panel['result'] = undefined;
626 KorAP.Plugin.destroy();
627 KorAP.Plugin = undefined;
628 });
629 });
Akronfec66a32020-08-28 13:01:14 +0200630
631 describe('KorAP.Plugin communications', function () {
632 it('should receive messages', function () {
633 var manager = pluginServerClass.create();
Akronbb891982020-10-05 16:07:18 +0200634 var id = manager.addService({"name":'Example 1', "src":'about:blank'});
Akronfec66a32020-08-28 13:01:14 +0200635 expect(id).toMatch(/^id-/);
Akronfec66a32020-08-28 13:01:14 +0200636 var temp = KorAP.koralQuery;
637 KorAP.koralQuery = { "@type" : "koral:test" };
Akronfec66a32020-08-28 13:01:14 +0200638 let data = {
639 "originID" : id,
640 "action" : "get",
641 "key" : "KQ"
642 };
Akronfec66a32020-08-28 13:01:14 +0200643 manager._receiveMsg({
644 "data" : data
645 });
Akronfec66a32020-08-28 13:01:14 +0200646 manager.destroy();
Akronfec66a32020-08-28 13:01:14 +0200647 expect(data.value["@type"]).toEqual("koral:test");
Akronfec66a32020-08-28 13:01:14 +0200648 // Recreate initial state
649 KorAP.koralQuery = temp;
650 });
651
Akronfec66a32020-08-28 13:01:14 +0200652 it('should add to pipe', function () {
653 var manager = pluginServerClass.create();
Akronfec66a32020-08-28 13:01:14 +0200654 var temp = KorAP.Pipe;
655 KorAP.Pipe = pipeClass.create();
Akronfec66a32020-08-28 13:01:14 +0200656 expect(KorAP.Pipe.toString()).toEqual("");
657
Akronbb891982020-10-05 16:07:18 +0200658 var id = manager.addService({"name":'Example 2', "src":'about:blank'});
Akronfec66a32020-08-28 13:01:14 +0200659 expect(id).toMatch(/^id-/);
Akronfec66a32020-08-28 13:01:14 +0200660 manager._receiveMsg({
661 "data" : {
662 "originID" : id,
663 "action" : "pipe",
664 "job" : "add",
665 "service" : "https://pipe-service.de"
666 }
667 });
Akronfec66a32020-08-28 13:01:14 +0200668 expect(KorAP.Pipe.toString()).toEqual("https://pipe-service.de");
Akronfec66a32020-08-28 13:01:14 +0200669 manager._receiveMsg({
670 "data" : {
671 "originID" : id,
672 "action" : "pipe",
673 "job" : "add",
674 "service" : "https://pipe-service-2.de"
675 }
676 });
Akronfec66a32020-08-28 13:01:14 +0200677 expect(KorAP.Pipe.toString()).toEqual("https://pipe-service.de,https://pipe-service-2.de");
Akronfec66a32020-08-28 13:01:14 +0200678 manager._receiveMsg({
679 "data" : {
680 "originID" : id,
681 "action" : "pipe",
682 "job" : "del",
683 "service" : "https://pipe-service.de"
684 }
685 });
Akronfec66a32020-08-28 13:01:14 +0200686 expect(KorAP.Pipe.toString()).toEqual("https://pipe-service-2.de");
Akronfec66a32020-08-28 13:01:14 +0200687 manager.destroy();
Akronfec66a32020-08-28 13:01:14 +0200688 // Recreate initial state
689 KorAP.Pipe = temp;
690 });
Akron45308ce2020-08-28 14:10:23 +0200691
Akron26d57f22021-09-10 16:48:57 +0200692 it('should reply to query information requests (queryform)', function () {
Akron45308ce2020-08-28 14:10:23 +0200693 var manager = pluginServerClass.create();
Akronbb891982020-10-05 16:07:18 +0200694 var id = manager.addService({"name":'Service', "src":'about:blank'});
Akron45308ce2020-08-28 14:10:23 +0200695 expect(id).toMatch(/^id-/);
696 var temp = KorAP.vc;
697 // Create form for query form information
698 let f = document.createElement('form');
699 var qfield = f.addE('input');
700 qfield.setAttribute("id", "q-field");
701 qfield.value = "[orth=Baum]";
702 var qlfield = f.addE('select');
703 qlfield.setAttribute("id", "ql-field");
704 qlfield.addE('option').setAttribute('value', 'cosmas-2');
705 qlfield.addE('option').setAttribute('value', 'poliqarp');
706 qlfield.selectedIndex = 1;
707
708 KorAP.vc = vcClass.create().fromJson({
709 "key" : "title",
710 "type" : "type:regex",
711 "value" : "[^b]ee.+?",
712 "@type" : "koral:doc"
713 });
714 // console.log(KorAP.vc.toQuery());
715
716 document.body.appendChild(f);
717 let data = {
718 "originID" : id,
719 "action" : "get",
720 "key" : "QueryForm"
721 };
722 manager._receiveMsg({
723 "data" : data
724 });
725 manager.destroy();
726 expect(data.value["q"]).toEqual("[orth=Baum]");
727 expect(data.value["ql"]).toEqual("poliqarp");
728 expect(data.value["cq"]).toEqual("title = /[^b]ee.+?/");
Akron26d57f22021-09-10 16:48:57 +0200729
Akron45308ce2020-08-28 14:10:23 +0200730 // Recreate initial state
731 KorAP.vc = temp;
732 document.body.removeChild(f);
733 });
Akron26d57f22021-09-10 16:48:57 +0200734
735 it('should reply to query information requests (pagination)', function () {
736 var manager = pluginServerClass.create();
737 var id = manager.addService({"name":'Service', "src":'about:blank'});
738 expect(id).toMatch(/^id-/);
739
740 // Create pagination element for pagination information
741 let p = document.createElement('div');
742 p.setAttribute('id', 'pagination')
743 p.setAttribute('data-page',3);
744 p.setAttribute('data-total',30);
745 p.setAttribute('data-count',25);
746
747 document.body.appendChild(p);
748
749 let data = {
750 "originID" : id,
751 "action" : "get",
752 "key" : "Pagination"
753 };
754 manager._receiveMsg({
755 "data" : data
756 });
757 manager.destroy();
758 expect(data.value["count"]).toEqual(25);
759 expect(data.value["page"]).toEqual(3);
760 expect(data.value["total"]).toEqual(30);
761
762 // Recreate initial state
763 document.body.removeChild(p);
764 });
Akronfec66a32020-08-28 13:01:14 +0200765 });
Akronb43c8c62018-07-04 18:27:28 +0200766});