blob: 9df1c220de4991d3ea7586b7b8d4988bf2d4e2cd [file] [log] [blame]
Akron362c11a2018-08-29 20:01:30 +02001define(['panel','view','panel/result','util'], function (panelClass,viewClass, resultClass) {
Akron56d42072018-07-24 11:17:24 +02002
3 var controlStr = "";
4
5 var helloViewClass = {
6 create : function () {
7 return Object.create(viewClass)._init(['myview']).upgradeTo(this);
8 },
9
10 show : function () {
11 if (this._show)
12 return this._show;
13
14 var e = document.createElement('span');
15 e.addT("Hello World!");
16
17 this._show = e;
18 return e;
19 }
20 };
hebastad025eb92019-12-07 21:04:42 +010021
22 var secViewClass = {
23 create : function () {
24 return Object.create(viewClass)._init(['secview']).upgradeTo(this);
25 },
26 };
Akron56d42072018-07-24 11:17:24 +020027
hebastad025eb92019-12-07 21:04:42 +010028
Akron56d42072018-07-24 11:17:24 +020029 describe('KorAP.View', function () {
30 it('should be initializable', function () {
31 var view = viewClass.create();
32
33 expect(view.shown()).toBeFalsy();
34
35 var e = view.element();
36 expect(view.shown()).toBeTruthy();
37
38 expect(e.tagName).toEqual("DIV");
39 expect(e.classList.contains("view")).toBeTruthy();
40
41 var btn = e.firstChild;
42 expect(btn.tagName).toEqual("DIV");
43 expect(btn.classList.contains("button-view")).toBeTruthy();
44 expect(btn.classList.contains("button-group")).toBeTruthy();
45
46 expect(btn.firstChild.tagName).toEqual("SPAN");
47 expect(btn.firstChild.getAttribute("title")).toEqual("Close");
48 expect(btn.firstChild.classList.contains("button-icon")).toBeTruthy();
49 expect(btn.firstChild.classList.contains("close")).toBeTruthy();
50 expect(btn.firstChild.firstChild.tagName).toEqual("SPAN");
51 expect(btn.firstChild.firstChild.firstChild.data).toEqual("Close");
52 });
53
54 it('should be classable', function () {
55 var view = viewClass.create(['versuch']);
56 var e = view.element();
57 expect(e.tagName).toEqual("DIV");
58 expect(e.classList.contains("view")).toBeTruthy();
59 expect(e.classList.contains("versuch")).toBeTruthy();
60
61 var btn = e.firstChild;
62 expect(btn.tagName).toEqual("DIV");
63 expect(btn.classList.contains("button-view")).toBeTruthy();
64 expect(btn.classList.contains("button-group")).toBeTruthy();
65 expect(btn.classList.contains("versuch")).toBeTruthy();
66 });
67 });
68
69 describe('KorAP.Panel', function () {
70
71 it('should be initializable', function () {
72 var panel = panelClass.create();
73 var e = panel.element();
74 expect(e.tagName).toEqual("DIV");
75 expect(e.classList.contains("panel")).toBeTruthy();
76 expect(e.firstChild.tagName).toEqual("DIV");
77
78 // No children in the empty view element
79 expect(e.firstChild.firstChild).toBeFalsy();
80 expect(e.lastChild.tagName).toEqual("DIV");
81 expect(e.lastChild.classList.contains("button-panel")).toBeTruthy();
82 expect(e.lastChild.classList.contains("button-group")).toBeTruthy();
83 expect(e.lastChild.firstChild).toBeFalsy();
84
85 expect(panel.actions).toBeTruthy();
86 });
87
88
89 it('should be extensible', function () {
90 var panel = panelClass.create();
91
92 controlStr = "";
93 panel.actions.add("New", ["new"], function () {
94 controlStr = 'New!!!';
95 });
96
97 var e = panel.element();
98
99 expect(e.tagName).toEqual("DIV");
100 expect(e.firstChild.firstChild).toBeFalsy();
101
102 expect(e.lastChild.firstChild.tagName).toEqual("SPAN");
103 expect(e.lastChild.firstChild.getAttribute("title")).toEqual("New");
104 expect(e.lastChild.firstChild.classList.contains("new")).toBeTruthy();
105 expect(e.lastChild.firstChild.firstChild.tagName).toEqual("SPAN");
106 expect(e.lastChild.firstChild.firstChild.firstChild.data).toEqual("New");
107
108 expect(controlStr).toEqual("");
109 e.lastChild.firstChild.click();
110 expect(controlStr).toEqual("New!!!");
111 });
112
113 it('should be classable', function () {
114 var panel = panelClass.create(["versuch"]);
115 var e = panel.element();
116 expect(e.tagName).toEqual("DIV");
117 expect(e.classList.contains("panel")).toBeTruthy();
118 expect(e.classList.contains("versuch")).toBeTruthy();
119 expect(e.lastChild.classList.contains("button-panel")).toBeTruthy();
120 expect(e.lastChild.classList.contains("versuch")).toBeTruthy();
121 });
122
123 it('should be extensible by a view', function () {
124 var panel = panelClass.create();
125 var view = helloViewClass.create();
126 var e = panel.element();
127
128 panel.add(view);
129
130 var viewE = e.firstChild.firstChild;
131 expect(viewE.classList.contains('view')).toBeTruthy();
132 expect(viewE.classList.contains('myview')).toBeTruthy();
133 expect(viewE.firstChild.tagName).toEqual("SPAN");
134 expect(viewE.firstChild.firstChild.data).toEqual("Hello World!");
135 });
hebastad025eb92019-12-07 21:04:42 +0100136
137 it('views should be appended or prepended', function () {
138 let panel = panelClass.create();
139 let view = helloViewClass.create();
140 let e = panel.element();
141 panel.add(view);
142 let secview = secViewClass.create();
143 panel.add(secview);
144 let viewFirst = e.firstChild.firstChild;
145 expect(viewFirst.classList.contains('myview')).toBeTruthy();
146
147 let prependPanel = panelClass.create();
148 prependPanel.prepend = true;
149 prependPanel.add(view);
150 prependPanel.add(secview);
151 viewFirst = prependPanel.element().firstChild.firstChild;
152 expect(viewFirst.classList.contains('secview')).toBeTruthy();
153 });
154
Akron56d42072018-07-24 11:17:24 +0200155 });
Akron362c11a2018-08-29 20:01:30 +0200156
157 describe('KorAP.Panel.Result', function () {
158
159 it('should be initializable', function () {
160 var show = {};
161 var result = resultClass.create(show);
162 expect(result.element().children.length).toEqual(2);
163 expect(result.element().firstChild.children.length).toEqual(0);
164 });
165
166 it('should open KQAction', function () {
167 var show = {};
168 var result = resultClass.create(show);
169
170 result.addKqAction();
171
172 expect(result.element().lastChild.firstChild.textContent).toEqual("show KoralQuery");
173 expect(show["kq"]).toBeFalsy();
174
175 // Open KQ view
176 result.element().lastChild.firstChild.click();
177
178 expect(result.element().querySelector('#koralquery').textContent).toEqual("{}");
179 expect(show["kq"]).toBeTruthy();
180
181 var close = result.element().firstChild.firstChild.lastChild.firstChild;
182 expect(close.textContent).toEqual("Close");
183
184 // Close view
185 close.click();
186
187 expect(result.element().querySelector('#koralquery')).toBeFalsy();
188 expect(show["kq"]).toBeFalsy();
189 });
190 });
Akron56d42072018-07-24 11:17:24 +0200191});