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 () { |
Akron | 56a11af | 2018-07-27 18:28:45 +0200 | [diff] [blame^] | 79 | expect(function () { widgetClass.create() }).toThrow(new Error("Widget not well defined")); |
| 80 | |
| 81 | widget = widgetClass.create("Test", "https://example", 56); |
Akron | b43c8c6 | 2018-07-04 18:27:28 +0200 | [diff] [blame] | 82 | expect(widget).toBeTruthy(); |
Akron | 56a11af | 2018-07-27 18:28:45 +0200 | [diff] [blame^] | 83 | expect(widget.id).toEqual(56); |
| 84 | expect(widget.name).toEqual("Test"); |
| 85 | expect(widget.src).toEqual("https://example"); |
| 86 | }); |
| 87 | |
| 88 | it('should create a view element', function () { |
| 89 | var widget = widgetClass.create("Test", "https://example", 56); |
| 90 | var we = widget.element(); |
| 91 | |
| 92 | expect(we.tagName).toEqual("DIV"); |
| 93 | expect(we.classList.contains('view')).toBeTruthy(); |
| 94 | expect(we.classList.contains('widget')).toBeTruthy(); |
| 95 | |
| 96 | var iframe = we.firstChild; |
| 97 | expect(iframe.tagName).toEqual("IFRAME"); |
| 98 | expect(iframe.getAttribute("sandbox")).toEqual("allow-scripts"); |
| 99 | expect(iframe.getAttribute("src")).toEqual("https://example"); |
| 100 | expect(iframe.getAttribute("name")).toEqual("56"); |
| 101 | |
| 102 | var btn = we.lastChild; |
| 103 | expect(btn.classList.contains("button-group")).toBeTruthy(); |
| 104 | expect(btn.classList.contains("button-view")).toBeTruthy(); |
| 105 | expect(btn.classList.contains("widget")).toBeTruthy(); |
| 106 | |
| 107 | expect(btn.firstChild.tagName).toEqual("SPAN"); |
| 108 | expect(btn.firstChild.classList.contains("button-icon")).toBeTruthy(); |
| 109 | expect(btn.firstChild.classList.contains("close")).toBeTruthy(); |
| 110 | expect(btn.firstChild.firstChild.tagName).toEqual("SPAN"); |
| 111 | |
| 112 | expect(btn.lastChild.tagName).toEqual("SPAN"); |
| 113 | expect(btn.lastChild.classList.contains("button-icon")).toBeTruthy(); |
| 114 | expect(btn.lastChild.classList.contains("plugin")).toBeTruthy(); |
| 115 | expect(btn.lastChild.firstChild.tagName).toEqual("SPAN"); |
| 116 | expect(btn.lastChild.textContent).toEqual("Test"); |
| 117 | }) |
| 118 | |
| 119 | it('should be resizable', function () { |
| 120 | var widget = widgetClass.create("Test", "https://example", 56); |
| 121 | var iframe = widget.show(); |
| 122 | expect(iframe.style.height).toEqual('0px'); |
| 123 | widget.resize({ height : 9 }); |
| 124 | expect(iframe.style.height).toEqual('9px'); |
Akron | b43c8c6 | 2018-07-04 18:27:28 +0200 | [diff] [blame] | 125 | }); |
| 126 | }); |
Akron | b43c8c6 | 2018-07-04 18:27:28 +0200 | [diff] [blame] | 127 | }); |