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(); |
Akron | bb89198 | 2020-10-05 16:07:18 +0200 | [diff] [blame] | 14 | var id = manager.addWidget(panel, {"name": 'Example 1', "src": '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 | |
Akron | bb89198 | 2020-10-05 16:07:18 +0200 | [diff] [blame] | 42 | var id = manager.addService({"name":'Example 1', "src":'about:blank'}); |
Akron | 22598cd | 2019-12-09 14:59:03 +0100 | [diff] [blame] | 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(); |
Akron | bb89198 | 2020-10-05 16:07:18 +0200 | [diff] [blame] | 56 | var id = manager.addWidget(panel, {"name":'Example 2', "src":'about:blank'}); |
Akron | 4a70387 | 2018-07-26 10:59:41 +0200 | [diff] [blame] | 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 | ba09ed2 | 2020-10-01 16:01:45 +0200 | [diff] [blame] | 153 | |
| 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 | |
| 171 | let b = p.actions.element().firstChild; |
| 172 | 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 | |
| 195 | |
| 196 | it('should accept valid registrations for setWidget', function () { |
| 197 | let p = KorAP.Panel["result"] = panelClass.create(); |
| 198 | |
| 199 | let manager = pluginServerClass.create(); |
| 200 | |
| 201 | manager.register({ |
| 202 | name : 'Check', |
| 203 | embed : [{ |
| 204 | panel : 'result', |
| 205 | title : 'Add', |
| 206 | onClick : { |
| 207 | template : 'about:blank', |
| 208 | action : 'setWidget' |
| 209 | } |
| 210 | }] |
| 211 | }); |
| 212 | |
| 213 | let b = p.actions.element().firstChild; |
| 214 | expect(b.hasAttribute("data-icon")).toBeFalsy(); |
| 215 | expect(b.hasAttribute("cls")).toBeFalsy(); |
| 216 | expect(b.getAttribute("title")).toEqual("Add"); |
| 217 | |
| 218 | expect(p.element().querySelectorAll("iframe").length).toEqual(0); |
| 219 | |
| 220 | b.click(); |
| 221 | |
| 222 | expect(p.element().querySelectorAll("iframe").length).toEqual(1); |
| 223 | expect(p.element().querySelectorAll("div.view.show.widget").length).toEqual(1); |
| 224 | |
| 225 | b.click(); |
| 226 | |
| 227 | expect(p.element().querySelectorAll("iframe").length).toEqual(1); |
| 228 | expect(p.element().querySelectorAll("div.view.widget").length).toEqual(1); |
| 229 | expect(p.element().querySelectorAll("div.view.show.widget").length).toEqual(0); |
Akron | fcf89db | 2020-10-01 17:40:20 +0200 | [diff] [blame] | 230 | |
| 231 | p.element().querySelector("span.close").click(); |
| 232 | |
| 233 | expect(p.element().querySelectorAll("iframe").length).toEqual(0); |
| 234 | |
| 235 | b.click(); |
| 236 | |
| 237 | expect(p.element().querySelectorAll("iframe").length).toEqual(1); |
| 238 | expect(p.element().querySelectorAll("div.view.widget").length).toEqual(1); |
| 239 | expect(p.element().querySelectorAll("div.view.show.widget").length).toEqual(1); |
Akron | fb11a96 | 2020-10-05 12:12:55 +0200 | [diff] [blame] | 240 | expect(p.element().querySelector("iframe").getAttribute('sandbox')).toEqual(''); |
Akron | ba09ed2 | 2020-10-01 16:01:45 +0200 | [diff] [blame] | 241 | |
| 242 | manager.destroy(); |
| 243 | |
| 244 | KorAP.Panel["result"] = undefined; |
| 245 | }); |
Akron | fb11a96 | 2020-10-05 12:12:55 +0200 | [diff] [blame] | 246 | |
| 247 | it('should accept widget permissions', function () { |
| 248 | let p = KorAP.Panel["result"] = panelClass.create(); |
| 249 | |
| 250 | let manager = pluginServerClass.create(); |
| 251 | |
| 252 | manager.register({ |
| 253 | name : 'Check', |
| 254 | embed : [{ |
| 255 | panel : 'result', |
| 256 | title : 'Add', |
| 257 | onClick : { |
| 258 | template : 'about:blank', |
| 259 | action : 'addWidget', |
Akron | ce0d882 | 2020-10-05 16:25:40 +0200 | [diff] [blame] | 260 | permissions: ['scripts', 'forms', 'all'] |
Akron | fb11a96 | 2020-10-05 12:12:55 +0200 | [diff] [blame] | 261 | } |
| 262 | }] |
| 263 | }); |
| 264 | |
| 265 | let b = p.actions.element().firstChild; |
| 266 | b.click(); |
| 267 | expect(p.element().querySelectorAll("iframe").length).toEqual(1); |
| 268 | expect(p.element().querySelector("iframe").getAttribute('sandbox')).toEqual('allow-forms allow-scripts'); |
| 269 | }); |
Akron | b43c8c6 | 2018-07-04 18:27:28 +0200 | [diff] [blame] | 270 | }); |
Akron | 2d0d96d | 2019-11-18 19:49:50 +0100 | [diff] [blame] | 271 | |
Akron | b43c8c6 | 2018-07-04 18:27:28 +0200 | [diff] [blame] | 272 | describe('KorAP.Plugin.Widget', function () { |
| 273 | it('should be initializable', function () { |
Akron | 22598cd | 2019-12-09 14:59:03 +0100 | [diff] [blame] | 274 | expect(function () { widgetClass.create() }).toThrow(new Error("Service not well defined")); |
Akron | 56a11af | 2018-07-27 18:28:45 +0200 | [diff] [blame] | 275 | |
Akron | bb89198 | 2020-10-05 16:07:18 +0200 | [diff] [blame] | 276 | widget = widgetClass.create({"name" : "Test", "src":"https://example", "id":56}); |
Akron | b43c8c6 | 2018-07-04 18:27:28 +0200 | [diff] [blame] | 277 | expect(widget).toBeTruthy(); |
Akron | 56a11af | 2018-07-27 18:28:45 +0200 | [diff] [blame] | 278 | expect(widget.id).toEqual(56); |
| 279 | expect(widget.name).toEqual("Test"); |
| 280 | expect(widget.src).toEqual("https://example"); |
| 281 | }); |
| 282 | |
| 283 | it('should create a view element', function () { |
Akron | bb89198 | 2020-10-05 16:07:18 +0200 | [diff] [blame] | 284 | var widget = widgetClass.create({ |
| 285 | "name":"Test", |
| 286 | "src":"https://example", |
| 287 | "id":56, |
Akron | ce0d882 | 2020-10-05 16:25:40 +0200 | [diff] [blame] | 288 | "permissions":["scripts","forms"] |
Akron | bb89198 | 2020-10-05 16:07:18 +0200 | [diff] [blame] | 289 | }); |
Akron | 56a11af | 2018-07-27 18:28:45 +0200 | [diff] [blame] | 290 | var we = widget.element(); |
| 291 | |
| 292 | expect(we.tagName).toEqual("DIV"); |
| 293 | expect(we.classList.contains('view')).toBeTruthy(); |
| 294 | expect(we.classList.contains('widget')).toBeTruthy(); |
| 295 | |
| 296 | var iframe = we.firstChild; |
| 297 | expect(iframe.tagName).toEqual("IFRAME"); |
Akron | fb11a96 | 2020-10-05 12:12:55 +0200 | [diff] [blame] | 298 | expect(iframe.getAttribute("sandbox")).toEqual("allow-forms allow-scripts"); |
Akron | 56a11af | 2018-07-27 18:28:45 +0200 | [diff] [blame] | 299 | expect(iframe.getAttribute("src")).toEqual("https://example"); |
| 300 | expect(iframe.getAttribute("name")).toEqual("56"); |
Akron | fb11a96 | 2020-10-05 12:12:55 +0200 | [diff] [blame] | 301 | |
Akron | 56a11af | 2018-07-27 18:28:45 +0200 | [diff] [blame] | 302 | var btn = we.lastChild; |
| 303 | expect(btn.classList.contains("button-group")).toBeTruthy(); |
| 304 | expect(btn.classList.contains("button-view")).toBeTruthy(); |
| 305 | expect(btn.classList.contains("widget")).toBeTruthy(); |
| 306 | |
| 307 | expect(btn.firstChild.tagName).toEqual("SPAN"); |
| 308 | expect(btn.firstChild.classList.contains("button-icon")).toBeTruthy(); |
| 309 | expect(btn.firstChild.classList.contains("close")).toBeTruthy(); |
| 310 | expect(btn.firstChild.firstChild.tagName).toEqual("SPAN"); |
| 311 | |
| 312 | expect(btn.lastChild.tagName).toEqual("SPAN"); |
| 313 | expect(btn.lastChild.classList.contains("button-icon")).toBeTruthy(); |
| 314 | expect(btn.lastChild.classList.contains("plugin")).toBeTruthy(); |
| 315 | expect(btn.lastChild.firstChild.tagName).toEqual("SPAN"); |
| 316 | expect(btn.lastChild.textContent).toEqual("Test"); |
| 317 | }) |
Akron | fb11a96 | 2020-10-05 12:12:55 +0200 | [diff] [blame] | 318 | |
Akron | 56a11af | 2018-07-27 18:28:45 +0200 | [diff] [blame] | 319 | it('should be resizable', function () { |
Akron | bb89198 | 2020-10-05 16:07:18 +0200 | [diff] [blame] | 320 | var widget = widgetClass.create({"name":"Test", "src":"https://example", "id":56}); |
Akron | 56a11af | 2018-07-27 18:28:45 +0200 | [diff] [blame] | 321 | var iframe = widget.show(); |
| 322 | expect(iframe.style.height).toEqual('0px'); |
| 323 | widget.resize({ height : 9 }); |
| 324 | expect(iframe.style.height).toEqual('9px'); |
Akron | b43c8c6 | 2018-07-04 18:27:28 +0200 | [diff] [blame] | 325 | }); |
Akron | 3d9ce5e | 2020-10-01 15:18:36 +0200 | [diff] [blame] | 326 | |
| 327 | it('should be minimizable', function () { |
Akron | bb89198 | 2020-10-05 16:07:18 +0200 | [diff] [blame] | 328 | var widget = widgetClass.create({"name":"Test", "src":"https://example", "id":56}); |
Akron | 3d9ce5e | 2020-10-01 15:18:36 +0200 | [diff] [blame] | 329 | var we = widget.element(); |
| 330 | expect(we.classList.contains('show')).toBeTruthy(); |
| 331 | widget.minimize(); |
| 332 | expect(we.classList.contains('show')).toBeFalsy(); |
| 333 | }); |
Akron | b43c8c6 | 2018-07-04 18:27:28 +0200 | [diff] [blame] | 334 | }); |
Akron | 2d0d96d | 2019-11-18 19:49:50 +0100 | [diff] [blame] | 335 | |
Akron | 22598cd | 2019-12-09 14:59:03 +0100 | [diff] [blame] | 336 | describe('KorAP.Plugin.Service', function () { |
| 337 | it('should be initializable', function () { |
| 338 | expect(function () { serviceClass.create() }).toThrow(new Error("Service not well defined")); |
| 339 | |
Akron | bb89198 | 2020-10-05 16:07:18 +0200 | [diff] [blame] | 340 | let service = serviceClass.create({"name":"Test", "src":"https://example", "id":56}); |
Akron | 22598cd | 2019-12-09 14:59:03 +0100 | [diff] [blame] | 341 | expect(service).toBeTruthy(); |
| 342 | expect(service.id).toEqual(56); |
| 343 | expect(service.name).toEqual("Test"); |
| 344 | expect(service.src).toEqual("https://example"); |
| 345 | }); |
| 346 | |
| 347 | it('should be loadable', function () { |
Akron | bb89198 | 2020-10-05 16:07:18 +0200 | [diff] [blame] | 348 | let service = serviceClass.create({"name":"Test", "src":"https://example", "id":56}); |
Akron | 22598cd | 2019-12-09 14:59:03 +0100 | [diff] [blame] | 349 | expect(service).toBeTruthy(); |
| 350 | |
| 351 | let i = service.load(); |
| 352 | expect(i.tagName).toEqual("IFRAME"); |
| 353 | expect(i.getAttribute("allowTransparency")).toEqual("true"); |
| 354 | expect(i.getAttribute("frameborder")).toEqual(''+0); |
| 355 | expect(i.getAttribute("name")).toEqual(''+service.id); |
| 356 | expect(i.getAttribute("src")).toEqual(service.src); |
| 357 | }); |
| 358 | }); |
| 359 | |
Akron | 2d0d96d | 2019-11-18 19:49:50 +0100 | [diff] [blame] | 360 | describe('KorAP.Plugin.QueryPanel', function () { |
| 361 | it('should establish a query plugin', function () { |
| 362 | var queryPanel = queryPanelClass.create(); |
| 363 | |
| 364 | var div = document.createElement('div'); |
| 365 | |
| 366 | div.appendChild(queryPanel.element()); |
| 367 | KorAP.Panel = KorAP.Panel || {}; |
| 368 | KorAP.Panel['query'] = queryPanel; |
| 369 | |
| 370 | // Register plugin afterwards |
| 371 | var manager = pluginServerClass.create(); |
| 372 | |
| 373 | manager.register({ |
| 374 | name : 'Check', |
| 375 | embed : [{ |
| 376 | panel : 'query', |
| 377 | title : 'Translate', |
| 378 | onClick : { |
| 379 | template : 'test' |
| 380 | } |
| 381 | }] |
| 382 | }); |
| 383 | |
| 384 | expect(manager.buttonGroup('query').length).toEqual(0); |
| 385 | |
| 386 | // Clean up |
| 387 | KorAP.Panel['query'] = undefined; |
| 388 | manager.destroy(); |
| 389 | }); |
hebasta | f6adf8d | 2019-11-26 14:04:10 +0100 | [diff] [blame] | 390 | |
| 391 | it('Plugin buttons should be cleared after adding to panel', function () { |
| 392 | |
| 393 | // Register plugin first |
| 394 | KorAP.Plugin = pluginServerClass.create(); |
| 395 | |
| 396 | KorAP.Plugin.register({ |
| 397 | name : 'Check', |
| 398 | embed : [{ |
| 399 | panel : 'query', |
| 400 | title : 'Translate', |
| 401 | onClick : { |
| 402 | template : 'test' |
| 403 | } |
| 404 | }] |
| 405 | }); |
| 406 | |
| 407 | |
| 408 | var queryPanel = queryPanelClass.create(); |
| 409 | var div = document.createElement('div'); |
| 410 | |
| 411 | div.appendChild(queryPanel.element()); |
| 412 | KorAP.Panel = KorAP.Panel || {}; |
| 413 | KorAP.Panel['query'] = queryPanel; |
| 414 | expect(KorAP.Plugin.buttonGroup('query').length).toEqual(0); |
| 415 | |
| 416 | // Clean up |
| 417 | KorAP.Panel['query'] = undefined; |
| 418 | KorAP.Plugin.destroy(); |
| 419 | KorAP.Plugin = undefined; |
| 420 | }); |
Akron | 2d0d96d | 2019-11-18 19:49:50 +0100 | [diff] [blame] | 421 | }); |
hebasta | 043e96f | 2019-11-28 12:33:00 +0100 | [diff] [blame] | 422 | |
Akron | 45308ce | 2020-08-28 14:10:23 +0200 | [diff] [blame] | 423 | describe('KorAP.Plugin.ResultPanel', function () { |
hebasta | 043e96f | 2019-11-28 12:33:00 +0100 | [diff] [blame] | 424 | it('Plugin is registered second: buttons should be added to panel', function () { |
| 425 | |
| 426 | var resultPanel = resultPanelClass.create(); |
| 427 | resultPanel.addAlignAction(); |
| 428 | var div = document.createElement('div'); |
| 429 | |
| 430 | div.appendChild(resultPanel.element()); |
| 431 | KorAP.Panel = KorAP.Panel || {}; |
| 432 | KorAP.Panel['result'] = resultPanel; |
| 433 | |
| 434 | // Register plugin afterwards |
| 435 | var manager = pluginServerClass.create(); |
| 436 | |
| 437 | manager.register({ |
| 438 | name : 'ResultPlugin', |
| 439 | embed : [{ |
| 440 | panel : 'result', |
| 441 | title : 'Dosomething', |
| 442 | onClick : { |
| 443 | template : 'test' |
| 444 | } |
| 445 | }] |
| 446 | }); |
| 447 | |
| 448 | expect(manager.buttonGroup('result').length).toEqual(0); |
| 449 | expect(KorAP.Panel['result'].actions.element().innerHTML).toContain('Dosomething'); |
| 450 | |
| 451 | // Clean up |
| 452 | KorAP.Panel['result'] = undefined; |
| 453 | manager.destroy(); |
Akron | 45308ce | 2020-08-28 14:10:23 +0200 | [diff] [blame] | 454 | }); |
hebasta | 043e96f | 2019-11-28 12:33:00 +0100 | [diff] [blame] | 455 | |
| 456 | it('Plugin is registered first: Buttons should be added to panel and cleared', function () { |
| 457 | |
| 458 | // Register plugin first |
| 459 | KorAP.Plugin = pluginServerClass.create(); |
| 460 | |
| 461 | KorAP.Plugin.register({ |
| 462 | name : 'ResultPlugin', |
| 463 | embed : [{ |
| 464 | panel : 'result', |
| 465 | title : 'Dosomething', |
| 466 | onClick : { |
| 467 | template : 'test' |
| 468 | } |
| 469 | }] |
| 470 | }); |
| 471 | |
| 472 | expect(KorAP.Plugin.buttonGroup('result').length).toEqual(1); |
| 473 | |
| 474 | var resultPanel = resultPanelClass.create(); |
| 475 | var div = document.createElement('div'); |
| 476 | div.appendChild(resultPanel.element()); |
| 477 | KorAP.Panel = KorAP.Panel || {}; |
| 478 | KorAP.Panel['result'] = resultPanel; |
| 479 | expect(KorAP.Plugin.buttonGroup('result').length).toEqual(0); |
| 480 | expect(KorAP.Panel['result'].actions.element().innerHTML).toContain('Dosomething'); |
| 481 | |
| 482 | // Clean up |
| 483 | KorAP.Panel['result'] = undefined; |
| 484 | KorAP.Plugin.destroy(); |
| 485 | KorAP.Plugin = undefined; |
| 486 | }); |
| 487 | }); |
Akron | fec66a3 | 2020-08-28 13:01:14 +0200 | [diff] [blame] | 488 | |
| 489 | describe('KorAP.Plugin communications', function () { |
| 490 | it('should receive messages', function () { |
| 491 | var manager = pluginServerClass.create(); |
Akron | bb89198 | 2020-10-05 16:07:18 +0200 | [diff] [blame] | 492 | var id = manager.addService({"name":'Example 1', "src":'about:blank'}); |
Akron | fec66a3 | 2020-08-28 13:01:14 +0200 | [diff] [blame] | 493 | expect(id).toMatch(/^id-/); |
Akron | fec66a3 | 2020-08-28 13:01:14 +0200 | [diff] [blame] | 494 | var temp = KorAP.koralQuery; |
| 495 | KorAP.koralQuery = { "@type" : "koral:test" }; |
Akron | fec66a3 | 2020-08-28 13:01:14 +0200 | [diff] [blame] | 496 | let data = { |
| 497 | "originID" : id, |
| 498 | "action" : "get", |
| 499 | "key" : "KQ" |
| 500 | }; |
Akron | fec66a3 | 2020-08-28 13:01:14 +0200 | [diff] [blame] | 501 | manager._receiveMsg({ |
| 502 | "data" : data |
| 503 | }); |
Akron | fec66a3 | 2020-08-28 13:01:14 +0200 | [diff] [blame] | 504 | manager.destroy(); |
Akron | fec66a3 | 2020-08-28 13:01:14 +0200 | [diff] [blame] | 505 | expect(data.value["@type"]).toEqual("koral:test"); |
Akron | fec66a3 | 2020-08-28 13:01:14 +0200 | [diff] [blame] | 506 | // Recreate initial state |
| 507 | KorAP.koralQuery = temp; |
| 508 | }); |
| 509 | |
Akron | fec66a3 | 2020-08-28 13:01:14 +0200 | [diff] [blame] | 510 | it('should add to pipe', function () { |
| 511 | var manager = pluginServerClass.create(); |
Akron | fec66a3 | 2020-08-28 13:01:14 +0200 | [diff] [blame] | 512 | var temp = KorAP.Pipe; |
| 513 | KorAP.Pipe = pipeClass.create(); |
Akron | fec66a3 | 2020-08-28 13:01:14 +0200 | [diff] [blame] | 514 | expect(KorAP.Pipe.toString()).toEqual(""); |
| 515 | |
Akron | bb89198 | 2020-10-05 16:07:18 +0200 | [diff] [blame] | 516 | var id = manager.addService({"name":'Example 2', "src":'about:blank'}); |
Akron | fec66a3 | 2020-08-28 13:01:14 +0200 | [diff] [blame] | 517 | expect(id).toMatch(/^id-/); |
Akron | fec66a3 | 2020-08-28 13:01:14 +0200 | [diff] [blame] | 518 | manager._receiveMsg({ |
| 519 | "data" : { |
| 520 | "originID" : id, |
| 521 | "action" : "pipe", |
| 522 | "job" : "add", |
| 523 | "service" : "https://pipe-service.de" |
| 524 | } |
| 525 | }); |
Akron | fec66a3 | 2020-08-28 13:01:14 +0200 | [diff] [blame] | 526 | expect(KorAP.Pipe.toString()).toEqual("https://pipe-service.de"); |
Akron | fec66a3 | 2020-08-28 13:01:14 +0200 | [diff] [blame] | 527 | manager._receiveMsg({ |
| 528 | "data" : { |
| 529 | "originID" : id, |
| 530 | "action" : "pipe", |
| 531 | "job" : "add", |
| 532 | "service" : "https://pipe-service-2.de" |
| 533 | } |
| 534 | }); |
Akron | fec66a3 | 2020-08-28 13:01:14 +0200 | [diff] [blame] | 535 | 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] | 536 | manager._receiveMsg({ |
| 537 | "data" : { |
| 538 | "originID" : id, |
| 539 | "action" : "pipe", |
| 540 | "job" : "del", |
| 541 | "service" : "https://pipe-service.de" |
| 542 | } |
| 543 | }); |
Akron | fec66a3 | 2020-08-28 13:01:14 +0200 | [diff] [blame] | 544 | expect(KorAP.Pipe.toString()).toEqual("https://pipe-service-2.de"); |
Akron | fec66a3 | 2020-08-28 13:01:14 +0200 | [diff] [blame] | 545 | manager.destroy(); |
Akron | fec66a3 | 2020-08-28 13:01:14 +0200 | [diff] [blame] | 546 | // Recreate initial state |
| 547 | KorAP.Pipe = temp; |
| 548 | }); |
Akron | 45308ce | 2020-08-28 14:10:23 +0200 | [diff] [blame] | 549 | |
| 550 | it('should reply to query information requests', function () { |
| 551 | var manager = pluginServerClass.create(); |
Akron | bb89198 | 2020-10-05 16:07:18 +0200 | [diff] [blame] | 552 | var id = manager.addService({"name":'Service', "src":'about:blank'}); |
Akron | 45308ce | 2020-08-28 14:10:23 +0200 | [diff] [blame] | 553 | expect(id).toMatch(/^id-/); |
| 554 | var temp = KorAP.vc; |
| 555 | // Create form for query form information |
| 556 | let f = document.createElement('form'); |
| 557 | var qfield = f.addE('input'); |
| 558 | qfield.setAttribute("id", "q-field"); |
| 559 | qfield.value = "[orth=Baum]"; |
| 560 | var qlfield = f.addE('select'); |
| 561 | qlfield.setAttribute("id", "ql-field"); |
| 562 | qlfield.addE('option').setAttribute('value', 'cosmas-2'); |
| 563 | qlfield.addE('option').setAttribute('value', 'poliqarp'); |
| 564 | qlfield.selectedIndex = 1; |
| 565 | |
| 566 | KorAP.vc = vcClass.create().fromJson({ |
| 567 | "key" : "title", |
| 568 | "type" : "type:regex", |
| 569 | "value" : "[^b]ee.+?", |
| 570 | "@type" : "koral:doc" |
| 571 | }); |
| 572 | // console.log(KorAP.vc.toQuery()); |
| 573 | |
| 574 | document.body.appendChild(f); |
| 575 | let data = { |
| 576 | "originID" : id, |
| 577 | "action" : "get", |
| 578 | "key" : "QueryForm" |
| 579 | }; |
| 580 | manager._receiveMsg({ |
| 581 | "data" : data |
| 582 | }); |
| 583 | manager.destroy(); |
| 584 | expect(data.value["q"]).toEqual("[orth=Baum]"); |
| 585 | expect(data.value["ql"]).toEqual("poliqarp"); |
| 586 | expect(data.value["cq"]).toEqual("title = /[^b]ee.+?/"); |
| 587 | // Recreate initial state |
| 588 | KorAP.vc = temp; |
| 589 | document.body.removeChild(f); |
| 590 | }); |
Akron | fec66a3 | 2020-08-28 13:01:14 +0200 | [diff] [blame] | 591 | }); |
Akron | b43c8c6 | 2018-07-04 18:27:28 +0200 | [diff] [blame] | 592 | }); |