blob: 0694070aa36c4a02edb6d182ae972b3e049e5105 [file] [log] [blame]
Akron4a703872018-07-26 10:59:41 +02001define(['plugin/server','plugin/widget','panel'], function (pluginServerClass, widgetClass, panelClass) {
Akronb43c8c62018-07-04 18:27:28 +02002
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
Akron4a703872018-07-26 10:59:41 +020011
Akronb43c8c62018-07-04 18:27:28 +020012 it('should add a widget', function () {
13 var manager = pluginServerClass.create();
Akron4a703872018-07-26 10:59:41 +020014 var panel = panelClass.create();
15 var id = manager.addWidget(panel, 'Example 1', 'about:blank');
Akronb43c8c62018-07-04 18:27:28 +020016 expect(id).toMatch(/^id-/);
Akron4a703872018-07-26 10:59:41 +020017
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
Akronb43c8c62018-07-04 18:27:28 +020028 manager.destroy();
29 });
Akron10a47962018-07-12 21:17:10 +020030
Akron4a703872018-07-26 10:59:41 +020031 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 () {
Akron10a47962018-07-12 21:17:10 +020053 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"));
Akron10a47962018-07-12 21:17:10 +020074 });
Akronb43c8c62018-07-04 18:27:28 +020075 });
76
77 describe('KorAP.Plugin.Widget', function () {
78 it('should be initializable', function () {
Akron56a11af2018-07-27 18:28:45 +020079 expect(function () { widgetClass.create() }).toThrow(new Error("Widget not well defined"));
80
81 widget = widgetClass.create("Test", "https://example", 56);
Akronb43c8c62018-07-04 18:27:28 +020082 expect(widget).toBeTruthy();
Akron56a11af2018-07-27 18:28:45 +020083 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');
Akronb43c8c62018-07-04 18:27:28 +0200125 });
126 });
Akronb43c8c62018-07-04 18:27:28 +0200127});