| Akron | 45308ce | 2020-08-28 14:10:23 +0200 | [diff] [blame] | 1 | define(['plugin/server','plugin/widget','panel', 'panel/query', 'panel/result', 'plugin/service', 'pipe', 'vc','util'], function (pluginServerClass, widgetClass, panelClass, queryPanelClass, resultPanelClass, serviceClass, pipeClass, vcClass) { | 
| Akron | b43c8c6 | 2018-07-04 18:27:28 +0200 | [diff] [blame] | 2 |  | 
|  | 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(); | 
| Akron | 4a70387 | 2018-07-26 10:59:41 +0200 | [diff] [blame] | 13 | var panel = panelClass.create(); | 
|  | 14 | var id = manager.addWidget(panel, 'Example 1', 'about:blank'); | 
| Akron | b43c8c6 | 2018-07-04 18:27:28 +0200 | [diff] [blame] | 15 | expect(id).toMatch(/^id-/); | 
| Akron | 4a70387 | 2018-07-26 10:59:41 +0200 | [diff] [blame] | 16 |  | 
|  | 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 |  | 
| Akron | b43c8c6 | 2018-07-04 18:27:28 +0200 | [diff] [blame] | 27 | manager.destroy(); | 
|  | 28 | }); | 
| Akron | 10a4796 | 2018-07-12 21:17:10 +0200 | [diff] [blame] | 29 |  | 
| Akron | 22598cd | 2019-12-09 14:59:03 +0100 | [diff] [blame] | 30 | 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 |  | 
|  | 42 | var id = manager.addService('Example 1', 'about:blank'); | 
|  | 43 | 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 |  | 
| Akron | 4a70387 | 2018-07-26 10:59:41 +0200 | [diff] [blame] | 53 | it('should close a widget', function () { | 
|  | 54 | var manager = pluginServerClass.create(); | 
|  | 55 | var panel = panelClass.create(); | 
|  | 56 | var id = manager.addWidget(panel, 'Example 2', 'about:blank'); | 
|  | 57 | 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 |  | 
| Akron | 22598cd | 2019-12-09 14:59:03 +0100 | [diff] [blame] | 65 | var widget = manager.service(id); | 
|  | 66 | expect(widget.isWidget).toBeTruthy(); | 
| Akron | 4a70387 | 2018-07-26 10:59:41 +0200 | [diff] [blame] | 67 | widget.close(); | 
|  | 68 |  | 
|  | 69 | expect(panelE.getElementsByClassName('view').length).toEqual(0); | 
| Akron | 4a70387 | 2018-07-26 10:59:41 +0200 | [diff] [blame] | 70 | manager.destroy(); | 
|  | 71 | }); | 
|  | 72 |  | 
|  | 73 |  | 
|  | 74 | it('should fail on invalid registrations', function () { | 
| Akron | 10a4796 | 2018-07-12 21:17:10 +0200 | [diff] [blame] | 75 | 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")); | 
| Akron | 2d0d96d | 2019-11-18 19:49:50 +0100 | [diff] [blame] | 96 | 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 | }); | 
|  | 116 |  | 
|  | 117 | 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(); | 
| Akron | 10a4796 | 2018-07-12 21:17:10 +0200 | [diff] [blame] | 133 | }); | 
| hebasta | 043e96f | 2019-11-28 12:33:00 +0100 | [diff] [blame] | 134 |  | 
|  | 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 | }); | 
| Akron | b43c8c6 | 2018-07-04 18:27:28 +0200 | [diff] [blame] | 153 | }); | 
| Akron | 2d0d96d | 2019-11-18 19:49:50 +0100 | [diff] [blame] | 154 |  | 
| Akron | b43c8c6 | 2018-07-04 18:27:28 +0200 | [diff] [blame] | 155 | describe('KorAP.Plugin.Widget', function () { | 
|  | 156 | it('should be initializable', function () { | 
| Akron | 22598cd | 2019-12-09 14:59:03 +0100 | [diff] [blame] | 157 | expect(function () { widgetClass.create() }).toThrow(new Error("Service not well defined")); | 
| Akron | 56a11af | 2018-07-27 18:28:45 +0200 | [diff] [blame] | 158 |  | 
|  | 159 | widget = widgetClass.create("Test", "https://example", 56); | 
| Akron | b43c8c6 | 2018-07-04 18:27:28 +0200 | [diff] [blame] | 160 | expect(widget).toBeTruthy(); | 
| Akron | 56a11af | 2018-07-27 18:28:45 +0200 | [diff] [blame] | 161 | expect(widget.id).toEqual(56); | 
|  | 162 | expect(widget.name).toEqual("Test"); | 
|  | 163 | expect(widget.src).toEqual("https://example"); | 
|  | 164 | }); | 
|  | 165 |  | 
|  | 166 | it('should create a view element', function () { | 
|  | 167 | var widget = widgetClass.create("Test", "https://example", 56); | 
|  | 168 | var we = widget.element(); | 
|  | 169 |  | 
|  | 170 | expect(we.tagName).toEqual("DIV"); | 
|  | 171 | expect(we.classList.contains('view')).toBeTruthy(); | 
|  | 172 | expect(we.classList.contains('widget')).toBeTruthy(); | 
|  | 173 |  | 
|  | 174 | var iframe = we.firstChild; | 
|  | 175 | expect(iframe.tagName).toEqual("IFRAME"); | 
| hebasta | 7891324 | 2020-03-30 13:39:20 +0200 | [diff] [blame] | 176 | expect(iframe.getAttribute("sandbox")).toEqual("allow-scripts allow-forms"); | 
| Akron | 56a11af | 2018-07-27 18:28:45 +0200 | [diff] [blame] | 177 | expect(iframe.getAttribute("src")).toEqual("https://example"); | 
|  | 178 | expect(iframe.getAttribute("name")).toEqual("56"); | 
|  | 179 |  | 
|  | 180 | var btn = we.lastChild; | 
|  | 181 | expect(btn.classList.contains("button-group")).toBeTruthy(); | 
|  | 182 | expect(btn.classList.contains("button-view")).toBeTruthy(); | 
|  | 183 | expect(btn.classList.contains("widget")).toBeTruthy(); | 
|  | 184 |  | 
|  | 185 | expect(btn.firstChild.tagName).toEqual("SPAN"); | 
|  | 186 | expect(btn.firstChild.classList.contains("button-icon")).toBeTruthy(); | 
|  | 187 | expect(btn.firstChild.classList.contains("close")).toBeTruthy(); | 
|  | 188 | expect(btn.firstChild.firstChild.tagName).toEqual("SPAN"); | 
|  | 189 |  | 
|  | 190 | expect(btn.lastChild.tagName).toEqual("SPAN"); | 
|  | 191 | expect(btn.lastChild.classList.contains("button-icon")).toBeTruthy(); | 
|  | 192 | expect(btn.lastChild.classList.contains("plugin")).toBeTruthy(); | 
|  | 193 | expect(btn.lastChild.firstChild.tagName).toEqual("SPAN"); | 
|  | 194 | expect(btn.lastChild.textContent).toEqual("Test"); | 
|  | 195 | }) | 
|  | 196 |  | 
|  | 197 | it('should be resizable', function () { | 
|  | 198 | var widget = widgetClass.create("Test", "https://example", 56); | 
|  | 199 | var iframe = widget.show(); | 
|  | 200 | expect(iframe.style.height).toEqual('0px'); | 
|  | 201 | widget.resize({ height : 9 }); | 
|  | 202 | expect(iframe.style.height).toEqual('9px'); | 
| Akron | b43c8c6 | 2018-07-04 18:27:28 +0200 | [diff] [blame] | 203 | }); | 
|  | 204 | }); | 
| Akron | 2d0d96d | 2019-11-18 19:49:50 +0100 | [diff] [blame] | 205 |  | 
| Akron | 22598cd | 2019-12-09 14:59:03 +0100 | [diff] [blame] | 206 | describe('KorAP.Plugin.Service', function () { | 
|  | 207 | it('should be initializable', function () { | 
|  | 208 | expect(function () { serviceClass.create() }).toThrow(new Error("Service not well defined")); | 
|  | 209 |  | 
|  | 210 | let service = serviceClass.create("Test", "https://example", 56); | 
|  | 211 | expect(service).toBeTruthy(); | 
|  | 212 | expect(service.id).toEqual(56); | 
|  | 213 | expect(service.name).toEqual("Test"); | 
|  | 214 | expect(service.src).toEqual("https://example"); | 
|  | 215 | }); | 
|  | 216 |  | 
|  | 217 | it('should be loadable', function () { | 
|  | 218 | let service = serviceClass.create("Test", "https://example", 56); | 
|  | 219 | expect(service).toBeTruthy(); | 
|  | 220 |  | 
|  | 221 | let i = service.load(); | 
|  | 222 | expect(i.tagName).toEqual("IFRAME"); | 
|  | 223 | expect(i.getAttribute("allowTransparency")).toEqual("true"); | 
|  | 224 | expect(i.getAttribute("frameborder")).toEqual(''+0); | 
|  | 225 | expect(i.getAttribute("name")).toEqual(''+service.id); | 
|  | 226 | expect(i.getAttribute("src")).toEqual(service.src); | 
|  | 227 | }); | 
|  | 228 | }); | 
|  | 229 |  | 
| Akron | 2d0d96d | 2019-11-18 19:49:50 +0100 | [diff] [blame] | 230 | describe('KorAP.Plugin.QueryPanel', function () { | 
|  | 231 | it('should establish a query plugin', function () { | 
|  | 232 | var queryPanel = queryPanelClass.create(); | 
|  | 233 |  | 
|  | 234 | var div = document.createElement('div'); | 
|  | 235 |  | 
|  | 236 | div.appendChild(queryPanel.element()); | 
|  | 237 | KorAP.Panel = KorAP.Panel || {}; | 
|  | 238 | KorAP.Panel['query'] = queryPanel; | 
|  | 239 |  | 
|  | 240 | // Register plugin afterwards | 
|  | 241 | var manager = pluginServerClass.create(); | 
|  | 242 |  | 
|  | 243 | manager.register({ | 
|  | 244 | name : 'Check', | 
|  | 245 | embed : [{ | 
|  | 246 | panel : 'query', | 
|  | 247 | title : 'Translate', | 
|  | 248 | onClick : { | 
|  | 249 | template : 'test' | 
|  | 250 | } | 
|  | 251 | }] | 
|  | 252 | }); | 
|  | 253 |  | 
|  | 254 | expect(manager.buttonGroup('query').length).toEqual(0); | 
|  | 255 |  | 
|  | 256 | // Clean up | 
|  | 257 | KorAP.Panel['query'] = undefined; | 
|  | 258 | manager.destroy(); | 
|  | 259 | }); | 
| hebasta | f6adf8d | 2019-11-26 14:04:10 +0100 | [diff] [blame] | 260 |  | 
|  | 261 | it('Plugin buttons should be cleared after adding to panel', function () { | 
|  | 262 |  | 
|  | 263 | // Register plugin first | 
|  | 264 | KorAP.Plugin = pluginServerClass.create(); | 
|  | 265 |  | 
|  | 266 | KorAP.Plugin.register({ | 
|  | 267 | name : 'Check', | 
|  | 268 | embed : [{ | 
|  | 269 | panel : 'query', | 
|  | 270 | title : 'Translate', | 
|  | 271 | onClick : { | 
|  | 272 | template : 'test' | 
|  | 273 | } | 
|  | 274 | }] | 
|  | 275 | }); | 
|  | 276 |  | 
|  | 277 |  | 
|  | 278 | var queryPanel = queryPanelClass.create(); | 
|  | 279 | var div = document.createElement('div'); | 
|  | 280 |  | 
|  | 281 | div.appendChild(queryPanel.element()); | 
|  | 282 | KorAP.Panel = KorAP.Panel || {}; | 
|  | 283 | KorAP.Panel['query'] = queryPanel; | 
|  | 284 | expect(KorAP.Plugin.buttonGroup('query').length).toEqual(0); | 
|  | 285 |  | 
|  | 286 | // Clean up | 
|  | 287 | KorAP.Panel['query'] = undefined; | 
|  | 288 | KorAP.Plugin.destroy(); | 
|  | 289 | KorAP.Plugin = undefined; | 
|  | 290 | }); | 
| Akron | 2d0d96d | 2019-11-18 19:49:50 +0100 | [diff] [blame] | 291 | }); | 
| hebasta | 043e96f | 2019-11-28 12:33:00 +0100 | [diff] [blame] | 292 |  | 
| Akron | 45308ce | 2020-08-28 14:10:23 +0200 | [diff] [blame] | 293 | describe('KorAP.Plugin.ResultPanel', function () { | 
| hebasta | 043e96f | 2019-11-28 12:33:00 +0100 | [diff] [blame] | 294 | it('Plugin is registered second: buttons should be added to panel', function () { | 
|  | 295 |  | 
|  | 296 | var resultPanel = resultPanelClass.create(); | 
|  | 297 | resultPanel.addAlignAction(); | 
|  | 298 | var div = document.createElement('div'); | 
|  | 299 |  | 
|  | 300 | div.appendChild(resultPanel.element()); | 
|  | 301 | KorAP.Panel = KorAP.Panel || {}; | 
|  | 302 | KorAP.Panel['result'] = resultPanel; | 
|  | 303 |  | 
|  | 304 | // Register plugin afterwards | 
|  | 305 | var manager = pluginServerClass.create(); | 
|  | 306 |  | 
|  | 307 | manager.register({ | 
|  | 308 | name : 'ResultPlugin', | 
|  | 309 | embed : [{ | 
|  | 310 | panel : 'result', | 
|  | 311 | title : 'Dosomething', | 
|  | 312 | onClick : { | 
|  | 313 | template : 'test' | 
|  | 314 | } | 
|  | 315 | }] | 
|  | 316 | }); | 
|  | 317 |  | 
|  | 318 | expect(manager.buttonGroup('result').length).toEqual(0); | 
|  | 319 | expect(KorAP.Panel['result'].actions.element().innerHTML).toContain('Dosomething'); | 
|  | 320 |  | 
|  | 321 | // Clean up | 
|  | 322 | KorAP.Panel['result'] = undefined; | 
|  | 323 | manager.destroy(); | 
| Akron | 45308ce | 2020-08-28 14:10:23 +0200 | [diff] [blame] | 324 | }); | 
| hebasta | 043e96f | 2019-11-28 12:33:00 +0100 | [diff] [blame] | 325 |  | 
|  | 326 | it('Plugin is registered first: Buttons should be added to panel and cleared', function () { | 
|  | 327 |  | 
|  | 328 | // Register plugin first | 
|  | 329 | KorAP.Plugin = pluginServerClass.create(); | 
|  | 330 |  | 
|  | 331 | KorAP.Plugin.register({ | 
|  | 332 | name : 'ResultPlugin', | 
|  | 333 | embed : [{ | 
|  | 334 | panel : 'result', | 
|  | 335 | title : 'Dosomething', | 
|  | 336 | onClick : { | 
|  | 337 | template : 'test' | 
|  | 338 | } | 
|  | 339 | }] | 
|  | 340 | }); | 
|  | 341 |  | 
|  | 342 | expect(KorAP.Plugin.buttonGroup('result').length).toEqual(1); | 
|  | 343 |  | 
|  | 344 | var resultPanel = resultPanelClass.create(); | 
|  | 345 | var div = document.createElement('div'); | 
|  | 346 | div.appendChild(resultPanel.element()); | 
|  | 347 | KorAP.Panel = KorAP.Panel || {}; | 
|  | 348 | KorAP.Panel['result'] = resultPanel; | 
|  | 349 | expect(KorAP.Plugin.buttonGroup('result').length).toEqual(0); | 
|  | 350 | expect(KorAP.Panel['result'].actions.element().innerHTML).toContain('Dosomething'); | 
|  | 351 |  | 
|  | 352 | // Clean up | 
|  | 353 | KorAP.Panel['result'] = undefined; | 
|  | 354 | KorAP.Plugin.destroy(); | 
|  | 355 | KorAP.Plugin = undefined; | 
|  | 356 | }); | 
|  | 357 | }); | 
| Akron | fec66a3 | 2020-08-28 13:01:14 +0200 | [diff] [blame] | 358 |  | 
|  | 359 | describe('KorAP.Plugin communications', function () { | 
|  | 360 | it('should receive messages', function () { | 
|  | 361 | var manager = pluginServerClass.create(); | 
| Akron | fec66a3 | 2020-08-28 13:01:14 +0200 | [diff] [blame] | 362 | var id = manager.addService('Example 1', 'about:blank'); | 
|  | 363 | expect(id).toMatch(/^id-/); | 
| Akron | fec66a3 | 2020-08-28 13:01:14 +0200 | [diff] [blame] | 364 | var temp = KorAP.koralQuery; | 
|  | 365 | KorAP.koralQuery = { "@type" : "koral:test" }; | 
| Akron | fec66a3 | 2020-08-28 13:01:14 +0200 | [diff] [blame] | 366 | let data = { | 
|  | 367 | "originID" : id, | 
|  | 368 | "action" : "get", | 
|  | 369 | "key" : "KQ" | 
|  | 370 | }; | 
| Akron | fec66a3 | 2020-08-28 13:01:14 +0200 | [diff] [blame] | 371 | manager._receiveMsg({ | 
|  | 372 | "data" : data | 
|  | 373 | }); | 
| Akron | fec66a3 | 2020-08-28 13:01:14 +0200 | [diff] [blame] | 374 | manager.destroy(); | 
| Akron | fec66a3 | 2020-08-28 13:01:14 +0200 | [diff] [blame] | 375 | expect(data.value["@type"]).toEqual("koral:test"); | 
| Akron | fec66a3 | 2020-08-28 13:01:14 +0200 | [diff] [blame] | 376 | // Recreate initial state | 
|  | 377 | KorAP.koralQuery = temp; | 
|  | 378 | }); | 
|  | 379 |  | 
| Akron | fec66a3 | 2020-08-28 13:01:14 +0200 | [diff] [blame] | 380 | it('should add to pipe', function () { | 
|  | 381 | var manager = pluginServerClass.create(); | 
| Akron | fec66a3 | 2020-08-28 13:01:14 +0200 | [diff] [blame] | 382 | var temp = KorAP.Pipe; | 
|  | 383 | KorAP.Pipe = pipeClass.create(); | 
| Akron | fec66a3 | 2020-08-28 13:01:14 +0200 | [diff] [blame] | 384 | expect(KorAP.Pipe.toString()).toEqual(""); | 
|  | 385 |  | 
|  | 386 | var id = manager.addService('Example 2', 'about:blank'); | 
|  | 387 | expect(id).toMatch(/^id-/); | 
| Akron | fec66a3 | 2020-08-28 13:01:14 +0200 | [diff] [blame] | 388 | manager._receiveMsg({ | 
|  | 389 | "data" : { | 
|  | 390 | "originID" : id, | 
|  | 391 | "action" : "pipe", | 
|  | 392 | "job" : "add", | 
|  | 393 | "service" : "https://pipe-service.de" | 
|  | 394 | } | 
|  | 395 | }); | 
| Akron | fec66a3 | 2020-08-28 13:01:14 +0200 | [diff] [blame] | 396 | expect(KorAP.Pipe.toString()).toEqual("https://pipe-service.de"); | 
| Akron | fec66a3 | 2020-08-28 13:01:14 +0200 | [diff] [blame] | 397 | manager._receiveMsg({ | 
|  | 398 | "data" : { | 
|  | 399 | "originID" : id, | 
|  | 400 | "action" : "pipe", | 
|  | 401 | "job" : "add", | 
|  | 402 | "service" : "https://pipe-service-2.de" | 
|  | 403 | } | 
|  | 404 | }); | 
| Akron | fec66a3 | 2020-08-28 13:01:14 +0200 | [diff] [blame] | 405 | expect(KorAP.Pipe.toString()).toEqual("https://pipe-service.de,https://pipe-service-2.de"); | 
| Akron | fec66a3 | 2020-08-28 13:01:14 +0200 | [diff] [blame] | 406 | manager._receiveMsg({ | 
|  | 407 | "data" : { | 
|  | 408 | "originID" : id, | 
|  | 409 | "action" : "pipe", | 
|  | 410 | "job" : "del", | 
|  | 411 | "service" : "https://pipe-service.de" | 
|  | 412 | } | 
|  | 413 | }); | 
| Akron | fec66a3 | 2020-08-28 13:01:14 +0200 | [diff] [blame] | 414 | expect(KorAP.Pipe.toString()).toEqual("https://pipe-service-2.de"); | 
| Akron | fec66a3 | 2020-08-28 13:01:14 +0200 | [diff] [blame] | 415 | manager.destroy(); | 
| Akron | fec66a3 | 2020-08-28 13:01:14 +0200 | [diff] [blame] | 416 | // Recreate initial state | 
|  | 417 | KorAP.Pipe = temp; | 
|  | 418 | }); | 
| Akron | 45308ce | 2020-08-28 14:10:23 +0200 | [diff] [blame] | 419 |  | 
|  | 420 | it('should reply to query information requests', function () { | 
|  | 421 | var manager = pluginServerClass.create(); | 
|  | 422 | var id = manager.addService('Service', 'about:blank'); | 
|  | 423 | expect(id).toMatch(/^id-/); | 
|  | 424 | var temp = KorAP.vc; | 
|  | 425 | // Create form for query form information | 
|  | 426 | let f = document.createElement('form'); | 
|  | 427 | var qfield = f.addE('input'); | 
|  | 428 | qfield.setAttribute("id", "q-field"); | 
|  | 429 | qfield.value = "[orth=Baum]"; | 
|  | 430 | var qlfield = f.addE('select'); | 
|  | 431 | qlfield.setAttribute("id", "ql-field"); | 
|  | 432 | qlfield.addE('option').setAttribute('value', 'cosmas-2'); | 
|  | 433 | qlfield.addE('option').setAttribute('value', 'poliqarp'); | 
|  | 434 | qlfield.selectedIndex = 1; | 
|  | 435 |  | 
|  | 436 | KorAP.vc = vcClass.create().fromJson({ | 
|  | 437 | "key"   : "title", | 
|  | 438 | "type"  : "type:regex", | 
|  | 439 | "value" : "[^b]ee.+?", | 
|  | 440 | "@type" : "koral:doc" | 
|  | 441 | }); | 
|  | 442 | // console.log(KorAP.vc.toQuery()); | 
|  | 443 |  | 
|  | 444 | document.body.appendChild(f); | 
|  | 445 | let data = { | 
|  | 446 | "originID" : id, | 
|  | 447 | "action" : "get", | 
|  | 448 | "key" : "QueryForm" | 
|  | 449 | }; | 
|  | 450 | manager._receiveMsg({ | 
|  | 451 | "data" : data | 
|  | 452 | }); | 
|  | 453 | manager.destroy(); | 
|  | 454 | expect(data.value["q"]).toEqual("[orth=Baum]"); | 
|  | 455 | expect(data.value["ql"]).toEqual("poliqarp"); | 
|  | 456 | expect(data.value["cq"]).toEqual("title = /[^b]ee.+?/"); | 
|  | 457 | // Recreate initial state | 
|  | 458 | KorAP.vc = temp; | 
|  | 459 | document.body.removeChild(f); | 
|  | 460 | }); | 
| Akron | fec66a3 | 2020-08-28 13:01:14 +0200 | [diff] [blame] | 461 | }); | 
| Akron | b43c8c6 | 2018-07-04 18:27:28 +0200 | [diff] [blame] | 462 | }); |