Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame^] | 1 | KorAP.OwnMenuItem = { |
| 2 | create : function (params) { |
| 3 | return Object.create(KorAP.MenuItem).upgradeTo(KorAP.OwnMenuItem)._init(params); |
| 4 | }, |
| 5 | content : function (content) { |
| 6 | if (arguments.length === 1) { |
| 7 | this._content = content; |
| 8 | }; |
| 9 | return this._content; |
| 10 | }, |
| 11 | _init : function (params) { |
| 12 | if (params[0] === undefined) |
| 13 | throw new Error("Missing parameters"); |
| 14 | |
| 15 | this._content = document.createTextNode(params[0]); |
| 16 | this._lcField = ' ' + this.content().textContent.toLowerCase(); |
| 17 | |
| 18 | return this; |
| 19 | } |
| 20 | }; |
| 21 | |
| 22 | KorAP.ComplexMenuItem = { |
| 23 | create : function (params) { |
| 24 | return Object.create(KorAP.MenuItem) |
| 25 | .upgradeTo(KorAP.ComplexMenuItem) |
| 26 | ._init(params); |
| 27 | }, |
| 28 | content : function (content) { |
| 29 | if (arguments.length === 1) { |
| 30 | this._content = content; |
| 31 | }; |
| 32 | return this._content; |
| 33 | }, |
| 34 | _init : function (params) { |
| 35 | if (params[0] === undefined) |
| 36 | throw new Error("Missing parameters"); |
| 37 | |
| 38 | var r = document.createElement('div'); |
| 39 | for (var i = 1; i <= params.length; i++) { |
| 40 | var h = document.createElement('h' + i); |
| 41 | h.appendChild(document.createTextNode(params[i-1])); |
| 42 | r.appendChild(h); |
| 43 | }; |
| 44 | |
| 45 | this._content = r; |
| 46 | this._lcField = ' ' + this.content().textContent.toLowerCase(); |
| 47 | |
| 48 | return this; |
| 49 | } |
| 50 | }; |
| 51 | |
| 52 | |
| 53 | describe('KorAP.MenuItem', function () { |
| 54 | it('should be initializable', function () { |
| 55 | expect( |
| 56 | function() { KorAP.MenuItem.create([]) } |
| 57 | ).toThrow(new Error("Missing parameters")); |
| 58 | |
| 59 | expect( |
| 60 | function() { KorAP.OwnMenuItem.create([]) } |
| 61 | ).toThrow(new Error("Missing parameters")); |
| 62 | |
| 63 | var mi = KorAP.OwnMenuItem.create(["Baum"]); |
| 64 | expect(mi.element().firstChild.nodeValue).toEqual('Baum'); |
| 65 | expect(mi.lcField()).toEqual(' baum'); |
| 66 | }); |
| 67 | |
| 68 | it('should be activatable and deactivateable by class', function () { |
| 69 | var menuItem = KorAP.OwnMenuItem.create(['Test']); |
| 70 | |
| 71 | expect(menuItem.active()).toBe(false); |
| 72 | expect(menuItem.element().getAttribute("class")).toBe(null); |
| 73 | menuItem.active(true); |
| 74 | expect(menuItem.active()).toBe(true); |
| 75 | expect(menuItem.element().getAttribute("class")).toEqual("active"); |
| 76 | menuItem.active(false); // Is active |
| 77 | expect(menuItem.active()).toBe(false); |
| 78 | expect(menuItem.element().getAttribute("class")).toEqual(""); |
| 79 | menuItem.active(true); |
| 80 | expect(menuItem.active()).toBe(true); |
| 81 | expect(menuItem.element().getAttribute("class")).toEqual("active"); |
| 82 | |
| 83 | menuItem = KorAP.OwnMenuItem.create(['Spiegel']); |
| 84 | expect(menuItem.active()).toBe(false); |
| 85 | expect(menuItem.element().getAttribute("class")).toBe(null); |
| 86 | menuItem.active(false); // Is not active |
| 87 | expect(menuItem.active()).toBe(false); |
| 88 | expect(menuItem.element().getAttribute("class")).toBe(null); |
| 89 | }); |
| 90 | |
| 91 | it('should be set to boundary', function () { |
| 92 | var menuItem = KorAP.OwnMenuItem.create(['CoreNLP']); |
| 93 | expect(menuItem.active()).toBe(false); |
| 94 | expect(menuItem.element().getAttribute("class")).toBe(null); |
| 95 | |
| 96 | // Set active |
| 97 | menuItem.active(true); |
| 98 | expect(menuItem.active()).toBe(true); |
| 99 | expect(menuItem.noMore()).toBe(false); |
| 100 | expect(menuItem.element().getAttribute("class")).toEqual("active"); |
| 101 | |
| 102 | // Set no more |
| 103 | menuItem.noMore(true); |
| 104 | expect(menuItem.active()).toBe(true); |
| 105 | expect(menuItem.noMore()).toBe(true); |
| 106 | expect(menuItem.element().getAttribute("class")).toEqual("active no-more"); |
| 107 | |
| 108 | // No no more |
| 109 | menuItem.noMore(false); |
| 110 | expect(menuItem.active()).toBe(true); |
| 111 | expect(menuItem.noMore()).toBe(false); |
| 112 | expect(menuItem.element().getAttribute("class")).toEqual("active"); |
| 113 | |
| 114 | // Set no more, deactivate |
| 115 | menuItem.noMore(true); |
| 116 | menuItem.active(false); |
| 117 | expect(menuItem.active()).toBe(false); |
| 118 | expect(menuItem.noMore()).toBe(true); |
| 119 | expect(menuItem.element().getAttribute("class")).toEqual("no-more"); |
| 120 | |
| 121 | // Set active |
| 122 | menuItem.active(true); |
| 123 | expect(menuItem.active()).toBe(true); |
| 124 | expect(menuItem.noMore()).toBe(true); |
| 125 | expect(menuItem.element().getAttribute("class")).toEqual("no-more active"); |
| 126 | }); |
| 127 | |
| 128 | |
| 129 | it('should be highlightable', function () { |
| 130 | // Highlight in the middle |
| 131 | var menuItem = KorAP.OwnMenuItem.create(['CoreNLP']); |
| 132 | menuItem.highlight("ren"); |
| 133 | expect(menuItem.element().innerHTML).toEqual("Co<mark>reN</mark>LP"); |
| 134 | |
| 135 | menuItem.lowlight(); |
| 136 | expect(menuItem.element().innerHTML).toEqual("CoreNLP"); |
| 137 | |
| 138 | var plain = "<div><h1>CoreNLP</h1><h2>corenlp/</h2></div>"; |
| 139 | |
| 140 | // Starting highlight |
| 141 | menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']); |
| 142 | menuItem.highlight("cor"); |
| 143 | expect(menuItem.element().innerHTML).toEqual("<div><h1><mark>Cor</mark>eNLP</h1><h2><mark>cor</mark>enlp/</h2></div>"); |
| 144 | |
| 145 | menuItem.lowlight(); |
| 146 | expect(menuItem.element().innerHTML).toEqual(plain); |
| 147 | |
| 148 | // Starting highlight - short |
| 149 | menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']); |
| 150 | menuItem.highlight("c"); |
| 151 | expect(menuItem.element().innerHTML).toEqual("<div><h1><mark>C</mark>oreNLP</h1><h2><mark>c</mark>orenlp/</h2></div>"); |
| 152 | |
| 153 | menuItem.lowlight(); |
| 154 | expect(menuItem.element().innerHTML).toEqual(plain); |
| 155 | |
| 156 | // Highlight at the end |
| 157 | menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']); |
| 158 | menuItem.highlight("nlp"); |
| 159 | expect(menuItem.element().innerHTML).toEqual("<div><h1>Core<mark>NLP</mark></h1><h2>core<mark>nlp</mark>/</h2></div>"); |
| 160 | |
| 161 | menuItem.lowlight(); |
| 162 | expect(menuItem.element().innerHTML).toEqual(plain); |
| 163 | |
| 164 | // Highlight at the end - short |
| 165 | menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']); |
| 166 | menuItem.highlight("p"); |
| 167 | expect(menuItem.element().innerHTML).toEqual("<div><h1>CoreNL<mark>P</mark></h1><h2>corenl<mark>p</mark>/</h2></div>"); |
| 168 | |
| 169 | menuItem.lowlight(); |
| 170 | expect(menuItem.element().innerHTML).toEqual(plain); |
| 171 | |
| 172 | // No highlight |
| 173 | menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']); |
| 174 | menuItem.highlight("xp"); |
| 175 | expect(menuItem.element().innerHTML).toEqual(plain); |
| 176 | |
| 177 | menuItem.lowlight(); |
| 178 | expect(menuItem.element().innerHTML).toEqual(plain); |
| 179 | |
| 180 | // Highlight in the middle - first |
| 181 | menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']); |
| 182 | menuItem.highlight("ren"); |
| 183 | expect(menuItem.element().innerHTML).toEqual("<div><h1>Co<mark>reN</mark>LP</h1><h2>co<mark>ren</mark>lp/</h2><h3>This is my Example</h3></div>"); |
| 184 | |
| 185 | plain = "<div><h1>CoreNLP</h1><h2>corenlp/</h2><h3>This is my Example</h3></div>" |
| 186 | |
| 187 | menuItem.lowlight(); |
| 188 | expect(menuItem.element().innerHTML).toEqual(plain); |
| 189 | |
| 190 | // Highlight in the middle - second |
| 191 | menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']); |
| 192 | menuItem.highlight("ampl"); |
| 193 | expect(menuItem.element().innerHTML).toEqual("<div><h1>CoreNLP</h1><h2>corenlp/</h2><h3>This is my Ex<mark>ampl</mark>e</h3></div>"); |
| 194 | |
| 195 | menuItem.lowlight(); |
| 196 | expect(menuItem.element().innerHTML).toEqual(plain); |
| 197 | |
| 198 | // Highlight in the middle - both |
| 199 | menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']); |
| 200 | menuItem.highlight("e"); |
| 201 | expect(menuItem.element().innerHTML).toEqual("<div><h1>Cor<mark>e</mark>NLP</h1><h2>cor<mark>e</mark>nlp/</h2><h3>This is my <mark>E</mark>xampl<mark>e</mark></h3></div>"); |
| 202 | |
| 203 | menuItem.lowlight(); |
| 204 | expect(menuItem.element().innerHTML).toEqual(plain); |
| 205 | |
| 206 | // Highlight in the end - second |
| 207 | menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']); |
| 208 | menuItem.highlight("le"); |
| 209 | expect(menuItem.element().innerHTML).toEqual("<div><h1>CoreNLP</h1><h2>corenlp/</h2><h3>This is my Examp<mark>le</mark></h3></div>"); |
| 210 | |
| 211 | menuItem.lowlight(); |
| 212 | expect(menuItem.element().innerHTML).toEqual(plain); |
| 213 | |
| 214 | // Highlight at the beginning - second |
| 215 | menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']); |
| 216 | menuItem.highlight("this"); |
| 217 | expect(menuItem.element().innerHTML).toEqual("<div><h1>CoreNLP</h1><h2>corenlp/</h2><h3><mark>This</mark> is my Example</h3></div>"); |
| 218 | |
| 219 | menuItem.lowlight(); |
| 220 | expect(menuItem.element().innerHTML).toEqual(plain); |
| 221 | }); |
| 222 | |
| 223 | }); |
| 224 | |
| 225 | |
| 226 | /* |
| 227 | |
| 228 | describe('KorAP.MenuItem', function () { |
| 229 | |
| 230 | }); |
| 231 | |
| 232 | |
| 233 | describe('KorAP.Menu', function () { |
| 234 | |
| 235 | var list = [ |
| 236 | ["Constituency", "c=", "Example 1"], |
| 237 | ["Lemma", "l="], |
| 238 | ["Morphology", "m=", "Example 2"], |
| 239 | ["Part-of-Speech", "p="], |
| 240 | ["Syntax", "syn="] |
| 241 | ]; |
| 242 | |
| 243 | |
| 244 | it('should be initializable', function () { |
| 245 | |
| 246 | var menu = KorAP.Menu.create("cnx/", list); |
| 247 | expect(menu.context).toEqual('cnx/'); |
| 248 | expect(menu.element.nodeName).toEqual('UL'); |
| 249 | expect(menu.element.style.opacity).toEqual("0"); |
| 250 | |
| 251 | KorAP.limit = 8; |
| 252 | |
| 253 | // view |
| 254 | menu.show(); |
| 255 | |
| 256 | // First element in list |
| 257 | expect(menu.item(0).active()).toBe(true); |
| 258 | expect(menu.item(0).noMore()).toBe(true); |
| 259 | |
| 260 | // Middle element in list |
| 261 | expect(menu.item(2).active()).toBe(false); |
| 262 | expect(menu.item(2).noMore()).toBe(false); |
| 263 | |
| 264 | // Last element in list |
| 265 | expect(menu.item(menu.length - 1).active()).toBe(false); |
| 266 | expect(menu.item(menu.length - 1).noMore()).toBe(true); |
| 267 | }); |
| 268 | |
| 269 | it('should be visible', function () { |
| 270 | var menu = KorAP.Menu.create("cnx/", list); |
| 271 | expect(menu.delete()).toBe(undefined); |
| 272 | |
| 273 | KorAP.limit = 3; |
| 274 | |
| 275 | expect(menu.show()).toBe(undefined); |
| 276 | expect(menu.element.firstChild.innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>"); |
| 277 | expect(menu.element.childNodes[1].innerHTML).toEqual("<strong>Lemma</strong>"); |
| 278 | expect(menu.element.childNodes[1].getAttribute("data-action")).toEqual("l="); |
| 279 | expect(menu.element.childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
| 280 | expect(menu.element.childNodes[3]).toBe(undefined); |
| 281 | |
| 282 | // Check boundaries |
| 283 | expect(menu.element.childNodes[0].classList.contains("no-more")).toBe(true); |
| 284 | expect(menu.element.childNodes[1].classList.contains("no-more")).toBe(false); |
| 285 | expect(menu.element.childNodes[2].classList.contains("no-more")).toBe(false); |
| 286 | }); |
| 287 | |
| 288 | |
| 289 | it('should be filterable', function () { |
| 290 | var menu = KorAP.Menu.create("cnx/", list); |
| 291 | |
| 292 | KorAP.limit = 3; |
| 293 | |
| 294 | expect(menu.show("o")).toBe(undefined); |
| 295 | expect(menu.element.childNodes[0].innerHTML).toEqual("<strong>C<em>o</em>nstituency</strong><span>Example 1</span>"); |
| 296 | expect(menu.element.childNodes[1].innerHTML).toEqual("<strong>M<em>o</em>rphology</strong><span>Example 2</span>"); |
| 297 | expect(menu.element.childNodes[2].innerHTML).toEqual("<strong>Part-<em>o</em>f-Speech</strong>"); |
| 298 | expect(menu.element.childNodes[3]).toBe(undefined); |
| 299 | |
| 300 | // Check boundaries |
| 301 | expect(menu.element.childNodes[0].classList.contains("no-more")).toBe(true); |
| 302 | expect(menu.element.childNodes[1].classList.contains("no-more")).toBe(false); |
| 303 | expect(menu.element.childNodes[2].classList.contains("no-more")).toBe(true); |
| 304 | |
| 305 | |
| 306 | KorAP.limit = 2; |
| 307 | |
| 308 | expect(menu.show("o")).toBe(undefined); |
| 309 | expect(menu.element.childNodes[0].innerHTML).toEqual("<strong>C<em>o</em>nstituency</strong><span>Example 1</span>"); |
| 310 | expect(menu.element.childNodes[1].innerHTML).toEqual("<strong>M<em>o</em>rphology</strong><span>Example 2</span>"); |
| 311 | expect(menu.element.childNodes[2]).toBe(undefined); |
| 312 | |
| 313 | // Check boundaries |
| 314 | expect(menu.element.childNodes[0].classList.contains("no-more")).toBe(true); |
| 315 | expect(menu.element.childNodes[1].classList.contains("no-more")).toBe(false); |
| 316 | expect(menu.element.childNodes[2]).toBe(undefined); |
| 317 | }); |
| 318 | |
| 319 | it('should be nextable', function () { |
| 320 | var menu = KorAP.Menu.create("cnx/", list); |
| 321 | |
| 322 | KorAP.limit = 3; |
| 323 | expect(menu.show()).toBe(undefined); |
| 324 | |
| 325 | expect(menu.element.childNodes[0].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>"); |
| 326 | expect(menu.shownItem(0).active()).toBe(true); |
| 327 | expect(menu.element.childNodes[1].innerHTML).toEqual("<strong>Lemma</strong>"); |
| 328 | expect(menu.shownItem(1).active()).toBe(false); |
| 329 | expect(menu.element.childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
| 330 | expect(menu.shownItem(2).active()).toBe(false); |
| 331 | expect(menu.element.childNodes[3]).toBe(undefined); |
| 332 | |
| 333 | // Activate next (1) |
| 334 | menu.next(); |
| 335 | expect(menu.element.childNodes[0].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>"); |
| 336 | expect(menu.shownItem(0).active()).toBe(false); |
| 337 | expect(menu.element.childNodes[1].innerHTML).toEqual("<strong>Lemma</strong>"); |
| 338 | expect(menu.shownItem(1).active()).toBe(true); |
| 339 | expect(menu.element.childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
| 340 | expect(menu.shownItem(2).active()).toBe(false); |
| 341 | expect(menu.element.childNodes[3]).toBe(undefined); |
| 342 | |
| 343 | // Activate next (2) |
| 344 | menu.next(); |
| 345 | expect(menu.element.childNodes[0].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>"); |
| 346 | expect(menu.shownItem(0).active()).toBe(false); |
| 347 | expect(menu.element.childNodes[1].innerHTML).toEqual("<strong>Lemma</strong>"); |
| 348 | expect(menu.shownItem(1).active()).toBe(false); |
| 349 | expect(menu.element.childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
| 350 | expect(menu.shownItem(2).active()).toBe(true); |
| 351 | expect(menu.element.childNodes[3]).toBe(undefined); |
| 352 | |
| 353 | // Activate next (3) |
| 354 | menu.next(); |
| 355 | expect(menu.element.childNodes[0].innerHTML).toEqual("<strong>Lemma</strong>"); |
| 356 | expect(menu.shownItem(0).active()).toBe(false); |
| 357 | expect(menu.element.childNodes[1].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
| 358 | expect(menu.shownItem(1).active()).toBe(false); |
| 359 | expect(menu.element.childNodes[2].innerHTML).toEqual("<strong>Part-of-Speech</strong>"); |
| 360 | expect(menu.shownItem(2).active()).toBe(true); |
| 361 | expect(menu.element.childNodes[3]).toBe(undefined); |
| 362 | |
| 363 | // Activate next (4) |
| 364 | menu.next(); |
| 365 | expect(menu.element.childNodes[0].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
| 366 | expect(menu.shownItem(0).active()).toBe(false); |
| 367 | expect(menu.element.childNodes[1].innerHTML).toEqual("<strong>Part-of-Speech</strong>"); |
| 368 | expect(menu.shownItem(1).active()).toBe(false); |
| 369 | expect(menu.element.childNodes[2].innerHTML).toEqual("<strong>Syntax</strong>"); |
| 370 | expect(menu.shownItem(2).active()).toBe(true); |
| 371 | expect(menu.element.childNodes[3]).toBe(undefined); |
| 372 | |
| 373 | // Activate next (5) - ROLL |
| 374 | menu.next(); |
| 375 | expect(menu.element.childNodes[0].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>"); |
| 376 | expect(menu.shownItem(0).active()).toBe(true); |
| 377 | expect(menu.element.childNodes[1].innerHTML).toEqual("<strong>Lemma</strong>"); |
| 378 | expect(menu.shownItem(1).active()).toBe(false); |
| 379 | expect(menu.element.childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
| 380 | expect(menu.shownItem(2).active()).toBe(false); |
| 381 | expect(menu.element.childNodes[3]).toBe(undefined); |
| 382 | |
| 383 | // Active next (6) |
| 384 | menu.next(); |
| 385 | expect(menu.element.childNodes[0].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>"); |
| 386 | expect(menu.shownItem(0).active()).toBe(false); |
| 387 | expect(menu.element.childNodes[1].innerHTML).toEqual("<strong>Lemma</strong>"); |
| 388 | expect(menu.shownItem(1).active()).toBe(true); |
| 389 | expect(menu.element.childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
| 390 | expect(menu.shownItem(2).active()).toBe(false); |
| 391 | expect(menu.element.childNodes[3]).toBe(undefined); |
| 392 | |
| 393 | }); |
| 394 | |
| 395 | |
| 396 | it('should be prevable', function () { |
| 397 | var menu = KorAP.Menu.create("cnx/", list); |
| 398 | |
| 399 | KorAP.limit = 3; |
| 400 | expect(menu.show()).toBe(undefined); |
| 401 | |
| 402 | expect(menu.element.childNodes[0].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>"); |
| 403 | expect(menu.shownItem(0).active()).toBe(true); |
| 404 | expect(menu.element.childNodes[1].innerHTML).toEqual("<strong>Lemma</strong>"); |
| 405 | expect(menu.shownItem(1).active()).toBe(false); |
| 406 | expect(menu.element.childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
| 407 | expect(menu.shownItem(2).active()).toBe(false); |
| 408 | expect(menu.element.childNodes[3]).toBe(undefined); |
| 409 | |
| 410 | // Activate prev (1) - roll to bottom |
| 411 | menu.prev(); |
| 412 | expect(menu.element.childNodes[0].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
| 413 | expect(menu.shownItem(0).active()).toBe(false); |
| 414 | expect(menu.element.childNodes[1].innerHTML).toEqual("<strong>Part-of-Speech</strong>"); |
| 415 | expect(menu.shownItem(1).active()).toBe(false); |
| 416 | expect(menu.element.childNodes[2].innerHTML).toEqual("<strong>Syntax</strong>"); |
| 417 | expect(menu.shownItem(2).active()).toBe(true); |
| 418 | expect(menu.element.childNodes[3]).toBe(undefined); |
| 419 | |
| 420 | // Activate prev (2) |
| 421 | menu.prev(); |
| 422 | expect(menu.element.childNodes[0].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
| 423 | expect(menu.shownItem(0).active()).toBe(false); |
| 424 | expect(menu.element.childNodes[1].innerHTML).toEqual("<strong>Part-of-Speech</strong>"); |
| 425 | expect(menu.shownItem(1).active()).toBe(true); |
| 426 | expect(menu.element.childNodes[2].innerHTML).toEqual("<strong>Syntax</strong>"); |
| 427 | expect(menu.shownItem(2).active()).toBe(false); |
| 428 | expect(menu.element.childNodes[3]).toBe(undefined); |
| 429 | |
| 430 | // Activate prev (3) |
| 431 | menu.prev(); |
| 432 | expect(menu.shownItem(0).name).toEqual("Morphology"); |
| 433 | expect(menu.shownItem(0).active()).toBe(true); |
| 434 | expect(menu.shownItem(1).name).toEqual("Part-of-Speech"); |
| 435 | expect(menu.shownItem(1).active()).toBe(false); |
| 436 | expect(menu.shownItem(2).name).toEqual("Syntax"); |
| 437 | expect(menu.shownItem(2).active()).toBe(false); |
| 438 | expect(menu.element.childNodes[3]).toBe(undefined); |
| 439 | |
| 440 | // Activate prev (4) |
| 441 | menu.prev(); |
| 442 | expect(menu.shownItem(0).name).toEqual("Lemma"); |
| 443 | expect(menu.shownItem(0).active()).toBe(true); |
| 444 | expect(menu.shownItem(1).name).toEqual("Morphology"); |
| 445 | expect(menu.shownItem(1).active()).toBe(false); |
| 446 | expect(menu.shownItem(2).name).toEqual("Part-of-Speech"); |
| 447 | expect(menu.shownItem(2).active()).toBe(false); |
| 448 | expect(menu.element.childNodes[3]).toBe(undefined); |
| 449 | |
| 450 | // Activate prev (5) |
| 451 | menu.prev(); |
| 452 | expect(menu.shownItem(0).name).toEqual("Constituency"); |
| 453 | expect(menu.shownItem(0).active()).toBe(true); |
| 454 | expect(menu.shownItem(1).name).toEqual("Lemma"); |
| 455 | expect(menu.shownItem(1).active()).toBe(false); |
| 456 | expect(menu.shownItem(2).name).toEqual("Morphology"); |
| 457 | expect(menu.shownItem(2).active()).toBe(false); |
| 458 | expect(menu.element.childNodes[3]).toBe(undefined); |
| 459 | |
| 460 | // Activate next (1) |
| 461 | menu.next(); |
| 462 | expect(menu.shownItem(0).name).toEqual("Constituency"); |
| 463 | expect(menu.shownItem(0).active()).toBe(false); |
| 464 | expect(menu.shownItem(1).name).toEqual("Lemma"); |
| 465 | expect(menu.shownItem(1).active()).toBe(true); |
| 466 | expect(menu.shownItem(2).name).toEqual("Morphology"); |
| 467 | expect(menu.shownItem(2).active()).toBe(false); |
| 468 | expect(menu.element.childNodes[3]).toBe(undefined); |
| 469 | |
| 470 | // Activate prev (6) |
| 471 | menu.prev(); |
| 472 | |
| 473 | // Activate prev (7) |
| 474 | menu.prev(); |
| 475 | expect(menu.shownItem(0).name).toEqual("Morphology"); |
| 476 | expect(menu.shownItem(0).active()).toBe(false); |
| 477 | expect(menu.shownItem(1).name).toEqual("Part-of-Speech"); |
| 478 | expect(menu.shownItem(1).active()).toBe(false); |
| 479 | expect(menu.shownItem(2).name).toEqual("Syntax"); |
| 480 | expect(menu.shownItem(2).active()).toBe(true); |
| 481 | expect(menu.element.childNodes[3]).toBe(undefined); |
| 482 | }); |
| 483 | |
| 484 | it('should be navigatable and filterable (prefix = "o")', function () { |
| 485 | var menu = KorAP.Menu.create("cnx/", list); |
| 486 | |
| 487 | KorAP.limit = 2; |
| 488 | |
| 489 | expect(menu.show("o")).toBe(undefined); |
| 490 | |
| 491 | expect(menu.shownItem(0).name).toEqual("Constituency"); |
| 492 | expect(menu.element.childNodes[0].innerHTML).toEqual("<strong>C<em>o</em>nstituency</strong><span>Example 1</span>"); |
| 493 | expect(menu.shownItem(0).active()).toBe(true); |
| 494 | expect(menu.shownItem(1).name).toEqual("Morphology"); |
| 495 | expect(menu.element.childNodes[1].innerHTML).toEqual("<strong>M<em>o</em>rphology</strong><span>Example 2</span>"); |
| 496 | expect(menu.shownItem(1).active()).toBe(false); |
| 497 | expect(menu.shownItem(2)).toBe(undefined); |
| 498 | |
| 499 | // Next (1) |
| 500 | menu.next(); |
| 501 | expect(menu.shownItem(0).name).toEqual("Constituency"); |
| 502 | expect(menu.element.childNodes[0].innerHTML).toEqual("<strong>C<em>o</em>nstituency</strong><span>Example 1</span>"); |
| 503 | expect(menu.shownItem(0).active()).toBe(false); |
| 504 | expect(menu.shownItem(1).name).toEqual("Morphology"); |
| 505 | expect(menu.element.childNodes[1].innerHTML).toEqual("<strong>M<em>o</em>rphology</strong><span>Example 2</span>"); |
| 506 | expect(menu.shownItem(1).active()).toBe(true); |
| 507 | expect(menu.shownItem(2)).toBe(undefined); |
| 508 | |
| 509 | |
| 510 | // Next (2) |
| 511 | menu.next(); |
| 512 | expect(menu.shownItem(0).name).toEqual("Morphology"); |
| 513 | expect(menu.element.childNodes[0].innerHTML).toEqual("<strong>M<em>o</em>rphology</strong><span>Example 2</span>"); |
| 514 | expect(menu.shownItem(0).active()).toBe(false); |
| 515 | expect(menu.shownItem(1).name).toEqual("Part-of-Speech"); |
| 516 | expect(menu.element.childNodes[1].innerHTML).toEqual("<strong>Part-<em>o</em>f-Speech</strong>"); |
| 517 | expect(menu.shownItem(1).active()).toBe(true); |
| 518 | expect(menu.shownItem(2)).toBe(undefined); |
| 519 | |
| 520 | // Next (3) |
| 521 | menu.next(); |
| 522 | expect(menu.shownItem(0).name).toEqual("Constituency"); |
| 523 | expect(menu.element.childNodes[0].innerHTML).toEqual("<strong>C<em>o</em>nstituency</strong><span>Example 1</span>"); |
| 524 | expect(menu.shownItem(0).active()).toBe(true); |
| 525 | expect(menu.shownItem(1).name).toEqual("Morphology"); |
| 526 | expect(menu.element.childNodes[1].innerHTML).toEqual("<strong>M<em>o</em>rphology</strong><span>Example 2</span>"); |
| 527 | expect(menu.shownItem(1).active()).toBe(false); |
| 528 | expect(menu.shownItem(2)).toBe(undefined); |
| 529 | }); |
| 530 | |
| 531 | it('should be navigatable and filterable (prefix = "ex", "e")', function () { |
| 532 | var menu = KorAP.Menu.create("cnx/", list); |
| 533 | |
| 534 | KorAP.limit = 2; |
| 535 | |
| 536 | expect(menu.show("ex")).toBe(undefined); |
| 537 | |
| 538 | expect(menu.shownItem(0).name).toEqual("Constituency"); |
| 539 | expect(menu.element.childNodes[0].innerHTML).toEqual("<strong>Constituency</strong><span><em>Ex</em>ample 1</span>"); |
| 540 | expect(menu.shownItem(0).active()).toBe(true); |
| 541 | expect(menu.shownItem(1).name).toEqual("Morphology"); |
| 542 | expect(menu.element.childNodes[1].innerHTML).toEqual("<strong>Morphology</strong><span><em>Ex</em>ample 2</span>"); |
| 543 | expect(menu.shownItem(1).active()).toBe(false); |
| 544 | expect(menu.shownItem(2)).toBe(undefined); |
| 545 | |
| 546 | // Next (1) |
| 547 | menu.next(); |
| 548 | expect(menu.shownItem(0).name).toEqual("Constituency"); |
| 549 | expect(menu.element.childNodes[0].innerHTML).toEqual("<strong>Constituency</strong><span><em>Ex</em>ample 1</span>"); |
| 550 | expect(menu.shownItem(0).active()).toBe(false); |
| 551 | expect(menu.shownItem(1).name).toEqual("Morphology"); |
| 552 | expect(menu.element.childNodes[1].innerHTML).toEqual("<strong>Morphology</strong><span><em>Ex</em>ample 2</span>"); |
| 553 | expect(menu.shownItem(1).active()).toBe(true); |
| 554 | expect(menu.shownItem(2)).toBe(undefined); |
| 555 | |
| 556 | // Next (2) |
| 557 | menu.next(); |
| 558 | expect(menu.shownItem(0).name).toEqual("Constituency"); |
| 559 | expect(menu.element.childNodes[0].innerHTML).toEqual("<strong>Constituency</strong><span><em>Ex</em>ample 1</span>"); |
| 560 | expect(menu.shownItem(0).active()).toBe(true); |
| 561 | expect(menu.shownItem(1).name).toEqual("Morphology"); |
| 562 | expect(menu.element.childNodes[1].innerHTML).toEqual("<strong>Morphology</strong><span><em>Ex</em>ample 2</span>"); |
| 563 | expect(menu.shownItem(1).active()).toBe(false); |
| 564 | expect(menu.shownItem(2)).toBe(undefined); |
| 565 | |
| 566 | // Reset limit |
| 567 | KorAP.limit = 5; |
| 568 | |
| 569 | // Change show |
| 570 | expect(menu.show("e")).toBe(undefined); |
| 571 | |
| 572 | expect(menu.shownItem(0).name).toEqual("Constituency"); |
| 573 | expect(menu.element.childNodes[0].innerHTML).toEqual("<strong>Constitu<em>e</em>ncy</strong><span><em>E</em>xample 1</span>"); |
| 574 | expect(menu.shownItem(0).active()).toBe(true); |
| 575 | expect(menu.shownItem(1).name).toEqual("Morphology"); |
| 576 | expect(menu.element.childNodes[1].innerHTML).toEqual("<strong>Morphology</strong><span><em>E</em>xample 2</span>"); |
| 577 | expect(menu.shownItem(1).active()).toBe(false); |
| 578 | expect(menu.shownItem(2)).toBe(undefined); |
| 579 | |
| 580 | // Next (1) |
| 581 | menu.next(); |
| 582 | expect(menu.shownItem(0).name).toEqual("Constituency"); |
| 583 | expect(menu.element.childNodes[0].innerHTML).toEqual("<strong>Constitu<em>e</em>ncy</strong><span><em>E</em>xample 1</span>"); |
| 584 | expect(menu.shownItem(0).active()).toBe(false); |
| 585 | expect(menu.shownItem(1).name).toEqual("Morphology"); |
| 586 | expect(menu.element.childNodes[1].innerHTML).toEqual("<strong>Morphology</strong><span><em>E</em>xample 2</span>"); |
| 587 | expect(menu.shownItem(1).active()).toBe(true); |
| 588 | expect(menu.shownItem(2)).toBe(undefined); |
| 589 | |
| 590 | // Next (2) |
| 591 | menu.next(); |
| 592 | expect(menu.shownItem(0).name).toEqual("Constituency"); |
| 593 | expect(menu.element.childNodes[0].innerHTML).toEqual("<strong>Constitu<em>e</em>ncy</strong><span><em>E</em>xample 1</span>"); |
| 594 | expect(menu.shownItem(0).active()).toBe(true); |
| 595 | expect(menu.shownItem(1).name).toEqual("Morphology"); |
| 596 | expect(menu.element.childNodes[1].innerHTML).toEqual("<strong>Morphology</strong><span><em>E</em>xample 2</span>"); |
| 597 | expect(menu.shownItem(1).active()).toBe(false); |
| 598 | expect(menu.shownItem(2)).toBe(undefined); |
| 599 | }); |
| 600 | }); |
| 601 | |
| 602 | describe('KorAP.ContextAnalyzer', function () { |
| 603 | |
| 604 | it('should be initializable', function () { |
| 605 | var analyzer = KorAP.ContextAnalyzer.create(")"); |
| 606 | expect(analyzer).toBe(undefined); |
| 607 | |
| 608 | analyzer = KorAP.ContextAnalyzer.create(".+?"); |
| 609 | expect(analyzer).not.toBe(undefined); |
| 610 | |
| 611 | }); |
| 612 | |
| 613 | it('should check correctly', function () { |
| 614 | analyzer = KorAP.ContextAnalyzer.create(KorAP.context); |
| 615 | expect(analyzer.test("cnx/]cnx/c=")).toEqual("cnx/c="); |
| 616 | expect(analyzer.test("cnx/c=")).toEqual("cnx/c="); |
| 617 | expect(analyzer.test("cnx/c=np mate/m=mood:")).toEqual("mate/m=mood:"); |
| 618 | expect(analyzer.test("impcnx/")).toEqual("impcnx/"); |
| 619 | expect(analyzer.test("cnx/c=npcnx/")).toEqual("npcnx/"); |
| 620 | expect(analyzer.test("mate/m=degree:pos corenlp/ne_dewac_175m_600=")) |
| 621 | .toEqual("corenlp/ne_dewac_175m_600="); |
| 622 | }); |
| 623 | }); |
| 624 | |
| 625 | describe('KorAP.InputField', function () { |
| 626 | var input; |
| 627 | |
| 628 | beforeAll(function () { |
| 629 | input = document.createElement("input"); |
| 630 | input.setAttribute("type", "text"); |
| 631 | input.setAttribute("value", "abcdefghijklmno"); |
| 632 | input.style.position = 'absolute'; |
| 633 | input.style.top = "20px"; |
| 634 | input.style.left = "30px"; |
| 635 | input.focus(); |
| 636 | input.selectionStart = 5; |
| 637 | }); |
| 638 | |
| 639 | afterAll(function () { |
| 640 | document.getElementsByTagName("body")[0].removeChild(input); |
| 641 | document.getElementsByTagName("body")[0].removeChild( |
| 642 | document.getElementById("searchMirror") |
| 643 | ); |
| 644 | }); |
| 645 | |
| 646 | it('should be initializable', function () { |
| 647 | // Supports: context, searchField |
| 648 | var inputField = KorAP.InputField.create(input); |
| 649 | expect(inputField._element).not.toBe(undefined); |
| 650 | }); |
| 651 | |
| 652 | it('should have text', function () { |
| 653 | var inputField = KorAP.InputField.create(input); |
| 654 | |
| 655 | expect(inputField.value).toEqual("abcdefghijklmno"); |
| 656 | expect(inputField.element.selectionStart).toEqual(5); |
| 657 | expect(inputField.split()[0]).toEqual("abcde"); |
| 658 | expect(inputField.split()[1]).toEqual("fghijklmno"); |
| 659 | |
| 660 | inputField.insert("xyz"); |
| 661 | expect(inputField.split()[0]).toEqual("abcdexyz"); |
| 662 | expect(inputField.split()[1]).toEqual("fghijklmno"); |
| 663 | |
| 664 | }); |
| 665 | |
| 666 | it('should be correctly positioned', function () { |
| 667 | var inputField = KorAP.InputField.create(input); |
| 668 | document.getElementsByTagName("body")[0].appendChild(input); |
| 669 | inputField.reposition(); |
| 670 | expect(inputField.mirror.style.left).toEqual("30px"); |
| 671 | expect(inputField.mirror.style.top.match(/^(\d+)px$/)[1]).toBeGreaterThan(20); |
| 672 | }); |
| 673 | }); |
| 674 | */ |