Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 1 | function emitKeyboardEvent (element, type, keyCode) { |
| 2 | // event type : keydown, keyup, keypress |
| 3 | // http://stackoverflow.com/questions/596481/simulate-javascript-key-events |
| 4 | // http://stackoverflow.com/questions/961532/firing-a-keyboard-event-in-javascript |
| 5 | var keyboardEvent = document.createEvent("KeyboardEvent"); |
| 6 | var initMethod = typeof keyboardEvent.initKeyboardEvent !== 'undefined' ? |
| 7 | "initKeyboardEvent" : "initKeyEvent"; |
| 8 | |
| 9 | keyboardEvent[initMethod]( |
| 10 | type, |
| 11 | true, // bubbles |
| 12 | true, // cancelable |
| 13 | window, // viewArg: should be window |
| 14 | false, // ctrlKeyArg |
| 15 | false, // altKeyArg |
| 16 | false, // shiftKeyArg |
| 17 | false, // metaKeyArg |
| 18 | keyCode, // keyCodeArg : unsigned long the virtual key code, else 0 |
| 19 | 0 // charCodeArgs : unsigned long the Unicode character |
| 20 | // associated with the depressed key, else 0 |
| 21 | ); |
| 22 | |
| 23 | element.dispatchEvent(keyboardEvent); |
| 24 | }; |
| 25 | |
| 26 | |
| 27 | describe('KorAP.MenuItem', function () { |
| 28 | it('should be initializable', function () { |
| 29 | |
| 30 | expect( |
| 31 | function() { KorAP.MenuItem.create([]) } |
| 32 | ).toThrow(new Error("Missing parameters")); |
| 33 | |
| 34 | expect( |
| 35 | function() { KorAP.MenuItem.create(['CoreNLP']) } |
| 36 | ).toThrow(new Error("Missing parameters")); |
| 37 | |
| 38 | var menuItem = KorAP.MenuItem.create(['CoreNLP', 'corenlp/']); |
| 39 | expect(menuItem.name).toEqual('CoreNLP'); |
| 40 | expect(menuItem.action).toEqual('corenlp/'); |
| 41 | expect(menuItem.desc).toBeUndefined(); |
| 42 | expect(menuItem.lcfield).toEqual(' corenlp'); |
| 43 | |
| 44 | menuItem = KorAP.MenuItem.create(['CoreNLP', 'corenlp/', 'It\'s funny']); |
| 45 | expect(menuItem.name).toEqual('CoreNLP'); |
| 46 | expect(menuItem.action).toEqual('corenlp/'); |
| 47 | expect(menuItem.desc).not.toBeUndefined(); |
| 48 | expect(menuItem.desc).toEqual('It\'s funny'); |
| 49 | expect(menuItem.lcfield).toEqual(' corenlp it\'s funny'); |
| 50 | }); |
| 51 | |
| 52 | it('should have an element', function () { |
| 53 | var menuItem = KorAP.MenuItem.create(['CoreNLP', 'corenlp/']); |
| 54 | expect(menuItem.element).not.toBe(undefined); |
| 55 | expect(menuItem.element.nodeName).toEqual("LI"); |
| 56 | expect(menuItem.element.getAttribute("data-action")).toEqual("corenlp/"); |
| 57 | |
| 58 | var title = menuItem.element.firstChild; |
| 59 | expect(title.nodeName).toEqual("STRONG"); |
| 60 | expect(title.firstChild.nodeType).toEqual(3); |
| 61 | expect(title.firstChild.nodeValue).toEqual("CoreNLP"); |
| 62 | |
| 63 | expect(menuItem.element.childNodes[0]).not.toBe(undefined); |
| 64 | expect(menuItem.element.childNodes[1]).toBe(undefined); |
| 65 | |
| 66 | menuItem = KorAP.MenuItem.create(['CoreNLP', 'corenlp/', 'my DescRiption']); |
| 67 | expect(menuItem.element).not.toBe(undefined); |
| 68 | expect(menuItem.element.nodeName).toEqual("LI"); |
| 69 | expect(menuItem.element.getAttribute("data-action")).toEqual("corenlp/"); |
| 70 | |
| 71 | title = menuItem.element.firstChild; |
| 72 | expect(title.nodeName).toEqual("STRONG"); |
| 73 | expect(title.firstChild.nodeType).toEqual(3); // TextNode |
| 74 | expect(title.firstChild.nodeValue).toEqual("CoreNLP"); |
| 75 | |
| 76 | expect(menuItem.element.childNodes[0]).not.toBe(undefined); |
| 77 | expect(menuItem.element.childNodes[1]).not.toBe(undefined); |
| 78 | |
| 79 | var desc = menuItem.element.lastChild; |
| 80 | expect(desc.nodeName).toEqual("SPAN"); |
| 81 | expect(desc.firstChild.nodeType).toEqual(3); // TextNode |
| 82 | expect(desc.firstChild.nodeValue).toEqual("my DescRiption"); |
| 83 | |
| 84 | expect(menuItem.lcfield).toEqual(' corenlp my description'); |
| 85 | }); |
| 86 | |
| 87 | it('should be activatable and deactivateable by class', function () { |
| 88 | var menuItem = KorAP.MenuItem.create(['CoreNLP', 'corenlp/']); |
| 89 | expect(menuItem.active()).toBe(false); |
| 90 | expect(menuItem.element.getAttribute("class")).toBe(null); |
| 91 | menuItem.active(true); |
| 92 | expect(menuItem.active()).toBe(true); |
| 93 | expect(menuItem.element.getAttribute("class")).toEqual("active"); |
| 94 | menuItem.active(false); // Is active |
| 95 | expect(menuItem.active()).toBe(false); |
| 96 | expect(menuItem.element.getAttribute("class")).toEqual(""); |
| 97 | menuItem.active(true); |
| 98 | expect(menuItem.active()).toBe(true); |
| 99 | expect(menuItem.element.getAttribute("class")).toEqual("active"); |
| 100 | |
| 101 | menuItem = KorAP.MenuItem.create(['CoreNLP', 'corenlp/']); |
| 102 | expect(menuItem.active()).toBe(false); |
| 103 | expect(menuItem.element.getAttribute("class")).toBe(null); |
| 104 | menuItem.active(false); // Is not active |
| 105 | expect(menuItem.active()).toBe(false); |
| 106 | expect(menuItem.element.getAttribute("class")).toBe(null); |
| 107 | }); |
| 108 | |
| 109 | it('should be set to boundary', function () { |
| 110 | var menuItem = KorAP.MenuItem.create(['CoreNLP', 'corenlp/']); |
| 111 | expect(menuItem.active()).toBe(false); |
| 112 | expect(menuItem.element.getAttribute("class")).toBe(null); |
| 113 | |
| 114 | // Set active |
| 115 | menuItem.active(true); |
| 116 | expect(menuItem.active()).toBe(true); |
| 117 | expect(menuItem.noMore()).toBe(false); |
| 118 | expect(menuItem.element.getAttribute("class")).toEqual("active"); |
| 119 | |
| 120 | // Set no more |
| 121 | menuItem.noMore(true); |
| 122 | expect(menuItem.active()).toBe(true); |
| 123 | expect(menuItem.noMore()).toBe(true); |
| 124 | expect(menuItem.element.getAttribute("class")).toEqual("active no-more"); |
| 125 | |
| 126 | // No no more |
| 127 | menuItem.noMore(false); |
| 128 | expect(menuItem.active()).toBe(true); |
| 129 | expect(menuItem.noMore()).toBe(false); |
| 130 | expect(menuItem.element.getAttribute("class")).toEqual("active"); |
| 131 | |
| 132 | |
| 133 | // Set no more, deactivate |
| 134 | menuItem.noMore(true); |
| 135 | menuItem.active(false); |
| 136 | expect(menuItem.active()).toBe(false); |
| 137 | expect(menuItem.noMore()).toBe(true); |
| 138 | expect(menuItem.element.getAttribute("class")).toEqual("no-more"); |
| 139 | |
| 140 | // Set active |
| 141 | menuItem.active(true); |
| 142 | expect(menuItem.active()).toBe(true); |
| 143 | expect(menuItem.noMore()).toBe(true); |
| 144 | expect(menuItem.element.getAttribute("class")).toEqual("no-more active"); |
| 145 | }); |
| 146 | |
| 147 | |
| 148 | it('should be highlightable', function () { |
| 149 | // Highlight in the middle |
| 150 | var menuItem = KorAP.MenuItem.create(['CoreNLP', 'corenlp/']); |
| 151 | menuItem.highlight("ren"); |
| 152 | expect(menuItem.element.innerHTML).toEqual("<strong>Co<em>reN</em>LP</strong>"); |
| 153 | |
| 154 | menuItem.lowlight(); |
| 155 | expect(menuItem.element.innerHTML).toEqual("<strong>CoreNLP</strong>"); |
| 156 | |
| 157 | // Starting highlight |
| 158 | menuItem = KorAP.MenuItem.create(['CoreNLP', 'corenlp/']); |
| 159 | menuItem.highlight("cor"); |
| 160 | expect(menuItem.element.innerHTML).toEqual("<strong><em>Cor</em>eNLP</strong>"); |
| 161 | |
| 162 | menuItem.lowlight(); |
| 163 | expect(menuItem.element.innerHTML).toEqual("<strong>CoreNLP</strong>"); |
| 164 | |
| 165 | // Starting highlight - short |
| 166 | menuItem = KorAP.MenuItem.create(['CoreNLP', 'corenlp/']); |
| 167 | menuItem.highlight("c"); |
| 168 | expect(menuItem.element.innerHTML).toEqual("<strong><em>C</em>oreNLP</strong>"); |
| 169 | |
| 170 | menuItem.lowlight(); |
| 171 | expect(menuItem.element.innerHTML).toEqual("<strong>CoreNLP</strong>"); |
| 172 | |
| 173 | // Highlight at the end |
| 174 | menuItem = KorAP.MenuItem.create(['CoreNLP', 'corenlp/']); |
| 175 | menuItem.highlight("nlp"); |
| 176 | expect(menuItem.element.innerHTML).toEqual("<strong>Core<em>NLP</em></strong>"); |
| 177 | |
| 178 | menuItem.lowlight(); |
| 179 | expect(menuItem.element.innerHTML).toEqual("<strong>CoreNLP</strong>"); |
| 180 | |
| 181 | // Highlight at the end - short |
| 182 | menuItem = KorAP.MenuItem.create(['CoreNLP', 'corenlp/']); |
| 183 | menuItem.highlight("p"); |
| 184 | expect(menuItem.element.innerHTML).toEqual("<strong>CoreNL<em>P</em></strong>"); |
| 185 | |
| 186 | menuItem.lowlight(); |
| 187 | expect(menuItem.element.innerHTML).toEqual("<strong>CoreNLP</strong>"); |
| 188 | |
| 189 | // No highlight |
| 190 | menuItem = KorAP.MenuItem.create(['CoreNLP', 'corenlp/']); |
| 191 | menuItem.highlight("xp"); |
| 192 | expect(menuItem.element.innerHTML).toEqual("<strong>CoreNLP</strong>"); |
| 193 | |
| 194 | menuItem.lowlight(); |
| 195 | expect(menuItem.element.innerHTML).toEqual("<strong>CoreNLP</strong>"); |
| 196 | |
| 197 | // Highlight in the middle - first |
| 198 | menuItem = KorAP.MenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']); |
| 199 | menuItem.highlight("ren"); |
| 200 | expect(menuItem.element.innerHTML).toEqual("<strong>Co<em>reN</em>LP</strong><span>This is my Example</span>"); |
| 201 | |
| 202 | menuItem.lowlight(); |
| 203 | expect(menuItem.element.innerHTML).toEqual("<strong>CoreNLP</strong><span>This is my Example</span>"); |
| 204 | |
| 205 | // Highlight in the middle - second |
| 206 | menuItem = KorAP.MenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']); |
| 207 | menuItem.highlight("ampl"); |
| 208 | expect(menuItem.element.innerHTML).toEqual("<strong>CoreNLP</strong><span>This is my Ex<em>ampl</em>e</span>"); |
| 209 | |
| 210 | menuItem.lowlight(); |
| 211 | expect(menuItem.element.innerHTML).toEqual("<strong>CoreNLP</strong><span>This is my Example</span>"); |
| 212 | |
| 213 | // Highlight in the middle - both |
| 214 | menuItem = KorAP.MenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']); |
| 215 | menuItem.highlight("e"); |
| 216 | expect(menuItem.element.innerHTML).toEqual("<strong>Cor<em>e</em>NLP</strong><span>This is my <em>E</em>xample</span>"); |
| 217 | |
| 218 | menuItem.lowlight(); |
| 219 | expect(menuItem.element.innerHTML).toEqual("<strong>CoreNLP</strong><span>This is my Example</span>"); |
| 220 | |
| 221 | // Highlight in the end - second |
| 222 | menuItem = KorAP.MenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']); |
| 223 | menuItem.highlight("le"); |
| 224 | expect(menuItem.element.innerHTML).toEqual("<strong>CoreNLP</strong><span>This is my Examp<em>le</em></span>"); |
| 225 | |
| 226 | menuItem.lowlight(); |
| 227 | expect(menuItem.element.innerHTML).toEqual("<strong>CoreNLP</strong><span>This is my Example</span>"); |
| 228 | |
| 229 | // Highlight at the beginning - second |
| 230 | menuItem = KorAP.MenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']); |
| 231 | menuItem.highlight("this"); |
| 232 | expect(menuItem.element.innerHTML).toEqual("<strong>CoreNLP</strong><span><em>This</em> is my Example</span>"); |
| 233 | |
| 234 | menuItem.lowlight(); |
| 235 | expect(menuItem.element.innerHTML).toEqual("<strong>CoreNLP</strong><span>This is my Example</span>"); |
| 236 | }); |
| 237 | }); |
| 238 | |
| 239 | |
| 240 | describe('KorAP.Menu', function () { |
| 241 | |
| 242 | var list = [ |
| 243 | ["Constituency", "c=", "Example 1"], |
| 244 | ["Lemma", "l="], |
| 245 | ["Morphology", "m=", "Example 2"], |
| 246 | ["Part-of-Speech", "p="], |
| 247 | ["Syntax", "syn="] |
| 248 | ]; |
| 249 | |
| 250 | |
| 251 | it('should be initializable', function () { |
| 252 | |
| 253 | var menu = KorAP.Menu.create("cnx/", list); |
| 254 | expect(menu.context).toEqual('cnx/'); |
| 255 | expect(menu.element.nodeName).toEqual('UL'); |
| 256 | expect(menu.element.style.opacity).toEqual("0"); |
| 257 | |
| 258 | KorAP.limit = 8; |
| 259 | |
| 260 | // view |
| 261 | menu.show(); |
| 262 | |
| 263 | // First element in list |
| 264 | expect(menu.item(0).active()).toBe(true); |
| 265 | expect(menu.item(0).noMore()).toBe(true); |
| 266 | |
| 267 | // Middle element in list |
| 268 | expect(menu.item(2).active()).toBe(false); |
| 269 | expect(menu.item(2).noMore()).toBe(false); |
| 270 | |
| 271 | // Last element in list |
| 272 | expect(menu.item(menu.length - 1).active()).toBe(false); |
| 273 | expect(menu.item(menu.length - 1).noMore()).toBe(true); |
| 274 | }); |
| 275 | |
| 276 | it('should be visible', function () { |
| 277 | var menu = KorAP.Menu.create("cnx/", list); |
| 278 | expect(menu.delete()).toBe(undefined); |
| 279 | |
| 280 | KorAP.limit = 3; |
| 281 | |
| 282 | expect(menu.show()).toBe(undefined); |
| 283 | expect(menu.element.firstChild.innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>"); |
| 284 | expect(menu.element.childNodes[1].innerHTML).toEqual("<strong>Lemma</strong>"); |
| 285 | expect(menu.element.childNodes[1].getAttribute("data-action")).toEqual("l="); |
| 286 | expect(menu.element.childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
| 287 | expect(menu.element.childNodes[3]).toBe(undefined); |
| 288 | |
| 289 | // Check boundaries |
| 290 | expect(menu.element.childNodes[0].classList.contains("no-more")).toBe(true); |
| 291 | expect(menu.element.childNodes[1].classList.contains("no-more")).toBe(false); |
| 292 | expect(menu.element.childNodes[2].classList.contains("no-more")).toBe(false); |
| 293 | }); |
| 294 | |
| 295 | |
| 296 | it('should be filterable', function () { |
| 297 | var menu = KorAP.Menu.create("cnx/", list); |
| 298 | |
| 299 | KorAP.limit = 3; |
| 300 | |
| 301 | expect(menu.show("o")).toBe(undefined); |
| 302 | expect(menu.element.childNodes[0].innerHTML).toEqual("<strong>C<em>o</em>nstituency</strong><span>Example 1</span>"); |
| 303 | expect(menu.element.childNodes[1].innerHTML).toEqual("<strong>M<em>o</em>rphology</strong><span>Example 2</span>"); |
| 304 | expect(menu.element.childNodes[2].innerHTML).toEqual("<strong>Part-<em>o</em>f-Speech</strong>"); |
| 305 | expect(menu.element.childNodes[3]).toBe(undefined); |
| 306 | |
| 307 | // Check boundaries |
| 308 | expect(menu.element.childNodes[0].classList.contains("no-more")).toBe(true); |
| 309 | expect(menu.element.childNodes[1].classList.contains("no-more")).toBe(false); |
| 310 | expect(menu.element.childNodes[2].classList.contains("no-more")).toBe(true); |
| 311 | |
| 312 | |
| 313 | KorAP.limit = 2; |
| 314 | |
| 315 | expect(menu.show("o")).toBe(undefined); |
| 316 | expect(menu.element.childNodes[0].innerHTML).toEqual("<strong>C<em>o</em>nstituency</strong><span>Example 1</span>"); |
| 317 | expect(menu.element.childNodes[1].innerHTML).toEqual("<strong>M<em>o</em>rphology</strong><span>Example 2</span>"); |
| 318 | expect(menu.element.childNodes[2]).toBe(undefined); |
| 319 | |
| 320 | // Check boundaries |
| 321 | expect(menu.element.childNodes[0].classList.contains("no-more")).toBe(true); |
| 322 | expect(menu.element.childNodes[1].classList.contains("no-more")).toBe(false); |
| 323 | expect(menu.element.childNodes[2]).toBe(undefined); |
| 324 | }); |
| 325 | |
| 326 | it('should be nextable', function () { |
| 327 | var menu = KorAP.Menu.create("cnx/", list); |
| 328 | |
| 329 | KorAP.limit = 3; |
| 330 | expect(menu.show()).toBe(undefined); |
| 331 | |
| 332 | expect(menu.element.childNodes[0].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>"); |
| 333 | expect(menu.shownItem(0).active()).toBe(true); |
| 334 | expect(menu.element.childNodes[1].innerHTML).toEqual("<strong>Lemma</strong>"); |
| 335 | expect(menu.shownItem(1).active()).toBe(false); |
| 336 | expect(menu.element.childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
| 337 | expect(menu.shownItem(2).active()).toBe(false); |
| 338 | expect(menu.element.childNodes[3]).toBe(undefined); |
| 339 | |
| 340 | // Activate next (1) |
| 341 | menu.next(); |
| 342 | expect(menu.element.childNodes[0].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>"); |
| 343 | expect(menu.shownItem(0).active()).toBe(false); |
| 344 | expect(menu.element.childNodes[1].innerHTML).toEqual("<strong>Lemma</strong>"); |
| 345 | expect(menu.shownItem(1).active()).toBe(true); |
| 346 | expect(menu.element.childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
| 347 | expect(menu.shownItem(2).active()).toBe(false); |
| 348 | expect(menu.element.childNodes[3]).toBe(undefined); |
| 349 | |
| 350 | // Activate next (2) |
| 351 | menu.next(); |
| 352 | expect(menu.element.childNodes[0].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>"); |
| 353 | expect(menu.shownItem(0).active()).toBe(false); |
| 354 | expect(menu.element.childNodes[1].innerHTML).toEqual("<strong>Lemma</strong>"); |
| 355 | expect(menu.shownItem(1).active()).toBe(false); |
| 356 | expect(menu.element.childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
| 357 | expect(menu.shownItem(2).active()).toBe(true); |
| 358 | expect(menu.element.childNodes[3]).toBe(undefined); |
| 359 | |
| 360 | // Activate next (3) |
| 361 | menu.next(); |
| 362 | expect(menu.element.childNodes[0].innerHTML).toEqual("<strong>Lemma</strong>"); |
| 363 | expect(menu.shownItem(0).active()).toBe(false); |
| 364 | expect(menu.element.childNodes[1].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
| 365 | expect(menu.shownItem(1).active()).toBe(false); |
| 366 | expect(menu.element.childNodes[2].innerHTML).toEqual("<strong>Part-of-Speech</strong>"); |
| 367 | expect(menu.shownItem(2).active()).toBe(true); |
| 368 | expect(menu.element.childNodes[3]).toBe(undefined); |
| 369 | |
| 370 | // Activate next (4) |
| 371 | menu.next(); |
| 372 | expect(menu.element.childNodes[0].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
| 373 | expect(menu.shownItem(0).active()).toBe(false); |
| 374 | expect(menu.element.childNodes[1].innerHTML).toEqual("<strong>Part-of-Speech</strong>"); |
| 375 | expect(menu.shownItem(1).active()).toBe(false); |
| 376 | expect(menu.element.childNodes[2].innerHTML).toEqual("<strong>Syntax</strong>"); |
| 377 | expect(menu.shownItem(2).active()).toBe(true); |
| 378 | expect(menu.element.childNodes[3]).toBe(undefined); |
| 379 | |
| 380 | // Activate next (5) - ROLL |
| 381 | menu.next(); |
| 382 | expect(menu.element.childNodes[0].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>"); |
| 383 | expect(menu.shownItem(0).active()).toBe(true); |
| 384 | expect(menu.element.childNodes[1].innerHTML).toEqual("<strong>Lemma</strong>"); |
| 385 | expect(menu.shownItem(1).active()).toBe(false); |
| 386 | expect(menu.element.childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
| 387 | expect(menu.shownItem(2).active()).toBe(false); |
| 388 | expect(menu.element.childNodes[3]).toBe(undefined); |
| 389 | |
| 390 | // Active next (6) |
| 391 | menu.next(); |
| 392 | expect(menu.element.childNodes[0].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>"); |
| 393 | expect(menu.shownItem(0).active()).toBe(false); |
| 394 | expect(menu.element.childNodes[1].innerHTML).toEqual("<strong>Lemma</strong>"); |
| 395 | expect(menu.shownItem(1).active()).toBe(true); |
| 396 | expect(menu.element.childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
| 397 | expect(menu.shownItem(2).active()).toBe(false); |
| 398 | expect(menu.element.childNodes[3]).toBe(undefined); |
| 399 | |
| 400 | }); |
| 401 | |
| 402 | |
| 403 | it('should be prevable', function () { |
| 404 | var menu = KorAP.Menu.create("cnx/", list); |
| 405 | |
| 406 | KorAP.limit = 3; |
| 407 | expect(menu.show()).toBe(undefined); |
| 408 | |
| 409 | expect(menu.element.childNodes[0].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>"); |
| 410 | expect(menu.shownItem(0).active()).toBe(true); |
| 411 | expect(menu.element.childNodes[1].innerHTML).toEqual("<strong>Lemma</strong>"); |
| 412 | expect(menu.shownItem(1).active()).toBe(false); |
| 413 | expect(menu.element.childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
| 414 | expect(menu.shownItem(2).active()).toBe(false); |
| 415 | expect(menu.element.childNodes[3]).toBe(undefined); |
| 416 | |
| 417 | // Activate prev (1) - roll to bottom |
| 418 | menu.prev(); |
| 419 | expect(menu.element.childNodes[0].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
| 420 | expect(menu.shownItem(0).active()).toBe(false); |
| 421 | expect(menu.element.childNodes[1].innerHTML).toEqual("<strong>Part-of-Speech</strong>"); |
| 422 | expect(menu.shownItem(1).active()).toBe(false); |
| 423 | expect(menu.element.childNodes[2].innerHTML).toEqual("<strong>Syntax</strong>"); |
| 424 | expect(menu.shownItem(2).active()).toBe(true); |
| 425 | expect(menu.element.childNodes[3]).toBe(undefined); |
| 426 | |
| 427 | // Activate prev (2) |
| 428 | menu.prev(); |
| 429 | expect(menu.element.childNodes[0].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
| 430 | expect(menu.shownItem(0).active()).toBe(false); |
| 431 | expect(menu.element.childNodes[1].innerHTML).toEqual("<strong>Part-of-Speech</strong>"); |
| 432 | expect(menu.shownItem(1).active()).toBe(true); |
| 433 | expect(menu.element.childNodes[2].innerHTML).toEqual("<strong>Syntax</strong>"); |
| 434 | expect(menu.shownItem(2).active()).toBe(false); |
| 435 | expect(menu.element.childNodes[3]).toBe(undefined); |
| 436 | |
| 437 | // Activate prev (3) |
| 438 | menu.prev(); |
| 439 | expect(menu.shownItem(0).name).toEqual("Morphology"); |
| 440 | expect(menu.shownItem(0).active()).toBe(true); |
| 441 | expect(menu.shownItem(1).name).toEqual("Part-of-Speech"); |
| 442 | expect(menu.shownItem(1).active()).toBe(false); |
| 443 | expect(menu.shownItem(2).name).toEqual("Syntax"); |
| 444 | expect(menu.shownItem(2).active()).toBe(false); |
| 445 | expect(menu.element.childNodes[3]).toBe(undefined); |
| 446 | |
| 447 | // Activate prev (4) |
| 448 | menu.prev(); |
| 449 | expect(menu.shownItem(0).name).toEqual("Lemma"); |
| 450 | expect(menu.shownItem(0).active()).toBe(true); |
| 451 | expect(menu.shownItem(1).name).toEqual("Morphology"); |
| 452 | expect(menu.shownItem(1).active()).toBe(false); |
| 453 | expect(menu.shownItem(2).name).toEqual("Part-of-Speech"); |
| 454 | expect(menu.shownItem(2).active()).toBe(false); |
| 455 | expect(menu.element.childNodes[3]).toBe(undefined); |
| 456 | |
| 457 | // Activate prev (5) |
| 458 | menu.prev(); |
| 459 | expect(menu.shownItem(0).name).toEqual("Constituency"); |
| 460 | expect(menu.shownItem(0).active()).toBe(true); |
| 461 | expect(menu.shownItem(1).name).toEqual("Lemma"); |
| 462 | expect(menu.shownItem(1).active()).toBe(false); |
| 463 | expect(menu.shownItem(2).name).toEqual("Morphology"); |
| 464 | expect(menu.shownItem(2).active()).toBe(false); |
| 465 | expect(menu.element.childNodes[3]).toBe(undefined); |
| 466 | |
| 467 | // Activate next (1) |
| 468 | menu.next(); |
| 469 | expect(menu.shownItem(0).name).toEqual("Constituency"); |
| 470 | expect(menu.shownItem(0).active()).toBe(false); |
| 471 | expect(menu.shownItem(1).name).toEqual("Lemma"); |
| 472 | expect(menu.shownItem(1).active()).toBe(true); |
| 473 | expect(menu.shownItem(2).name).toEqual("Morphology"); |
| 474 | expect(menu.shownItem(2).active()).toBe(false); |
| 475 | expect(menu.element.childNodes[3]).toBe(undefined); |
| 476 | |
| 477 | // Activate prev (6) |
| 478 | menu.prev(); |
| 479 | |
| 480 | // Activate prev (7) |
| 481 | menu.prev(); |
| 482 | expect(menu.shownItem(0).name).toEqual("Morphology"); |
| 483 | expect(menu.shownItem(0).active()).toBe(false); |
| 484 | expect(menu.shownItem(1).name).toEqual("Part-of-Speech"); |
| 485 | expect(menu.shownItem(1).active()).toBe(false); |
| 486 | expect(menu.shownItem(2).name).toEqual("Syntax"); |
| 487 | expect(menu.shownItem(2).active()).toBe(true); |
| 488 | expect(menu.element.childNodes[3]).toBe(undefined); |
| 489 | }); |
| 490 | |
| 491 | it('should be navigatable and filterable (prefix = "o")', function () { |
| 492 | var menu = KorAP.Menu.create("cnx/", list); |
| 493 | |
| 494 | KorAP.limit = 2; |
| 495 | |
| 496 | expect(menu.show("o")).toBe(undefined); |
| 497 | |
| 498 | expect(menu.shownItem(0).name).toEqual("Constituency"); |
| 499 | expect(menu.element.childNodes[0].innerHTML).toEqual("<strong>C<em>o</em>nstituency</strong><span>Example 1</span>"); |
| 500 | expect(menu.shownItem(0).active()).toBe(true); |
| 501 | expect(menu.shownItem(1).name).toEqual("Morphology"); |
| 502 | expect(menu.element.childNodes[1].innerHTML).toEqual("<strong>M<em>o</em>rphology</strong><span>Example 2</span>"); |
| 503 | expect(menu.shownItem(1).active()).toBe(false); |
| 504 | expect(menu.shownItem(2)).toBe(undefined); |
| 505 | |
| 506 | // Next (1) |
| 507 | menu.next(); |
| 508 | expect(menu.shownItem(0).name).toEqual("Constituency"); |
| 509 | expect(menu.element.childNodes[0].innerHTML).toEqual("<strong>C<em>o</em>nstituency</strong><span>Example 1</span>"); |
| 510 | expect(menu.shownItem(0).active()).toBe(false); |
| 511 | expect(menu.shownItem(1).name).toEqual("Morphology"); |
| 512 | expect(menu.element.childNodes[1].innerHTML).toEqual("<strong>M<em>o</em>rphology</strong><span>Example 2</span>"); |
| 513 | expect(menu.shownItem(1).active()).toBe(true); |
| 514 | expect(menu.shownItem(2)).toBe(undefined); |
| 515 | |
| 516 | |
| 517 | // Next (2) |
| 518 | menu.next(); |
| 519 | expect(menu.shownItem(0).name).toEqual("Morphology"); |
| 520 | expect(menu.element.childNodes[0].innerHTML).toEqual("<strong>M<em>o</em>rphology</strong><span>Example 2</span>"); |
| 521 | expect(menu.shownItem(0).active()).toBe(false); |
| 522 | expect(menu.shownItem(1).name).toEqual("Part-of-Speech"); |
| 523 | expect(menu.element.childNodes[1].innerHTML).toEqual("<strong>Part-<em>o</em>f-Speech</strong>"); |
| 524 | expect(menu.shownItem(1).active()).toBe(true); |
| 525 | expect(menu.shownItem(2)).toBe(undefined); |
| 526 | |
| 527 | // Next (3) |
| 528 | menu.next(); |
| 529 | expect(menu.shownItem(0).name).toEqual("Constituency"); |
| 530 | expect(menu.element.childNodes[0].innerHTML).toEqual("<strong>C<em>o</em>nstituency</strong><span>Example 1</span>"); |
| 531 | expect(menu.shownItem(0).active()).toBe(true); |
| 532 | expect(menu.shownItem(1).name).toEqual("Morphology"); |
| 533 | expect(menu.element.childNodes[1].innerHTML).toEqual("<strong>M<em>o</em>rphology</strong><span>Example 2</span>"); |
| 534 | expect(menu.shownItem(1).active()).toBe(false); |
| 535 | expect(menu.shownItem(2)).toBe(undefined); |
| 536 | }); |
| 537 | |
| 538 | it('should be navigatable and filterable (prefix = "ex", "e")', function () { |
| 539 | var menu = KorAP.Menu.create("cnx/", list); |
| 540 | |
| 541 | KorAP.limit = 2; |
| 542 | |
| 543 | expect(menu.show("ex")).toBe(undefined); |
| 544 | |
| 545 | expect(menu.shownItem(0).name).toEqual("Constituency"); |
| 546 | expect(menu.element.childNodes[0].innerHTML).toEqual("<strong>Constituency</strong><span><em>Ex</em>ample 1</span>"); |
| 547 | expect(menu.shownItem(0).active()).toBe(true); |
| 548 | expect(menu.shownItem(1).name).toEqual("Morphology"); |
| 549 | expect(menu.element.childNodes[1].innerHTML).toEqual("<strong>Morphology</strong><span><em>Ex</em>ample 2</span>"); |
| 550 | expect(menu.shownItem(1).active()).toBe(false); |
| 551 | expect(menu.shownItem(2)).toBe(undefined); |
| 552 | |
| 553 | // Next (1) |
| 554 | menu.next(); |
| 555 | expect(menu.shownItem(0).name).toEqual("Constituency"); |
| 556 | expect(menu.element.childNodes[0].innerHTML).toEqual("<strong>Constituency</strong><span><em>Ex</em>ample 1</span>"); |
| 557 | expect(menu.shownItem(0).active()).toBe(false); |
| 558 | expect(menu.shownItem(1).name).toEqual("Morphology"); |
| 559 | expect(menu.element.childNodes[1].innerHTML).toEqual("<strong>Morphology</strong><span><em>Ex</em>ample 2</span>"); |
| 560 | expect(menu.shownItem(1).active()).toBe(true); |
| 561 | expect(menu.shownItem(2)).toBe(undefined); |
| 562 | |
| 563 | // Next (2) |
| 564 | menu.next(); |
| 565 | expect(menu.shownItem(0).name).toEqual("Constituency"); |
| 566 | expect(menu.element.childNodes[0].innerHTML).toEqual("<strong>Constituency</strong><span><em>Ex</em>ample 1</span>"); |
| 567 | expect(menu.shownItem(0).active()).toBe(true); |
| 568 | expect(menu.shownItem(1).name).toEqual("Morphology"); |
| 569 | expect(menu.element.childNodes[1].innerHTML).toEqual("<strong>Morphology</strong><span><em>Ex</em>ample 2</span>"); |
| 570 | expect(menu.shownItem(1).active()).toBe(false); |
| 571 | expect(menu.shownItem(2)).toBe(undefined); |
| 572 | |
| 573 | // Reset limit |
| 574 | KorAP.limit = 5; |
| 575 | |
| 576 | // Change show |
| 577 | expect(menu.show("e")).toBe(undefined); |
| 578 | |
| 579 | expect(menu.shownItem(0).name).toEqual("Constituency"); |
| 580 | expect(menu.element.childNodes[0].innerHTML).toEqual("<strong>Constitu<em>e</em>ncy</strong><span><em>E</em>xample 1</span>"); |
| 581 | expect(menu.shownItem(0).active()).toBe(true); |
| 582 | expect(menu.shownItem(1).name).toEqual("Morphology"); |
| 583 | expect(menu.element.childNodes[1].innerHTML).toEqual("<strong>Morphology</strong><span><em>E</em>xample 2</span>"); |
| 584 | expect(menu.shownItem(1).active()).toBe(false); |
| 585 | expect(menu.shownItem(2)).toBe(undefined); |
| 586 | |
| 587 | // Next (1) |
| 588 | menu.next(); |
| 589 | expect(menu.shownItem(0).name).toEqual("Constituency"); |
| 590 | expect(menu.element.childNodes[0].innerHTML).toEqual("<strong>Constitu<em>e</em>ncy</strong><span><em>E</em>xample 1</span>"); |
| 591 | expect(menu.shownItem(0).active()).toBe(false); |
| 592 | expect(menu.shownItem(1).name).toEqual("Morphology"); |
| 593 | expect(menu.element.childNodes[1].innerHTML).toEqual("<strong>Morphology</strong><span><em>E</em>xample 2</span>"); |
| 594 | expect(menu.shownItem(1).active()).toBe(true); |
| 595 | expect(menu.shownItem(2)).toBe(undefined); |
| 596 | |
| 597 | // Next (2) |
| 598 | menu.next(); |
| 599 | expect(menu.shownItem(0).name).toEqual("Constituency"); |
| 600 | expect(menu.element.childNodes[0].innerHTML).toEqual("<strong>Constitu<em>e</em>ncy</strong><span><em>E</em>xample 1</span>"); |
| 601 | expect(menu.shownItem(0).active()).toBe(true); |
| 602 | expect(menu.shownItem(1).name).toEqual("Morphology"); |
| 603 | expect(menu.element.childNodes[1].innerHTML).toEqual("<strong>Morphology</strong><span><em>E</em>xample 2</span>"); |
| 604 | expect(menu.shownItem(1).active()).toBe(false); |
| 605 | expect(menu.shownItem(2)).toBe(undefined); |
| 606 | }); |
| 607 | }); |
| 608 | |
| 609 | describe('KorAP.ContextAnalyzer', function () { |
| 610 | |
| 611 | it('should be initializable', function () { |
| 612 | var analyzer = KorAP.ContextAnalyzer.create(")"); |
| 613 | expect(analyzer).toBe(undefined); |
| 614 | |
| 615 | analyzer = KorAP.ContextAnalyzer.create(".+?"); |
| 616 | expect(analyzer).not.toBe(undefined); |
| 617 | |
| 618 | }); |
| 619 | |
| 620 | it('should check correctly', function () { |
| 621 | analyzer = KorAP.ContextAnalyzer.create(KorAP.context); |
| 622 | expect(analyzer.test("cnx/]cnx/c=")).toEqual("cnx/c="); |
| 623 | expect(analyzer.test("cnx/c=")).toEqual("cnx/c="); |
| 624 | expect(analyzer.test("cnx/c=np mate/m=mood:")).toEqual("mate/m=mood:"); |
| 625 | expect(analyzer.test("impcnx/")).toEqual("impcnx/"); |
| 626 | expect(analyzer.test("cnx/c=npcnx/")).toEqual("npcnx/"); |
| 627 | expect(analyzer.test("mate/m=degree:pos corenlp/ne_dewac_175m_600=")) |
| 628 | .toEqual("corenlp/ne_dewac_175m_600="); |
| 629 | }); |
| 630 | }); |
| 631 | |
| 632 | describe('KorAP.InputField', function () { |
| 633 | var input; |
| 634 | |
| 635 | beforeAll(function () { |
| 636 | input = document.createElement("input"); |
| 637 | input.setAttribute("type", "text"); |
| 638 | input.setAttribute("value", "abcdefghijklmno"); |
| 639 | input.style.position = 'absolute'; |
| 640 | input.style.top = "20px"; |
| 641 | input.style.left = "30px"; |
| 642 | input.focus(); |
| 643 | input.selectionStart = 5; |
| 644 | }); |
| 645 | |
| 646 | afterAll(function () { |
| 647 | document.getElementsByTagName("body")[0].removeChild(input); |
| 648 | document.getElementsByTagName("body")[0].removeChild( |
| 649 | document.getElementById("searchMirror") |
| 650 | ); |
| 651 | }); |
| 652 | |
| 653 | it('should be initializable', function () { |
| 654 | // Supports: context, searchField |
| 655 | var inputField = KorAP.InputField.create(input); |
| 656 | expect(inputField._element).not.toBe(undefined); |
| 657 | }); |
| 658 | |
| 659 | it('should have text', function () { |
| 660 | var inputField = KorAP.InputField.create(input); |
| 661 | |
| 662 | expect(inputField.value).toEqual("abcdefghijklmno"); |
| 663 | expect(inputField.element.selectionStart).toEqual(5); |
| 664 | expect(inputField.split()[0]).toEqual("abcde"); |
| 665 | expect(inputField.split()[1]).toEqual("fghijklmno"); |
| 666 | |
| 667 | inputField.insert("xyz"); |
| 668 | expect(inputField.split()[0]).toEqual("abcdexyz"); |
| 669 | expect(inputField.split()[1]).toEqual("fghijklmno"); |
| 670 | |
| 671 | }); |
| 672 | |
| 673 | it('should be correctly positioned', function () { |
| 674 | var inputField = KorAP.InputField.create(input); |
| 675 | document.getElementsByTagName("body")[0].appendChild(input); |
| 676 | inputField.reposition(); |
| 677 | expect(inputField.mirror.style.left).toEqual("30px"); |
| 678 | expect(inputField.mirror.style.top.match(/^(\d+)px$/)[1]).toBeGreaterThan(20); |
| 679 | }); |
| 680 | |
Nils Diewald | dc3862c | 2014-12-16 02:44:59 +0000 | [diff] [blame] | 681 | /* |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 682 | it('should be correctly triggerable', function () { |
| 683 | // https://developer.mozilla.org/samples/domref/dispatchEvent.html |
| 684 | var hint = KorAP.Hint.create({ "inputField" : input }); |
| 685 | emitKeyboardEvent(hint.inputField.element, "keypress", 20); |
| 686 | }); |
Nils Diewald | dc3862c | 2014-12-16 02:44:59 +0000 | [diff] [blame] | 687 | */ |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 688 | |
| 689 | }); |
| 690 | |
| 691 | |
| 692 | |
| 693 | /* |
| 694 | describe('KorAP.Hint', function () { |
| 695 | KorAP.hintArray = { |
| 696 | "corenlp/" : [ |
| 697 | ["Named Entity", "ne=" , "Combined"], |
| 698 | ["Named Entity", "ne_dewac_175m_600=" , "ne_dewac_175m_600"], |
| 699 | ["Named Entity", "ne_hgc_175m_600=", "ne_hgc_175m_600"] |
| 700 | ] |
| 701 | }; |
| 702 | |
| 703 | it('should be initializable', function () { |
| 704 | // Supports: context, searchField |
| 705 | var hint = KorAP.Hint.create(); |
| 706 | }); |
| 707 | }); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 708 | |
| 709 | |
| 710 | describe('KorAP.ContextAnalyzer', function () { |
| 711 | |
| 712 | it('should be initializable', function () { |
| 713 | var analyzer = KorAP.ContextAnalyzer.create(")"); |
| 714 | expect(analyzer).toBe(undefined); |
| 715 | |
| 716 | analyzer = KorAP.ContextAnalyzer.create(".+?"); |
| 717 | expect(analyzer).not.toBe(undefined); |
| 718 | |
| 719 | }); |
| 720 | |
| 721 | it('should check correctly', function () { |
| 722 | analyzer = KorAP.ContextAnalyzer.create(KorAP.context); |
| 723 | expect(analyzer.test("cnx/]cnx/c=")).toEqual("cnx/c="); |
| 724 | expect(analyzer.test("cnx/c=")).toEqual("cnx/c="); |
| 725 | expect(analyzer.test("cnx/c=np mate/m=mood:")).toEqual("mate/m=mood:"); |
| 726 | expect(analyzer.test("impcnx/")).toEqual("impcnx/"); |
| 727 | expect(analyzer.test("cnx/c=npcnx/")).toEqual("npcnx/"); |
| 728 | expect(analyzer.test("mate/m=degree:pos corenlp/ne_dewac_175m_600=")) |
| 729 | .toEqual("corenlp/ne_dewac_175m_600="); |
| 730 | }); |
| 731 | }); |
| 732 | |
| 733 | describe('KorAP.InputField', function () { |
| 734 | var input; |
| 735 | |
| 736 | beforeAll(function () { |
| 737 | input = document.createElement("input"); |
| 738 | input.setAttribute("type", "text"); |
| 739 | input.setAttribute("value", "abcdefghijklmno"); |
| 740 | input.style.position = 'absolute'; |
| 741 | input.style.top = "20px"; |
| 742 | input.style.left = "30px"; |
| 743 | input.focus(); |
| 744 | input.selectionStart = 5; |
| 745 | }); |
| 746 | |
| 747 | afterAll(function () { |
| 748 | document.getElementsByTagName("body")[0].removeChild(input); |
| 749 | document.getElementsByTagName("body")[0].removeChild( |
| 750 | document.getElementById("searchMirror") |
| 751 | ); |
| 752 | }); |
| 753 | |
| 754 | it('should be initializable', function () { |
| 755 | // Supports: context, searchField |
| 756 | var inputField = KorAP.InputField.create(input); |
| 757 | expect(inputField._element).not.toBe(undefined); |
| 758 | }); |
| 759 | |
| 760 | it('should have text', function () { |
| 761 | var inputField = KorAP.InputField.create(input); |
| 762 | |
| 763 | expect(inputField.value).toEqual("abcdefghijklmno"); |
| 764 | expect(inputField.element.selectionStart).toEqual(5); |
| 765 | expect(inputField.split()[0]).toEqual("abcde"); |
| 766 | expect(inputField.split()[1]).toEqual("fghijklmno"); |
| 767 | |
| 768 | inputField.insert("xyz"); |
| 769 | expect(inputField.split()[0]).toEqual("abcdexyz"); |
| 770 | expect(inputField.split()[1]).toEqual("fghijklmno"); |
| 771 | |
| 772 | }); |
| 773 | |
| 774 | it('should be correctly positioned', function () { |
| 775 | var inputField = KorAP.InputField.create(input); |
| 776 | document.getElementsByTagName("body")[0].appendChild(input); |
| 777 | inputField.reposition(); |
| 778 | expect(inputField.mirror.style.left).toEqual("30px"); |
| 779 | expect(inputField.mirror.style.top.match(/^(\d+)px$/)[1]).toBeGreaterThan(20); |
| 780 | }); |
| 781 | }); |
| 782 | |
| 783 | |
| 784 | |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 785 | */ |