Akron | 4a70387 | 2018-07-26 10:59:41 +0200 | [diff] [blame^] | 1 | define(['plugin/server','plugin/widget','panel'], function (pluginServerClass, widgetClass, panelClass) { |
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 | |
Akron | 4a70387 | 2018-07-26 10:59:41 +0200 | [diff] [blame^] | 11 | |
Akron | b43c8c6 | 2018-07-04 18:27:28 +0200 | [diff] [blame] | 12 | it('should add a widget', function () { |
| 13 | var manager = pluginServerClass.create(); |
Akron | 4a70387 | 2018-07-26 10:59:41 +0200 | [diff] [blame^] | 14 | var panel = panelClass.create(); |
| 15 | var id = manager.addWidget(panel, 'Example 1', 'about:blank'); |
Akron | b43c8c6 | 2018-07-04 18:27:28 +0200 | [diff] [blame] | 16 | expect(id).toMatch(/^id-/); |
Akron | 4a70387 | 2018-07-26 10:59:41 +0200 | [diff] [blame^] | 17 | |
| 18 | var panelE = panel.element(); |
| 19 | var widgetE = panelE.firstChild.firstChild; |
| 20 | expect(widgetE.classList.contains('widget')).toBeTruthy(); |
| 21 | expect(widgetE.firstChild.tagName).toEqual("IFRAME"); |
| 22 | var iframe = widgetE.firstChild; |
| 23 | expect(iframe.getAttribute("src")).toEqual("about:blank"); |
| 24 | |
| 25 | expect(widgetE.lastChild.firstChild.textContent).toEqual("Close"); |
| 26 | expect(widgetE.lastChild.lastChild.textContent).toEqual("Example 1"); |
| 27 | |
Akron | b43c8c6 | 2018-07-04 18:27:28 +0200 | [diff] [blame] | 28 | manager.destroy(); |
| 29 | }); |
Akron | 10a4796 | 2018-07-12 21:17:10 +0200 | [diff] [blame] | 30 | |
Akron | 4a70387 | 2018-07-26 10:59:41 +0200 | [diff] [blame^] | 31 | it('should close a widget', function () { |
| 32 | var manager = pluginServerClass.create(); |
| 33 | var panel = panelClass.create(); |
| 34 | var id = manager.addWidget(panel, 'Example 2', 'about:blank'); |
| 35 | expect(id).toMatch(/^id-/); |
| 36 | |
| 37 | var panelE = panel.element(); |
| 38 | var widgetE = panelE.firstChild.firstChild; |
| 39 | expect(widgetE.classList.contains('widget')).toBeTruthy(); |
| 40 | |
| 41 | expect(panelE.getElementsByClassName('view').length).toEqual(1); |
| 42 | |
| 43 | var widget = manager.widget(id); |
| 44 | widget.close(); |
| 45 | |
| 46 | expect(panelE.getElementsByClassName('view').length).toEqual(0); |
| 47 | |
| 48 | manager.destroy(); |
| 49 | }); |
| 50 | |
| 51 | |
| 52 | it('should fail on invalid registrations', function () { |
Akron | 10a4796 | 2018-07-12 21:17:10 +0200 | [diff] [blame] | 53 | var manager = pluginServerClass.create(); |
| 54 | |
| 55 | expect( |
| 56 | function() { manager.register({}) } |
| 57 | ).toThrow(new Error("Missing name of plugin")); |
| 58 | |
| 59 | expect( |
| 60 | function() { manager.register({ |
| 61 | name : 'Example', |
| 62 | embed : '' |
| 63 | })} |
| 64 | ).toThrow(new Error("Embedding of plugin is no list")); |
| 65 | |
| 66 | expect( |
| 67 | function() { manager.register({ |
| 68 | name : 'Example', |
| 69 | embed : [{ |
| 70 | panel : '' |
| 71 | }] |
| 72 | })} |
| 73 | ).toThrow(new Error("Panel for plugin is invalid")); |
Akron | 10a4796 | 2018-07-12 21:17:10 +0200 | [diff] [blame] | 74 | }); |
Akron | b43c8c6 | 2018-07-04 18:27:28 +0200 | [diff] [blame] | 75 | }); |
| 76 | |
| 77 | describe('KorAP.Plugin.Widget', function () { |
| 78 | it('should be initializable', function () { |
| 79 | var widget = widgetClass.create(); |
| 80 | expect(widget).toBeTruthy(); |
| 81 | }); |
| 82 | }); |
| 83 | |
| 84 | }); |