Akron | 362c11a | 2018-08-29 20:01:30 +0200 | [diff] [blame] | 1 | define(['panel','view','panel/result','util'], function (panelClass,viewClass, resultClass) { |
Akron | 56d4207 | 2018-07-24 11:17:24 +0200 | [diff] [blame] | 2 | |
| 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 | }; |
hebasta | d025eb9 | 2019-12-07 21:04:42 +0100 | [diff] [blame] | 21 | |
| 22 | var secViewClass = { |
| 23 | create : function () { |
| 24 | return Object.create(viewClass)._init(['secview']).upgradeTo(this); |
| 25 | }, |
| 26 | }; |
Akron | 56d4207 | 2018-07-24 11:17:24 +0200 | [diff] [blame] | 27 | |
hebasta | d025eb9 | 2019-12-07 21:04:42 +0100 | [diff] [blame] | 28 | |
Akron | 56d4207 | 2018-07-24 11:17:24 +0200 | [diff] [blame] | 29 | 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 | }); |
Akron | 3d9ce5e | 2020-10-01 15:18:36 +0200 | [diff] [blame] | 67 | |
| 68 | it('should be minimizable', function () { |
| 69 | var view = viewClass.create(['versuch']); |
| 70 | var e = view.element(); |
| 71 | expect(e.classList.contains('show')).toBeTruthy(); |
| 72 | view.minimize(); |
| 73 | expect(e.classList.contains('show')).toBeFalsy(); |
| 74 | }); |
Akron | 56d4207 | 2018-07-24 11:17:24 +0200 | [diff] [blame] | 75 | }); |
| 76 | |
| 77 | describe('KorAP.Panel', function () { |
| 78 | |
| 79 | it('should be initializable', function () { |
| 80 | var panel = panelClass.create(); |
| 81 | var e = panel.element(); |
| 82 | expect(e.tagName).toEqual("DIV"); |
| 83 | expect(e.classList.contains("panel")).toBeTruthy(); |
| 84 | expect(e.firstChild.tagName).toEqual("DIV"); |
| 85 | |
| 86 | // No children in the empty view element |
| 87 | expect(e.firstChild.firstChild).toBeFalsy(); |
| 88 | expect(e.lastChild.tagName).toEqual("DIV"); |
| 89 | expect(e.lastChild.classList.contains("button-panel")).toBeTruthy(); |
| 90 | expect(e.lastChild.classList.contains("button-group")).toBeTruthy(); |
| 91 | expect(e.lastChild.firstChild).toBeFalsy(); |
| 92 | |
| 93 | expect(panel.actions).toBeTruthy(); |
| 94 | }); |
| 95 | |
| 96 | |
| 97 | it('should be extensible', function () { |
| 98 | var panel = panelClass.create(); |
| 99 | |
| 100 | controlStr = ""; |
Akron | 792b1a4 | 2020-09-14 18:56:38 +0200 | [diff] [blame] | 101 | panel.actions.add("New", {'cls':["new"]}, function () { |
Akron | 56d4207 | 2018-07-24 11:17:24 +0200 | [diff] [blame] | 102 | controlStr = 'New!!!'; |
| 103 | }); |
| 104 | |
| 105 | var e = panel.element(); |
| 106 | |
| 107 | expect(e.tagName).toEqual("DIV"); |
| 108 | expect(e.firstChild.firstChild).toBeFalsy(); |
| 109 | |
| 110 | expect(e.lastChild.firstChild.tagName).toEqual("SPAN"); |
| 111 | expect(e.lastChild.firstChild.getAttribute("title")).toEqual("New"); |
| 112 | expect(e.lastChild.firstChild.classList.contains("new")).toBeTruthy(); |
| 113 | expect(e.lastChild.firstChild.firstChild.tagName).toEqual("SPAN"); |
| 114 | expect(e.lastChild.firstChild.firstChild.firstChild.data).toEqual("New"); |
| 115 | |
| 116 | expect(controlStr).toEqual(""); |
| 117 | e.lastChild.firstChild.click(); |
| 118 | expect(controlStr).toEqual("New!!!"); |
| 119 | }); |
| 120 | |
| 121 | it('should be classable', function () { |
| 122 | var panel = panelClass.create(["versuch"]); |
| 123 | var e = panel.element(); |
| 124 | expect(e.tagName).toEqual("DIV"); |
| 125 | expect(e.classList.contains("panel")).toBeTruthy(); |
| 126 | expect(e.classList.contains("versuch")).toBeTruthy(); |
| 127 | expect(e.lastChild.classList.contains("button-panel")).toBeTruthy(); |
| 128 | expect(e.lastChild.classList.contains("versuch")).toBeTruthy(); |
| 129 | }); |
| 130 | |
| 131 | it('should be extensible by a view', function () { |
| 132 | var panel = panelClass.create(); |
| 133 | var view = helloViewClass.create(); |
| 134 | var e = panel.element(); |
| 135 | |
| 136 | panel.add(view); |
| 137 | |
| 138 | var viewE = e.firstChild.firstChild; |
| 139 | expect(viewE.classList.contains('view')).toBeTruthy(); |
| 140 | expect(viewE.classList.contains('myview')).toBeTruthy(); |
| 141 | expect(viewE.firstChild.tagName).toEqual("SPAN"); |
| 142 | expect(viewE.firstChild.firstChild.data).toEqual("Hello World!"); |
| 143 | }); |
hebasta | d025eb9 | 2019-12-07 21:04:42 +0100 | [diff] [blame] | 144 | |
| 145 | it('views should be appended or prepended', function () { |
| 146 | let panel = panelClass.create(); |
| 147 | let view = helloViewClass.create(); |
| 148 | let e = panel.element(); |
| 149 | panel.add(view); |
| 150 | let secview = secViewClass.create(); |
| 151 | panel.add(secview); |
| 152 | let viewFirst = e.firstChild.firstChild; |
| 153 | expect(viewFirst.classList.contains('myview')).toBeTruthy(); |
| 154 | |
| 155 | let prependPanel = panelClass.create(); |
| 156 | prependPanel.prepend = true; |
| 157 | prependPanel.add(view); |
| 158 | prependPanel.add(secview); |
| 159 | viewFirst = prependPanel.element().firstChild.firstChild; |
| 160 | expect(viewFirst.classList.contains('secview')).toBeTruthy(); |
| 161 | }); |
| 162 | |
Akron | 56d4207 | 2018-07-24 11:17:24 +0200 | [diff] [blame] | 163 | }); |
Akron | 362c11a | 2018-08-29 20:01:30 +0200 | [diff] [blame] | 164 | |
| 165 | describe('KorAP.Panel.Result', function () { |
| 166 | |
| 167 | it('should be initializable', function () { |
| 168 | var show = {}; |
| 169 | var result = resultClass.create(show); |
| 170 | expect(result.element().children.length).toEqual(2); |
| 171 | expect(result.element().firstChild.children.length).toEqual(0); |
| 172 | }); |
| 173 | |
| 174 | it('should open KQAction', function () { |
| 175 | var show = {}; |
| 176 | var result = resultClass.create(show); |
| 177 | |
| 178 | result.addKqAction(); |
| 179 | |
| 180 | expect(result.element().lastChild.firstChild.textContent).toEqual("show KoralQuery"); |
| 181 | expect(show["kq"]).toBeFalsy(); |
| 182 | |
| 183 | // Open KQ view |
| 184 | result.element().lastChild.firstChild.click(); |
| 185 | |
| 186 | expect(result.element().querySelector('#koralquery').textContent).toEqual("{}"); |
| 187 | expect(show["kq"]).toBeTruthy(); |
| 188 | |
| 189 | var close = result.element().firstChild.firstChild.lastChild.firstChild; |
| 190 | expect(close.textContent).toEqual("Close"); |
| 191 | |
| 192 | // Close view |
| 193 | close.click(); |
| 194 | |
| 195 | expect(result.element().querySelector('#koralquery')).toBeFalsy(); |
| 196 | expect(show["kq"]).toBeFalsy(); |
| 197 | }); |
Akron | ece4bb7 | 2020-10-19 12:24:20 +0200 | [diff] [blame] | 198 | |
| 199 | it('should open toggler', function () { |
| 200 | const show = {}; |
| 201 | |
| 202 | const div = document.body.addE("div"); |
| 203 | div.setAttribute("id","search"); |
| 204 | const ol = div.addE("ol"); |
| 205 | ol.classList.add("align-left"); |
| 206 | |
| 207 | const result = resultClass.create(show); |
| 208 | |
| 209 | result.addAlignAction(); |
| 210 | |
| 211 | const b = result.element().lastChild.firstChild; |
| 212 | |
| 213 | expect(b.textContent).toEqual("toggle alignment"); |
| 214 | expect(b.classList.contains('right')).toBeTruthy(); |
| 215 | expect(ol.classList.contains('align-left')).toBeTruthy(); |
| 216 | |
| 217 | b.click(); |
| 218 | |
| 219 | expect(b.textContent).toEqual("toggle alignment"); |
| 220 | expect(b.classList.contains('center')).toBeTruthy(); |
| 221 | expect(ol.classList.contains('align-right')).toBeTruthy(); |
| 222 | |
| 223 | b.click(); |
| 224 | |
| 225 | expect(b.textContent).toEqual("toggle alignment"); |
| 226 | expect(b.classList.contains('left')).toBeTruthy(); |
| 227 | expect(ol.classList.contains('align-center')).toBeTruthy(); |
| 228 | |
| 229 | b.click(); |
| 230 | |
| 231 | expect(b.textContent).toEqual("toggle alignment"); |
| 232 | expect(b.classList.contains('right')).toBeTruthy(); |
| 233 | expect(ol.classList.contains('align-left')).toBeTruthy(); |
| 234 | |
| 235 | document.body.removeChild(div); |
| 236 | }); |
Akron | 362c11a | 2018-08-29 20:01:30 +0200 | [diff] [blame] | 237 | }); |
Akron | 56d4207 | 2018-07-24 11:17:24 +0200 | [diff] [blame] | 238 | }); |