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