blob: acadeac1ef3d36fec051d687fa2872083131d2da [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',
256 onClick : {
Akronda32e7a2021-11-16 17:28:57 +0100257 state : 'check',
Akrona70b6892021-11-04 14:23:24 +0100258 template : 'about:blank',
259 action : 'toggle',
260 'default' : false
261 }
262 }]
263 });
264
265 let b = p.actions().element().firstChild;
266 expect(b.hasAttribute("data-icon")).toBeFalsy();
267 expect(b.hasAttribute("cls")).toBeFalsy();
268 expect(b.getAttribute("title")).toEqual("Glemm");
269 expect(b.firstChild.classList.contains('button-icon')).toBeTruthy();
270 expect(b.firstChild.classList.contains('check')).toBeTruthy();
271 expect(b.firstChild.classList.contains('checked')).toBeFalsy();
272
273 expect(p.element().querySelectorAll("iframe").length).toEqual(0);
274
Akronda32e7a2021-11-16 17:28:57 +0100275 expect(manager.states().toString()).toEqual("");
276
Akrona70b6892021-11-04 14:23:24 +0100277 b.click();
278
Akronda32e7a2021-11-16 17:28:57 +0100279 expect(manager.states().toString()).toEqual("\"check\":true");
280
Akrona70b6892021-11-04 14:23:24 +0100281 expect(b.getAttribute("title")).toEqual("Glemm");
282 expect(b.firstChild.classList.contains('button-icon')).toBeTruthy();
283 expect(b.firstChild.classList.contains('check')).toBeTruthy();
284 expect(b.firstChild.classList.contains('checked')).toBeTruthy();
285
286 // Check with true default
287 p = KorAP.Panel["result"] = panelClass.create();
288
289 manager = pluginServerClass.create();
290
291 manager.register({
292 name : 'Check',
293 embed : [{
294 panel : 'result',
295 title : 'Glemm',
296 onClick : {
297 template : 'about:blank',
298 action : 'toggle',
299 'default' : true
300 }
301 }]
302 });
303
304 b = p.actions().element().firstChild;
305 expect(b.hasAttribute("data-icon")).toBeFalsy();
306 expect(b.hasAttribute("cls")).toBeFalsy();
307 expect(b.getAttribute("title")).toEqual("Glemm");
308 expect(b.firstChild.classList.contains('button-icon')).toBeTruthy();
309 expect(b.firstChild.classList.contains('check')).toBeTruthy();
310 expect(b.firstChild.classList.contains('checked')).toBeTruthy();
311
312 manager.destroy();
313 KorAP.Panel["result"] = undefined;
314 });
315
316
Akron3d013802020-10-07 15:03:38 +0200317 it('should alert on plugin info (1)', function () {
318
319 let alertMsg;
320 spyOn(window, 'alert').and.callFake(function(msg) {
321 alertMsg = msg;
322 });
323
324 let p = KorAP.Panel["result"] = panelClass.create();
325
326 let manager = pluginServerClass.create();
327
328 manager.register({
329 name : 'Check',
330 embed : [{
331 panel : 'result',
332 title : 'Add',
333 onClick : {
334 template : 'about:blank',
335 action : 'setWidget'
336 }
337 }]
338 });
339
340 expect(alertMsg).toBeUndefined();
341
Akron37ea1192021-07-28 10:40:14 +0200342 let b = p.actions().element().firstChild;
Akron3d013802020-10-07 15:03:38 +0200343 b.click();
344
345 // This may only be temporary and should open the plugin window instead
346 p.element().querySelector("span.plugin").click();
347
348 expect(alertMsg).toEqual('Check');
349
350 manager.destroy();
351 KorAP.Panel["result"] = undefined;
352 });
353
354
355 it('should alert on plugin info (2)', function () {
356
357 let alertMsg;
358 spyOn(window, 'alert').and.callFake(function(msg) {
359 alertMsg = msg;
360 });
361
362 let p = KorAP.Panel["result"] = panelClass.create();
363
364 let manager = pluginServerClass.create();
365
366 manager.register({
367 name : 'Check',
368 desc : 'Simple Check plugin',
369 embed : [{
370 panel : 'result',
371 title : 'Add',
372 onClick : {
373 template : 'about:blank',
374 action : 'setWidget'
375 }
376 }]
377 });
378
379 expect(alertMsg).toBeUndefined();
380
Akron37ea1192021-07-28 10:40:14 +0200381 let b = p.actions().element().firstChild;
Akron3d013802020-10-07 15:03:38 +0200382 b.click();
383
384 // This may only be temporary and should open the plugin window instead
385 p.element().querySelector("span.plugin").click();
386
387 expect(alertMsg).toEqual("Check\n\nSimple Check plugin");
388
389 manager.destroy();
390 KorAP.Panel["result"] = undefined;
391 });
392
393
Akronfb11a962020-10-05 12:12:55 +0200394 it('should accept widget permissions', function () {
395 let p = KorAP.Panel["result"] = panelClass.create();
396
397 let manager = pluginServerClass.create();
398
399 manager.register({
400 name : 'Check',
401 embed : [{
402 panel : 'result',
403 title : 'Add',
404 onClick : {
405 template : 'about:blank',
406 action : 'addWidget',
Akronce0d8822020-10-05 16:25:40 +0200407 permissions: ['scripts', 'forms', 'all']
Akronfb11a962020-10-05 12:12:55 +0200408 }
409 }]
410 });
411
Akron37ea1192021-07-28 10:40:14 +0200412 let b = p.actions().element().firstChild;
Akronfb11a962020-10-05 12:12:55 +0200413 b.click();
414 expect(p.element().querySelectorAll("iframe").length).toEqual(1);
415 expect(p.element().querySelector("iframe").getAttribute('sandbox')).toEqual('allow-forms allow-scripts');
416 });
Akronb43c8c62018-07-04 18:27:28 +0200417 });
Akron2d0d96d2019-11-18 19:49:50 +0100418
Akronb43c8c62018-07-04 18:27:28 +0200419 describe('KorAP.Plugin.Widget', function () {
420 it('should be initializable', function () {
Akron22598cd2019-12-09 14:59:03 +0100421 expect(function () { widgetClass.create() }).toThrow(new Error("Service not well defined"));
Akron56a11af2018-07-27 18:28:45 +0200422
Akronbb891982020-10-05 16:07:18 +0200423 widget = widgetClass.create({"name" : "Test", "src":"https://example", "id":56});
Akronb43c8c62018-07-04 18:27:28 +0200424 expect(widget).toBeTruthy();
Akron56a11af2018-07-27 18:28:45 +0200425 expect(widget.id).toEqual(56);
426 expect(widget.name).toEqual("Test");
427 expect(widget.src).toEqual("https://example");
428 });
429
430 it('should create a view element', function () {
Akronbb891982020-10-05 16:07:18 +0200431 var widget = widgetClass.create({
432 "name":"Test",
433 "src":"https://example",
434 "id":56,
Akronce0d8822020-10-05 16:25:40 +0200435 "permissions":["scripts","forms"]
Akronbb891982020-10-05 16:07:18 +0200436 });
Akron56a11af2018-07-27 18:28:45 +0200437 var we = widget.element();
438
439 expect(we.tagName).toEqual("DIV");
440 expect(we.classList.contains('view')).toBeTruthy();
441 expect(we.classList.contains('widget')).toBeTruthy();
442
443 var iframe = we.firstChild;
444 expect(iframe.tagName).toEqual("IFRAME");
Akronfb11a962020-10-05 12:12:55 +0200445 expect(iframe.getAttribute("sandbox")).toEqual("allow-forms allow-scripts");
Akron56a11af2018-07-27 18:28:45 +0200446 expect(iframe.getAttribute("src")).toEqual("https://example");
447 expect(iframe.getAttribute("name")).toEqual("56");
Akronfb11a962020-10-05 12:12:55 +0200448
Akron56a11af2018-07-27 18:28:45 +0200449 var btn = we.lastChild;
450 expect(btn.classList.contains("button-group")).toBeTruthy();
451 expect(btn.classList.contains("button-view")).toBeTruthy();
452 expect(btn.classList.contains("widget")).toBeTruthy();
453
454 expect(btn.firstChild.tagName).toEqual("SPAN");
455 expect(btn.firstChild.classList.contains("button-icon")).toBeTruthy();
456 expect(btn.firstChild.classList.contains("close")).toBeTruthy();
457 expect(btn.firstChild.firstChild.tagName).toEqual("SPAN");
458
459 expect(btn.lastChild.tagName).toEqual("SPAN");
460 expect(btn.lastChild.classList.contains("button-icon")).toBeTruthy();
461 expect(btn.lastChild.classList.contains("plugin")).toBeTruthy();
462 expect(btn.lastChild.firstChild.tagName).toEqual("SPAN");
463 expect(btn.lastChild.textContent).toEqual("Test");
464 })
Akronfb11a962020-10-05 12:12:55 +0200465
Akron56a11af2018-07-27 18:28:45 +0200466 it('should be resizable', function () {
Akronbb891982020-10-05 16:07:18 +0200467 var widget = widgetClass.create({"name":"Test", "src":"https://example", "id":56});
Akron56a11af2018-07-27 18:28:45 +0200468 var iframe = widget.show();
469 expect(iframe.style.height).toEqual('0px');
470 widget.resize({ height : 9 });
471 expect(iframe.style.height).toEqual('9px');
Akronb43c8c62018-07-04 18:27:28 +0200472 });
Akron3d9ce5e2020-10-01 15:18:36 +0200473
474 it('should be minimizable', function () {
Akronbb891982020-10-05 16:07:18 +0200475 var widget = widgetClass.create({"name":"Test", "src":"https://example", "id":56});
Akron3d9ce5e2020-10-01 15:18:36 +0200476 var we = widget.element();
477 expect(we.classList.contains('show')).toBeTruthy();
478 widget.minimize();
479 expect(we.classList.contains('show')).toBeFalsy();
480 });
Akronb43c8c62018-07-04 18:27:28 +0200481 });
Akron2d0d96d2019-11-18 19:49:50 +0100482
Akron22598cd2019-12-09 14:59:03 +0100483 describe('KorAP.Plugin.Service', function () {
484 it('should be initializable', function () {
485 expect(function () { serviceClass.create() }).toThrow(new Error("Service not well defined"));
486
Akronbb891982020-10-05 16:07:18 +0200487 let service = serviceClass.create({"name":"Test", "src":"https://example", "id":56});
Akron22598cd2019-12-09 14:59:03 +0100488 expect(service).toBeTruthy();
489 expect(service.id).toEqual(56);
490 expect(service.name).toEqual("Test");
491 expect(service.src).toEqual("https://example");
492 });
493
494 it('should be loadable', function () {
Akronbb891982020-10-05 16:07:18 +0200495 let service = serviceClass.create({"name":"Test", "src":"https://example", "id":56});
Akron22598cd2019-12-09 14:59:03 +0100496 expect(service).toBeTruthy();
497
498 let i = service.load();
499 expect(i.tagName).toEqual("IFRAME");
500 expect(i.getAttribute("allowTransparency")).toEqual("true");
501 expect(i.getAttribute("frameborder")).toEqual(''+0);
502 expect(i.getAttribute("name")).toEqual(''+service.id);
503 expect(i.getAttribute("src")).toEqual(service.src);
504 });
505 });
506
Akron2d0d96d2019-11-18 19:49:50 +0100507 describe('KorAP.Plugin.QueryPanel', function () {
508 it('should establish a query plugin', function () {
509 var queryPanel = queryPanelClass.create();
510
511 var div = document.createElement('div');
512
513 div.appendChild(queryPanel.element());
514 KorAP.Panel = KorAP.Panel || {};
515 KorAP.Panel['query'] = queryPanel;
516
517 // Register plugin afterwards
518 var manager = pluginServerClass.create();
519
520 manager.register({
521 name : 'Check',
522 embed : [{
523 panel : 'query',
524 title : 'Translate',
525 onClick : {
526 template : 'test'
527 }
528 }]
529 });
530
531 expect(manager.buttonGroup('query').length).toEqual(0);
532
533 // Clean up
534 KorAP.Panel['query'] = undefined;
535 manager.destroy();
536 });
hebastaf6adf8d2019-11-26 14:04:10 +0100537
538 it('Plugin buttons should be cleared after adding to panel', function () {
539
540 // Register plugin first
541 KorAP.Plugin = pluginServerClass.create();
542
543 KorAP.Plugin.register({
544 name : 'Check',
545 embed : [{
546 panel : 'query',
547 title : 'Translate',
548 onClick : {
549 template : 'test'
550 }
551 }]
552 });
553
554
555 var queryPanel = queryPanelClass.create();
556 var div = document.createElement('div');
557
558 div.appendChild(queryPanel.element());
559 KorAP.Panel = KorAP.Panel || {};
560 KorAP.Panel['query'] = queryPanel;
561 expect(KorAP.Plugin.buttonGroup('query').length).toEqual(0);
562
563 // Clean up
564 KorAP.Panel['query'] = undefined;
565 KorAP.Plugin.destroy();
566 KorAP.Plugin = undefined;
567 });
Akron2d0d96d2019-11-18 19:49:50 +0100568 });
hebasta043e96f2019-11-28 12:33:00 +0100569
Akron45308ce2020-08-28 14:10:23 +0200570 describe('KorAP.Plugin.ResultPanel', function () {
hebasta043e96f2019-11-28 12:33:00 +0100571 it('Plugin is registered second: buttons should be added to panel', function () {
572
573 var resultPanel = resultPanelClass.create();
574 resultPanel.addAlignAction();
575 var div = document.createElement('div');
576
577 div.appendChild(resultPanel.element());
578 KorAP.Panel = KorAP.Panel || {};
579 KorAP.Panel['result'] = resultPanel;
580
581 // Register plugin afterwards
582 var manager = pluginServerClass.create();
583
584 manager.register({
585 name : 'ResultPlugin',
586 embed : [{
587 panel : 'result',
588 title : 'Dosomething',
589 onClick : {
590 template : 'test'
591 }
592 }]
593 });
594
595 expect(manager.buttonGroup('result').length).toEqual(0);
Akron37ea1192021-07-28 10:40:14 +0200596 expect(KorAP.Panel['result'].actions().element().innerHTML).toContain('Dosomething');
hebasta043e96f2019-11-28 12:33:00 +0100597
598 // Clean up
599 KorAP.Panel['result'] = undefined;
600 manager.destroy();
Akron45308ce2020-08-28 14:10:23 +0200601 });
hebasta043e96f2019-11-28 12:33:00 +0100602
603 it('Plugin is registered first: Buttons should be added to panel and cleared', function () {
604
605 // Register plugin first
606 KorAP.Plugin = pluginServerClass.create();
607
608 KorAP.Plugin.register({
609 name : 'ResultPlugin',
610 embed : [{
611 panel : 'result',
612 title : 'Dosomething',
613 onClick : {
614 template : 'test'
615 }
616 }]
617 });
618
619 expect(KorAP.Plugin.buttonGroup('result').length).toEqual(1);
620
621 var resultPanel = resultPanelClass.create();
622 var div = document.createElement('div');
623 div.appendChild(resultPanel.element());
624 KorAP.Panel = KorAP.Panel || {};
625 KorAP.Panel['result'] = resultPanel;
626 expect(KorAP.Plugin.buttonGroup('result').length).toEqual(0);
Akron37ea1192021-07-28 10:40:14 +0200627 expect(KorAP.Panel['result'].actions().element().innerHTML).toContain('Dosomething');
hebasta043e96f2019-11-28 12:33:00 +0100628
629 // Clean up
630 KorAP.Panel['result'] = undefined;
631 KorAP.Plugin.destroy();
632 KorAP.Plugin = undefined;
633 });
634 });
Akronfec66a32020-08-28 13:01:14 +0200635
636 describe('KorAP.Plugin communications', function () {
637 it('should receive messages', function () {
638 var manager = pluginServerClass.create();
Akronbb891982020-10-05 16:07:18 +0200639 var id = manager.addService({"name":'Example 1', "src":'about:blank'});
Akronfec66a32020-08-28 13:01:14 +0200640 expect(id).toMatch(/^id-/);
Akronfec66a32020-08-28 13:01:14 +0200641 var temp = KorAP.koralQuery;
642 KorAP.koralQuery = { "@type" : "koral:test" };
Akronfec66a32020-08-28 13:01:14 +0200643 let data = {
644 "originID" : id,
645 "action" : "get",
646 "key" : "KQ"
647 };
Akronfec66a32020-08-28 13:01:14 +0200648 manager._receiveMsg({
649 "data" : data
650 });
Akronfec66a32020-08-28 13:01:14 +0200651 manager.destroy();
Akronfec66a32020-08-28 13:01:14 +0200652 expect(data.value["@type"]).toEqual("koral:test");
Akronfec66a32020-08-28 13:01:14 +0200653 // Recreate initial state
654 KorAP.koralQuery = temp;
655 });
656
Akronfec66a32020-08-28 13:01:14 +0200657 it('should add to pipe', function () {
658 var manager = pluginServerClass.create();
Akronfec66a32020-08-28 13:01:14 +0200659 var temp = KorAP.Pipe;
660 KorAP.Pipe = pipeClass.create();
Akronfec66a32020-08-28 13:01:14 +0200661 expect(KorAP.Pipe.toString()).toEqual("");
662
Akronbb891982020-10-05 16:07:18 +0200663 var id = manager.addService({"name":'Example 2', "src":'about:blank'});
Akronfec66a32020-08-28 13:01:14 +0200664 expect(id).toMatch(/^id-/);
Akronfec66a32020-08-28 13:01:14 +0200665 manager._receiveMsg({
666 "data" : {
667 "originID" : id,
668 "action" : "pipe",
669 "job" : "add",
670 "service" : "https://pipe-service.de"
671 }
672 });
Akronfec66a32020-08-28 13:01:14 +0200673 expect(KorAP.Pipe.toString()).toEqual("https://pipe-service.de");
Akronfec66a32020-08-28 13:01:14 +0200674 manager._receiveMsg({
675 "data" : {
676 "originID" : id,
677 "action" : "pipe",
678 "job" : "add",
679 "service" : "https://pipe-service-2.de"
680 }
681 });
Akronfec66a32020-08-28 13:01:14 +0200682 expect(KorAP.Pipe.toString()).toEqual("https://pipe-service.de,https://pipe-service-2.de");
Akronfec66a32020-08-28 13:01:14 +0200683 manager._receiveMsg({
684 "data" : {
685 "originID" : id,
686 "action" : "pipe",
687 "job" : "del",
688 "service" : "https://pipe-service.de"
689 }
690 });
Akronfec66a32020-08-28 13:01:14 +0200691 expect(KorAP.Pipe.toString()).toEqual("https://pipe-service-2.de");
Akronfec66a32020-08-28 13:01:14 +0200692 manager.destroy();
Akronfec66a32020-08-28 13:01:14 +0200693 // Recreate initial state
694 KorAP.Pipe = temp;
695 });
Akron45308ce2020-08-28 14:10:23 +0200696
Akron26d57f22021-09-10 16:48:57 +0200697 it('should reply to query information requests (queryform)', function () {
Akron45308ce2020-08-28 14:10:23 +0200698 var manager = pluginServerClass.create();
Akronbb891982020-10-05 16:07:18 +0200699 var id = manager.addService({"name":'Service', "src":'about:blank'});
Akron45308ce2020-08-28 14:10:23 +0200700 expect(id).toMatch(/^id-/);
701 var temp = KorAP.vc;
702 // Create form for query form information
703 let f = document.createElement('form');
704 var qfield = f.addE('input');
705 qfield.setAttribute("id", "q-field");
706 qfield.value = "[orth=Baum]";
707 var qlfield = f.addE('select');
708 qlfield.setAttribute("id", "ql-field");
709 qlfield.addE('option').setAttribute('value', 'cosmas-2');
710 qlfield.addE('option').setAttribute('value', 'poliqarp');
711 qlfield.selectedIndex = 1;
712
713 KorAP.vc = vcClass.create().fromJson({
714 "key" : "title",
715 "type" : "type:regex",
716 "value" : "[^b]ee.+?",
717 "@type" : "koral:doc"
718 });
719 // console.log(KorAP.vc.toQuery());
720
721 document.body.appendChild(f);
722 let data = {
723 "originID" : id,
724 "action" : "get",
725 "key" : "QueryForm"
726 };
727 manager._receiveMsg({
728 "data" : data
729 });
730 manager.destroy();
731 expect(data.value["q"]).toEqual("[orth=Baum]");
732 expect(data.value["ql"]).toEqual("poliqarp");
733 expect(data.value["cq"]).toEqual("title = /[^b]ee.+?/");
Akron26d57f22021-09-10 16:48:57 +0200734
Akron45308ce2020-08-28 14:10:23 +0200735 // Recreate initial state
736 KorAP.vc = temp;
737 document.body.removeChild(f);
738 });
Akron26d57f22021-09-10 16:48:57 +0200739
740 it('should reply to query information requests (pagination)', function () {
741 var manager = pluginServerClass.create();
742 var id = manager.addService({"name":'Service', "src":'about:blank'});
743 expect(id).toMatch(/^id-/);
744
745 // Create pagination element for pagination information
746 let p = document.createElement('div');
747 p.setAttribute('id', 'pagination')
748 p.setAttribute('data-page',3);
749 p.setAttribute('data-total',30);
750 p.setAttribute('data-count',25);
751
752 document.body.appendChild(p);
753
754 let data = {
755 "originID" : id,
756 "action" : "get",
757 "key" : "Pagination"
758 };
759 manager._receiveMsg({
760 "data" : data
761 });
762 manager.destroy();
763 expect(data.value["count"]).toEqual(25);
764 expect(data.value["page"]).toEqual(3);
765 expect(data.value["total"]).toEqual(30);
766
767 // Recreate initial state
768 document.body.removeChild(p);
769 });
Akronfec66a32020-08-28 13:01:14 +0200770 });
Akronb43c8c62018-07-04 18:27:28 +0200771});