blob: b11dc7ab1c5115ada4c0586f16a2c07a29c43ba4 [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 () {
79 var widget = widgetClass.create();
80 expect(widget).toBeTruthy();
81 });
82 });
83
84});