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 | }); |
Akron | 3d01380 | 2020-10-07 15:03:38 +0200 | [diff] [blame] | 116 | |
Akron | 2d0d96d | 2019-11-18 19:49:50 +0100 | [diff] [blame] | 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 | |
Akron | ba09ed2 | 2020-10-01 16:01:45 +0200 | [diff] [blame] | 195 | 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 | |
| 212 | let b = p.actions.element().firstChild; |
| 213 | 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); |
Akron | fcf89db | 2020-10-01 17:40:20 +0200 | [diff] [blame] | 229 | |
| 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); |
Akron | fb11a96 | 2020-10-05 12:12:55 +0200 | [diff] [blame] | 239 | expect(p.element().querySelector("iframe").getAttribute('sandbox')).toEqual(''); |
Akron | ba09ed2 | 2020-10-01 16:01:45 +0200 | [diff] [blame] | 240 | |
| 241 | manager.destroy(); |
| 242 | |
| 243 | KorAP.Panel["result"] = undefined; |
| 244 | }); |
Akron | fb11a96 | 2020-10-05 12:12:55 +0200 | [diff] [blame] | 245 | |
Akron | 3d01380 | 2020-10-07 15:03:38 +0200 | [diff] [blame] | 246 | 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 | |
| 271 | let b = p.actions.element().firstChild; |
| 272 | 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 | |
| 310 | let b = p.actions.element().firstChild; |
| 311 | 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 | |
Akron | fb11a96 | 2020-10-05 12:12:55 +0200 | [diff] [blame] | 323 | 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', |
Akron | ce0d882 | 2020-10-05 16:25:40 +0200 | [diff] [blame] | 336 | permissions: ['scripts', 'forms', 'all'] |
Akron | fb11a96 | 2020-10-05 12:12:55 +0200 | [diff] [blame] | 337 | } |
| 338 | }] |
| 339 | }); |
| 340 | |
| 341 | let b = p.actions.element().firstChild; |
| 342 | 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 | }); |
Akron | b43c8c6 | 2018-07-04 18:27:28 +0200 | [diff] [blame] | 346 | }); |
Akron | 2d0d96d | 2019-11-18 19:49:50 +0100 | [diff] [blame] | 347 | |
Akron | b43c8c6 | 2018-07-04 18:27:28 +0200 | [diff] [blame] | 348 | describe('KorAP.Plugin.Widget', function () { |
| 349 | it('should be initializable', function () { |
Akron | 22598cd | 2019-12-09 14:59:03 +0100 | [diff] [blame] | 350 | expect(function () { widgetClass.create() }).toThrow(new Error("Service not well defined")); |
Akron | 56a11af | 2018-07-27 18:28:45 +0200 | [diff] [blame] | 351 | |
Akron | bb89198 | 2020-10-05 16:07:18 +0200 | [diff] [blame] | 352 | widget = widgetClass.create({"name" : "Test", "src":"https://example", "id":56}); |
Akron | b43c8c6 | 2018-07-04 18:27:28 +0200 | [diff] [blame] | 353 | expect(widget).toBeTruthy(); |
Akron | 56a11af | 2018-07-27 18:28:45 +0200 | [diff] [blame] | 354 | 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 () { |
Akron | bb89198 | 2020-10-05 16:07:18 +0200 | [diff] [blame] | 360 | var widget = widgetClass.create({ |
| 361 | "name":"Test", |
| 362 | "src":"https://example", |
| 363 | "id":56, |
Akron | ce0d882 | 2020-10-05 16:25:40 +0200 | [diff] [blame] | 364 | "permissions":["scripts","forms"] |
Akron | bb89198 | 2020-10-05 16:07:18 +0200 | [diff] [blame] | 365 | }); |
Akron | 56a11af | 2018-07-27 18:28:45 +0200 | [diff] [blame] | 366 | 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"); |
Akron | fb11a96 | 2020-10-05 12:12:55 +0200 | [diff] [blame] | 374 | expect(iframe.getAttribute("sandbox")).toEqual("allow-forms allow-scripts"); |
Akron | 56a11af | 2018-07-27 18:28:45 +0200 | [diff] [blame] | 375 | expect(iframe.getAttribute("src")).toEqual("https://example"); |
| 376 | expect(iframe.getAttribute("name")).toEqual("56"); |
Akron | fb11a96 | 2020-10-05 12:12:55 +0200 | [diff] [blame] | 377 | |
Akron | 56a11af | 2018-07-27 18:28:45 +0200 | [diff] [blame] | 378 | 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 | }) |
Akron | fb11a96 | 2020-10-05 12:12:55 +0200 | [diff] [blame] | 394 | |
Akron | 56a11af | 2018-07-27 18:28:45 +0200 | [diff] [blame] | 395 | it('should be resizable', function () { |
Akron | bb89198 | 2020-10-05 16:07:18 +0200 | [diff] [blame] | 396 | var widget = widgetClass.create({"name":"Test", "src":"https://example", "id":56}); |
Akron | 56a11af | 2018-07-27 18:28:45 +0200 | [diff] [blame] | 397 | var iframe = widget.show(); |
| 398 | expect(iframe.style.height).toEqual('0px'); |
| 399 | widget.resize({ height : 9 }); |
| 400 | expect(iframe.style.height).toEqual('9px'); |
Akron | b43c8c6 | 2018-07-04 18:27:28 +0200 | [diff] [blame] | 401 | }); |
Akron | 3d9ce5e | 2020-10-01 15:18:36 +0200 | [diff] [blame] | 402 | |
| 403 | it('should be minimizable', function () { |
Akron | bb89198 | 2020-10-05 16:07:18 +0200 | [diff] [blame] | 404 | var widget = widgetClass.create({"name":"Test", "src":"https://example", "id":56}); |
Akron | 3d9ce5e | 2020-10-01 15:18:36 +0200 | [diff] [blame] | 405 | var we = widget.element(); |
| 406 | expect(we.classList.contains('show')).toBeTruthy(); |
| 407 | widget.minimize(); |
| 408 | expect(we.classList.contains('show')).toBeFalsy(); |
| 409 | }); |
Akron | b43c8c6 | 2018-07-04 18:27:28 +0200 | [diff] [blame] | 410 | }); |
Akron | 2d0d96d | 2019-11-18 19:49:50 +0100 | [diff] [blame] | 411 | |
Akron | 22598cd | 2019-12-09 14:59:03 +0100 | [diff] [blame] | 412 | describe('KorAP.Plugin.Service', function () { |
| 413 | it('should be initializable', function () { |
| 414 | expect(function () { serviceClass.create() }).toThrow(new Error("Service not well defined")); |
| 415 | |
Akron | bb89198 | 2020-10-05 16:07:18 +0200 | [diff] [blame] | 416 | let service = serviceClass.create({"name":"Test", "src":"https://example", "id":56}); |
Akron | 22598cd | 2019-12-09 14:59:03 +0100 | [diff] [blame] | 417 | 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 () { |
Akron | bb89198 | 2020-10-05 16:07:18 +0200 | [diff] [blame] | 424 | let service = serviceClass.create({"name":"Test", "src":"https://example", "id":56}); |
Akron | 22598cd | 2019-12-09 14:59:03 +0100 | [diff] [blame] | 425 | 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 | |
Akron | 2d0d96d | 2019-11-18 19:49:50 +0100 | [diff] [blame] | 436 | 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 | }); |
hebasta | f6adf8d | 2019-11-26 14:04:10 +0100 | [diff] [blame] | 466 | |
| 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 | }); |
Akron | 2d0d96d | 2019-11-18 19:49:50 +0100 | [diff] [blame] | 497 | }); |
hebasta | 043e96f | 2019-11-28 12:33:00 +0100 | [diff] [blame] | 498 | |
Akron | 45308ce | 2020-08-28 14:10:23 +0200 | [diff] [blame] | 499 | describe('KorAP.Plugin.ResultPanel', function () { |
hebasta | 043e96f | 2019-11-28 12:33:00 +0100 | [diff] [blame] | 500 | 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); |
| 525 | expect(KorAP.Panel['result'].actions.element().innerHTML).toContain('Dosomething'); |
| 526 | |
| 527 | // Clean up |
| 528 | KorAP.Panel['result'] = undefined; |
| 529 | manager.destroy(); |
Akron | 45308ce | 2020-08-28 14:10:23 +0200 | [diff] [blame] | 530 | }); |
hebasta | 043e96f | 2019-11-28 12:33:00 +0100 | [diff] [blame] | 531 | |
| 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); |
| 556 | expect(KorAP.Panel['result'].actions.element().innerHTML).toContain('Dosomething'); |
| 557 | |
| 558 | // Clean up |
| 559 | KorAP.Panel['result'] = undefined; |
| 560 | KorAP.Plugin.destroy(); |
| 561 | KorAP.Plugin = undefined; |
| 562 | }); |
| 563 | }); |
Akron | fec66a3 | 2020-08-28 13:01:14 +0200 | [diff] [blame] | 564 | |
| 565 | describe('KorAP.Plugin communications', function () { |
| 566 | it('should receive messages', function () { |
| 567 | var manager = pluginServerClass.create(); |
Akron | bb89198 | 2020-10-05 16:07:18 +0200 | [diff] [blame] | 568 | var id = manager.addService({"name":'Example 1', "src":'about:blank'}); |
Akron | fec66a3 | 2020-08-28 13:01:14 +0200 | [diff] [blame] | 569 | expect(id).toMatch(/^id-/); |
Akron | fec66a3 | 2020-08-28 13:01:14 +0200 | [diff] [blame] | 570 | var temp = KorAP.koralQuery; |
| 571 | KorAP.koralQuery = { "@type" : "koral:test" }; |
Akron | fec66a3 | 2020-08-28 13:01:14 +0200 | [diff] [blame] | 572 | let data = { |
| 573 | "originID" : id, |
| 574 | "action" : "get", |
| 575 | "key" : "KQ" |
| 576 | }; |
Akron | fec66a3 | 2020-08-28 13:01:14 +0200 | [diff] [blame] | 577 | manager._receiveMsg({ |
| 578 | "data" : data |
| 579 | }); |
Akron | fec66a3 | 2020-08-28 13:01:14 +0200 | [diff] [blame] | 580 | manager.destroy(); |
Akron | fec66a3 | 2020-08-28 13:01:14 +0200 | [diff] [blame] | 581 | expect(data.value["@type"]).toEqual("koral:test"); |
Akron | fec66a3 | 2020-08-28 13:01:14 +0200 | [diff] [blame] | 582 | // Recreate initial state |
| 583 | KorAP.koralQuery = temp; |
| 584 | }); |
| 585 | |
Akron | fec66a3 | 2020-08-28 13:01:14 +0200 | [diff] [blame] | 586 | it('should add to pipe', function () { |
| 587 | var manager = pluginServerClass.create(); |
Akron | fec66a3 | 2020-08-28 13:01:14 +0200 | [diff] [blame] | 588 | var temp = KorAP.Pipe; |
| 589 | KorAP.Pipe = pipeClass.create(); |
Akron | fec66a3 | 2020-08-28 13:01:14 +0200 | [diff] [blame] | 590 | expect(KorAP.Pipe.toString()).toEqual(""); |
| 591 | |
Akron | bb89198 | 2020-10-05 16:07:18 +0200 | [diff] [blame] | 592 | var id = manager.addService({"name":'Example 2', "src":'about:blank'}); |
Akron | fec66a3 | 2020-08-28 13:01:14 +0200 | [diff] [blame] | 593 | expect(id).toMatch(/^id-/); |
Akron | fec66a3 | 2020-08-28 13:01:14 +0200 | [diff] [blame] | 594 | manager._receiveMsg({ |
| 595 | "data" : { |
| 596 | "originID" : id, |
| 597 | "action" : "pipe", |
| 598 | "job" : "add", |
| 599 | "service" : "https://pipe-service.de" |
| 600 | } |
| 601 | }); |
Akron | fec66a3 | 2020-08-28 13:01:14 +0200 | [diff] [blame] | 602 | expect(KorAP.Pipe.toString()).toEqual("https://pipe-service.de"); |
Akron | fec66a3 | 2020-08-28 13:01:14 +0200 | [diff] [blame] | 603 | manager._receiveMsg({ |
| 604 | "data" : { |
| 605 | "originID" : id, |
| 606 | "action" : "pipe", |
| 607 | "job" : "add", |
| 608 | "service" : "https://pipe-service-2.de" |
| 609 | } |
| 610 | }); |
Akron | fec66a3 | 2020-08-28 13:01:14 +0200 | [diff] [blame] | 611 | 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] | 612 | manager._receiveMsg({ |
| 613 | "data" : { |
| 614 | "originID" : id, |
| 615 | "action" : "pipe", |
| 616 | "job" : "del", |
| 617 | "service" : "https://pipe-service.de" |
| 618 | } |
| 619 | }); |
Akron | fec66a3 | 2020-08-28 13:01:14 +0200 | [diff] [blame] | 620 | expect(KorAP.Pipe.toString()).toEqual("https://pipe-service-2.de"); |
Akron | fec66a3 | 2020-08-28 13:01:14 +0200 | [diff] [blame] | 621 | manager.destroy(); |
Akron | fec66a3 | 2020-08-28 13:01:14 +0200 | [diff] [blame] | 622 | // Recreate initial state |
| 623 | KorAP.Pipe = temp; |
| 624 | }); |
Akron | 45308ce | 2020-08-28 14:10:23 +0200 | [diff] [blame] | 625 | |
| 626 | it('should reply to query information requests', function () { |
| 627 | var manager = pluginServerClass.create(); |
Akron | bb89198 | 2020-10-05 16:07:18 +0200 | [diff] [blame] | 628 | var id = manager.addService({"name":'Service', "src":'about:blank'}); |
Akron | 45308ce | 2020-08-28 14:10:23 +0200 | [diff] [blame] | 629 | 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 | }); |
Akron | fec66a3 | 2020-08-28 13:01:14 +0200 | [diff] [blame] | 667 | }); |
Akron | b43c8c6 | 2018-07-04 18:27:28 +0200 | [diff] [blame] | 668 | }); |