blob: bc065fd2dfe542eff3c610a57adb047789e6cd1b [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 };
21
22 describe('KorAP.View', function () {
23 it('should be initializable', function () {
24 var view = viewClass.create();
25
26 expect(view.shown()).toBeFalsy();
27
28 var e = view.element();
29 expect(view.shown()).toBeTruthy();
30
31 expect(e.tagName).toEqual("DIV");
32 expect(e.classList.contains("view")).toBeTruthy();
33
34 var btn = e.firstChild;
35 expect(btn.tagName).toEqual("DIV");
36 expect(btn.classList.contains("button-view")).toBeTruthy();
37 expect(btn.classList.contains("button-group")).toBeTruthy();
38
39 expect(btn.firstChild.tagName).toEqual("SPAN");
40 expect(btn.firstChild.getAttribute("title")).toEqual("Close");
41 expect(btn.firstChild.classList.contains("button-icon")).toBeTruthy();
42 expect(btn.firstChild.classList.contains("close")).toBeTruthy();
43 expect(btn.firstChild.firstChild.tagName).toEqual("SPAN");
44 expect(btn.firstChild.firstChild.firstChild.data).toEqual("Close");
45 });
46
47 it('should be classable', function () {
48 var view = viewClass.create(['versuch']);
49 var e = view.element();
50 expect(e.tagName).toEqual("DIV");
51 expect(e.classList.contains("view")).toBeTruthy();
52 expect(e.classList.contains("versuch")).toBeTruthy();
53
54 var btn = e.firstChild;
55 expect(btn.tagName).toEqual("DIV");
56 expect(btn.classList.contains("button-view")).toBeTruthy();
57 expect(btn.classList.contains("button-group")).toBeTruthy();
58 expect(btn.classList.contains("versuch")).toBeTruthy();
59 });
60 });
61
62 describe('KorAP.Panel', function () {
63
64 it('should be initializable', function () {
65 var panel = panelClass.create();
66 var e = panel.element();
67 expect(e.tagName).toEqual("DIV");
68 expect(e.classList.contains("panel")).toBeTruthy();
69 expect(e.firstChild.tagName).toEqual("DIV");
70
71 // No children in the empty view element
72 expect(e.firstChild.firstChild).toBeFalsy();
73 expect(e.lastChild.tagName).toEqual("DIV");
74 expect(e.lastChild.classList.contains("button-panel")).toBeTruthy();
75 expect(e.lastChild.classList.contains("button-group")).toBeTruthy();
76 expect(e.lastChild.firstChild).toBeFalsy();
77
78 expect(panel.actions).toBeTruthy();
79 });
80
81
82 it('should be extensible', function () {
83 var panel = panelClass.create();
84
85 controlStr = "";
86 panel.actions.add("New", ["new"], function () {
87 controlStr = 'New!!!';
88 });
89
90 var e = panel.element();
91
92 expect(e.tagName).toEqual("DIV");
93 expect(e.firstChild.firstChild).toBeFalsy();
94
95 expect(e.lastChild.firstChild.tagName).toEqual("SPAN");
96 expect(e.lastChild.firstChild.getAttribute("title")).toEqual("New");
97 expect(e.lastChild.firstChild.classList.contains("new")).toBeTruthy();
98 expect(e.lastChild.firstChild.firstChild.tagName).toEqual("SPAN");
99 expect(e.lastChild.firstChild.firstChild.firstChild.data).toEqual("New");
100
101 expect(controlStr).toEqual("");
102 e.lastChild.firstChild.click();
103 expect(controlStr).toEqual("New!!!");
104 });
105
106 it('should be classable', function () {
107 var panel = panelClass.create(["versuch"]);
108 var e = panel.element();
109 expect(e.tagName).toEqual("DIV");
110 expect(e.classList.contains("panel")).toBeTruthy();
111 expect(e.classList.contains("versuch")).toBeTruthy();
112 expect(e.lastChild.classList.contains("button-panel")).toBeTruthy();
113 expect(e.lastChild.classList.contains("versuch")).toBeTruthy();
114 });
115
116 it('should be extensible by a view', function () {
117 var panel = panelClass.create();
118 var view = helloViewClass.create();
119 var e = panel.element();
120
121 panel.add(view);
122
123 var viewE = e.firstChild.firstChild;
124 expect(viewE.classList.contains('view')).toBeTruthy();
125 expect(viewE.classList.contains('myview')).toBeTruthy();
126 expect(viewE.firstChild.tagName).toEqual("SPAN");
127 expect(viewE.firstChild.firstChild.data).toEqual("Hello World!");
128 });
129 });
Akron362c11a2018-08-29 20:01:30 +0200130
131 describe('KorAP.Panel.Result', function () {
132
133 it('should be initializable', function () {
134 var show = {};
135 var result = resultClass.create(show);
136 expect(result.element().children.length).toEqual(2);
137 expect(result.element().firstChild.children.length).toEqual(0);
138 });
139
140 it('should open KQAction', function () {
141 var show = {};
142 var result = resultClass.create(show);
143
144 result.addKqAction();
145
146 expect(result.element().lastChild.firstChild.textContent).toEqual("show KoralQuery");
147 expect(show["kq"]).toBeFalsy();
148
149 // Open KQ view
150 result.element().lastChild.firstChild.click();
151
152 expect(result.element().querySelector('#koralquery').textContent).toEqual("{}");
153 expect(show["kq"]).toBeTruthy();
154
155 var close = result.element().firstChild.firstChild.lastChild.firstChild;
156 expect(close.textContent).toEqual("Close");
157
158 // Close view
159 close.click();
160
161 expect(result.element().querySelector('#koralquery')).toBeFalsy();
162 expect(show["kq"]).toBeFalsy();
163 });
164 });
Akron56d42072018-07-24 11:17:24 +0200165});