blob: 966d123ec263e2a492481b96631157debc4eeac0 [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
Akron3d013802020-10-07 15:03:38 +0200246 it('should alert on plugin info (1)', function () {
247
248 let alertMsg;
249 spyOn(window, 'alert').and.callFake(function(msg) {
250 alertMsg = msg;
251 });
252
253 let p = KorAP.Panel["result"] = panelClass.create();
254
255 let manager = pluginServerClass.create();
256
257 manager.register({
258 name : 'Check',
259 embed : [{
260 panel : 'result',
261 title : 'Add',
262 onClick : {
263 template : 'about:blank',
264 action : 'setWidget'
265 }
266 }]
267 });
268
269 expect(alertMsg).toBeUndefined();
270
Akron37ea1192021-07-28 10:40:14 +0200271 let b = p.actions().element().firstChild;
Akron3d013802020-10-07 15:03:38 +0200272 b.click();
273
274 // This may only be temporary and should open the plugin window instead
275 p.element().querySelector("span.plugin").click();
276
277 expect(alertMsg).toEqual('Check');
278
279 manager.destroy();
280 KorAP.Panel["result"] = undefined;
281 });
282
283
284 it('should alert on plugin info (2)', function () {
285
286 let alertMsg;
287 spyOn(window, 'alert').and.callFake(function(msg) {
288 alertMsg = msg;
289 });
290
291 let p = KorAP.Panel["result"] = panelClass.create();
292
293 let manager = pluginServerClass.create();
294
295 manager.register({
296 name : 'Check',
297 desc : 'Simple Check plugin',
298 embed : [{
299 panel : 'result',
300 title : 'Add',
301 onClick : {
302 template : 'about:blank',
303 action : 'setWidget'
304 }
305 }]
306 });
307
308 expect(alertMsg).toBeUndefined();
309
Akron37ea1192021-07-28 10:40:14 +0200310 let b = p.actions().element().firstChild;
Akron3d013802020-10-07 15:03:38 +0200311 b.click();
312
313 // This may only be temporary and should open the plugin window instead
314 p.element().querySelector("span.plugin").click();
315
316 expect(alertMsg).toEqual("Check\n\nSimple Check plugin");
317
318 manager.destroy();
319 KorAP.Panel["result"] = undefined;
320 });
321
322
Akronfb11a962020-10-05 12:12:55 +0200323 it('should accept widget permissions', function () {
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 : 'addWidget',
Akronce0d8822020-10-05 16:25:40 +0200336 permissions: ['scripts', 'forms', 'all']
Akronfb11a962020-10-05 12:12:55 +0200337 }
338 }]
339 });
340
Akron37ea1192021-07-28 10:40:14 +0200341 let b = p.actions().element().firstChild;
Akronfb11a962020-10-05 12:12:55 +0200342 b.click();
343 expect(p.element().querySelectorAll("iframe").length).toEqual(1);
344 expect(p.element().querySelector("iframe").getAttribute('sandbox')).toEqual('allow-forms allow-scripts');
345 });
Akronb43c8c62018-07-04 18:27:28 +0200346 });
Akron2d0d96d2019-11-18 19:49:50 +0100347
Akronb43c8c62018-07-04 18:27:28 +0200348 describe('KorAP.Plugin.Widget', function () {
349 it('should be initializable', function () {
Akron22598cd2019-12-09 14:59:03 +0100350 expect(function () { widgetClass.create() }).toThrow(new Error("Service not well defined"));
Akron56a11af2018-07-27 18:28:45 +0200351
Akronbb891982020-10-05 16:07:18 +0200352 widget = widgetClass.create({"name" : "Test", "src":"https://example", "id":56});
Akronb43c8c62018-07-04 18:27:28 +0200353 expect(widget).toBeTruthy();
Akron56a11af2018-07-27 18:28:45 +0200354 expect(widget.id).toEqual(56);
355 expect(widget.name).toEqual("Test");
356 expect(widget.src).toEqual("https://example");
357 });
358
359 it('should create a view element', function () {
Akronbb891982020-10-05 16:07:18 +0200360 var widget = widgetClass.create({
361 "name":"Test",
362 "src":"https://example",
363 "id":56,
Akronce0d8822020-10-05 16:25:40 +0200364 "permissions":["scripts","forms"]
Akronbb891982020-10-05 16:07:18 +0200365 });
Akron56a11af2018-07-27 18:28:45 +0200366 var we = widget.element();
367
368 expect(we.tagName).toEqual("DIV");
369 expect(we.classList.contains('view')).toBeTruthy();
370 expect(we.classList.contains('widget')).toBeTruthy();
371
372 var iframe = we.firstChild;
373 expect(iframe.tagName).toEqual("IFRAME");
Akronfb11a962020-10-05 12:12:55 +0200374 expect(iframe.getAttribute("sandbox")).toEqual("allow-forms allow-scripts");
Akron56a11af2018-07-27 18:28:45 +0200375 expect(iframe.getAttribute("src")).toEqual("https://example");
376 expect(iframe.getAttribute("name")).toEqual("56");
Akronfb11a962020-10-05 12:12:55 +0200377
Akron56a11af2018-07-27 18:28:45 +0200378 var btn = we.lastChild;
379 expect(btn.classList.contains("button-group")).toBeTruthy();
380 expect(btn.classList.contains("button-view")).toBeTruthy();
381 expect(btn.classList.contains("widget")).toBeTruthy();
382
383 expect(btn.firstChild.tagName).toEqual("SPAN");
384 expect(btn.firstChild.classList.contains("button-icon")).toBeTruthy();
385 expect(btn.firstChild.classList.contains("close")).toBeTruthy();
386 expect(btn.firstChild.firstChild.tagName).toEqual("SPAN");
387
388 expect(btn.lastChild.tagName).toEqual("SPAN");
389 expect(btn.lastChild.classList.contains("button-icon")).toBeTruthy();
390 expect(btn.lastChild.classList.contains("plugin")).toBeTruthy();
391 expect(btn.lastChild.firstChild.tagName).toEqual("SPAN");
392 expect(btn.lastChild.textContent).toEqual("Test");
393 })
Akronfb11a962020-10-05 12:12:55 +0200394
Akron56a11af2018-07-27 18:28:45 +0200395 it('should be resizable', function () {
Akronbb891982020-10-05 16:07:18 +0200396 var widget = widgetClass.create({"name":"Test", "src":"https://example", "id":56});
Akron56a11af2018-07-27 18:28:45 +0200397 var iframe = widget.show();
398 expect(iframe.style.height).toEqual('0px');
399 widget.resize({ height : 9 });
400 expect(iframe.style.height).toEqual('9px');
Akronb43c8c62018-07-04 18:27:28 +0200401 });
Akron3d9ce5e2020-10-01 15:18:36 +0200402
403 it('should be minimizable', function () {
Akronbb891982020-10-05 16:07:18 +0200404 var widget = widgetClass.create({"name":"Test", "src":"https://example", "id":56});
Akron3d9ce5e2020-10-01 15:18:36 +0200405 var we = widget.element();
406 expect(we.classList.contains('show')).toBeTruthy();
407 widget.minimize();
408 expect(we.classList.contains('show')).toBeFalsy();
409 });
Akronb43c8c62018-07-04 18:27:28 +0200410 });
Akron2d0d96d2019-11-18 19:49:50 +0100411
Akron22598cd2019-12-09 14:59:03 +0100412 describe('KorAP.Plugin.Service', function () {
413 it('should be initializable', function () {
414 expect(function () { serviceClass.create() }).toThrow(new Error("Service not well defined"));
415
Akronbb891982020-10-05 16:07:18 +0200416 let service = serviceClass.create({"name":"Test", "src":"https://example", "id":56});
Akron22598cd2019-12-09 14:59:03 +0100417 expect(service).toBeTruthy();
418 expect(service.id).toEqual(56);
419 expect(service.name).toEqual("Test");
420 expect(service.src).toEqual("https://example");
421 });
422
423 it('should be loadable', function () {
Akronbb891982020-10-05 16:07:18 +0200424 let service = serviceClass.create({"name":"Test", "src":"https://example", "id":56});
Akron22598cd2019-12-09 14:59:03 +0100425 expect(service).toBeTruthy();
426
427 let i = service.load();
428 expect(i.tagName).toEqual("IFRAME");
429 expect(i.getAttribute("allowTransparency")).toEqual("true");
430 expect(i.getAttribute("frameborder")).toEqual(''+0);
431 expect(i.getAttribute("name")).toEqual(''+service.id);
432 expect(i.getAttribute("src")).toEqual(service.src);
433 });
434 });
435
Akron2d0d96d2019-11-18 19:49:50 +0100436 describe('KorAP.Plugin.QueryPanel', function () {
437 it('should establish a query plugin', function () {
438 var queryPanel = queryPanelClass.create();
439
440 var div = document.createElement('div');
441
442 div.appendChild(queryPanel.element());
443 KorAP.Panel = KorAP.Panel || {};
444 KorAP.Panel['query'] = queryPanel;
445
446 // Register plugin afterwards
447 var manager = pluginServerClass.create();
448
449 manager.register({
450 name : 'Check',
451 embed : [{
452 panel : 'query',
453 title : 'Translate',
454 onClick : {
455 template : 'test'
456 }
457 }]
458 });
459
460 expect(manager.buttonGroup('query').length).toEqual(0);
461
462 // Clean up
463 KorAP.Panel['query'] = undefined;
464 manager.destroy();
465 });
hebastaf6adf8d2019-11-26 14:04:10 +0100466
467 it('Plugin buttons should be cleared after adding to panel', function () {
468
469 // Register plugin first
470 KorAP.Plugin = pluginServerClass.create();
471
472 KorAP.Plugin.register({
473 name : 'Check',
474 embed : [{
475 panel : 'query',
476 title : 'Translate',
477 onClick : {
478 template : 'test'
479 }
480 }]
481 });
482
483
484 var queryPanel = queryPanelClass.create();
485 var div = document.createElement('div');
486
487 div.appendChild(queryPanel.element());
488 KorAP.Panel = KorAP.Panel || {};
489 KorAP.Panel['query'] = queryPanel;
490 expect(KorAP.Plugin.buttonGroup('query').length).toEqual(0);
491
492 // Clean up
493 KorAP.Panel['query'] = undefined;
494 KorAP.Plugin.destroy();
495 KorAP.Plugin = undefined;
496 });
Akron2d0d96d2019-11-18 19:49:50 +0100497 });
hebasta043e96f2019-11-28 12:33:00 +0100498
Akron45308ce2020-08-28 14:10:23 +0200499 describe('KorAP.Plugin.ResultPanel', function () {
hebasta043e96f2019-11-28 12:33:00 +0100500 it('Plugin is registered second: buttons should be added to panel', function () {
501
502 var resultPanel = resultPanelClass.create();
503 resultPanel.addAlignAction();
504 var div = document.createElement('div');
505
506 div.appendChild(resultPanel.element());
507 KorAP.Panel = KorAP.Panel || {};
508 KorAP.Panel['result'] = resultPanel;
509
510 // Register plugin afterwards
511 var manager = pluginServerClass.create();
512
513 manager.register({
514 name : 'ResultPlugin',
515 embed : [{
516 panel : 'result',
517 title : 'Dosomething',
518 onClick : {
519 template : 'test'
520 }
521 }]
522 });
523
524 expect(manager.buttonGroup('result').length).toEqual(0);
Akron37ea1192021-07-28 10:40:14 +0200525 expect(KorAP.Panel['result'].actions().element().innerHTML).toContain('Dosomething');
hebasta043e96f2019-11-28 12:33:00 +0100526
527 // Clean up
528 KorAP.Panel['result'] = undefined;
529 manager.destroy();
Akron45308ce2020-08-28 14:10:23 +0200530 });
hebasta043e96f2019-11-28 12:33:00 +0100531
532 it('Plugin is registered first: Buttons should be added to panel and cleared', function () {
533
534 // Register plugin first
535 KorAP.Plugin = pluginServerClass.create();
536
537 KorAP.Plugin.register({
538 name : 'ResultPlugin',
539 embed : [{
540 panel : 'result',
541 title : 'Dosomething',
542 onClick : {
543 template : 'test'
544 }
545 }]
546 });
547
548 expect(KorAP.Plugin.buttonGroup('result').length).toEqual(1);
549
550 var resultPanel = resultPanelClass.create();
551 var div = document.createElement('div');
552 div.appendChild(resultPanel.element());
553 KorAP.Panel = KorAP.Panel || {};
554 KorAP.Panel['result'] = resultPanel;
555 expect(KorAP.Plugin.buttonGroup('result').length).toEqual(0);
Akron37ea1192021-07-28 10:40:14 +0200556 expect(KorAP.Panel['result'].actions().element().innerHTML).toContain('Dosomething');
hebasta043e96f2019-11-28 12:33:00 +0100557
558 // Clean up
559 KorAP.Panel['result'] = undefined;
560 KorAP.Plugin.destroy();
561 KorAP.Plugin = undefined;
562 });
563 });
Akronfec66a32020-08-28 13:01:14 +0200564
565 describe('KorAP.Plugin communications', function () {
566 it('should receive messages', function () {
567 var manager = pluginServerClass.create();
Akronbb891982020-10-05 16:07:18 +0200568 var id = manager.addService({"name":'Example 1', "src":'about:blank'});
Akronfec66a32020-08-28 13:01:14 +0200569 expect(id).toMatch(/^id-/);
Akronfec66a32020-08-28 13:01:14 +0200570 var temp = KorAP.koralQuery;
571 KorAP.koralQuery = { "@type" : "koral:test" };
Akronfec66a32020-08-28 13:01:14 +0200572 let data = {
573 "originID" : id,
574 "action" : "get",
575 "key" : "KQ"
576 };
Akronfec66a32020-08-28 13:01:14 +0200577 manager._receiveMsg({
578 "data" : data
579 });
Akronfec66a32020-08-28 13:01:14 +0200580 manager.destroy();
Akronfec66a32020-08-28 13:01:14 +0200581 expect(data.value["@type"]).toEqual("koral:test");
Akronfec66a32020-08-28 13:01:14 +0200582 // Recreate initial state
583 KorAP.koralQuery = temp;
584 });
585
Akronfec66a32020-08-28 13:01:14 +0200586 it('should add to pipe', function () {
587 var manager = pluginServerClass.create();
Akronfec66a32020-08-28 13:01:14 +0200588 var temp = KorAP.Pipe;
589 KorAP.Pipe = pipeClass.create();
Akronfec66a32020-08-28 13:01:14 +0200590 expect(KorAP.Pipe.toString()).toEqual("");
591
Akronbb891982020-10-05 16:07:18 +0200592 var id = manager.addService({"name":'Example 2', "src":'about:blank'});
Akronfec66a32020-08-28 13:01:14 +0200593 expect(id).toMatch(/^id-/);
Akronfec66a32020-08-28 13:01:14 +0200594 manager._receiveMsg({
595 "data" : {
596 "originID" : id,
597 "action" : "pipe",
598 "job" : "add",
599 "service" : "https://pipe-service.de"
600 }
601 });
Akronfec66a32020-08-28 13:01:14 +0200602 expect(KorAP.Pipe.toString()).toEqual("https://pipe-service.de");
Akronfec66a32020-08-28 13:01:14 +0200603 manager._receiveMsg({
604 "data" : {
605 "originID" : id,
606 "action" : "pipe",
607 "job" : "add",
608 "service" : "https://pipe-service-2.de"
609 }
610 });
Akronfec66a32020-08-28 13:01:14 +0200611 expect(KorAP.Pipe.toString()).toEqual("https://pipe-service.de,https://pipe-service-2.de");
Akronfec66a32020-08-28 13:01:14 +0200612 manager._receiveMsg({
613 "data" : {
614 "originID" : id,
615 "action" : "pipe",
616 "job" : "del",
617 "service" : "https://pipe-service.de"
618 }
619 });
Akronfec66a32020-08-28 13:01:14 +0200620 expect(KorAP.Pipe.toString()).toEqual("https://pipe-service-2.de");
Akronfec66a32020-08-28 13:01:14 +0200621 manager.destroy();
Akronfec66a32020-08-28 13:01:14 +0200622 // Recreate initial state
623 KorAP.Pipe = temp;
624 });
Akron45308ce2020-08-28 14:10:23 +0200625
626 it('should reply to query information requests', function () {
627 var manager = pluginServerClass.create();
Akronbb891982020-10-05 16:07:18 +0200628 var id = manager.addService({"name":'Service', "src":'about:blank'});
Akron45308ce2020-08-28 14:10:23 +0200629 expect(id).toMatch(/^id-/);
630 var temp = KorAP.vc;
631 // Create form for query form information
632 let f = document.createElement('form');
633 var qfield = f.addE('input');
634 qfield.setAttribute("id", "q-field");
635 qfield.value = "[orth=Baum]";
636 var qlfield = f.addE('select');
637 qlfield.setAttribute("id", "ql-field");
638 qlfield.addE('option').setAttribute('value', 'cosmas-2');
639 qlfield.addE('option').setAttribute('value', 'poliqarp');
640 qlfield.selectedIndex = 1;
641
642 KorAP.vc = vcClass.create().fromJson({
643 "key" : "title",
644 "type" : "type:regex",
645 "value" : "[^b]ee.+?",
646 "@type" : "koral:doc"
647 });
648 // console.log(KorAP.vc.toQuery());
649
650 document.body.appendChild(f);
651 let data = {
652 "originID" : id,
653 "action" : "get",
654 "key" : "QueryForm"
655 };
656 manager._receiveMsg({
657 "data" : data
658 });
659 manager.destroy();
660 expect(data.value["q"]).toEqual("[orth=Baum]");
661 expect(data.value["ql"]).toEqual("poliqarp");
662 expect(data.value["cq"]).toEqual("title = /[^b]ee.+?/");
663 // Recreate initial state
664 KorAP.vc = temp;
665 document.body.removeChild(f);
666 });
Akronfec66a32020-08-28 13:01:14 +0200667 });
Akronb43c8c62018-07-04 18:27:28 +0200668});