Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1 | define(['menu'], function () { |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 2 | |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 3 | var menuItemClass = require('menu/item'); |
| 4 | var prefixClass = require('menu/prefix'); |
| 5 | var menuClass = require('menu'); |
| 6 | var lengthFieldClass = require('menu/lengthField'); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 7 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 8 | // The OwnMenu item |
| 9 | KorAP.OwnMenuItem = { |
| 10 | create : function (params) { |
| 11 | return Object.create(menuItemClass).upgradeTo(KorAP.OwnMenuItem)._init(params); |
| 12 | }, |
| 13 | content : function (content) { |
| 14 | if (arguments.length === 1) { |
| 15 | this._content = content; |
| 16 | }; |
| 17 | return this._content; |
| 18 | }, |
| 19 | _init : function (params) { |
| 20 | if (params[0] === undefined) |
| 21 | throw new Error("Missing parameters"); |
| 22 | |
| 23 | this._content = document.createTextNode(params[0]); |
| 24 | this._lcField = ' ' + this.content().textContent.toLowerCase(); |
| 25 | |
| 26 | return this; |
| 27 | } |
| 28 | }; |
| 29 | |
| 30 | // The OwnMenu |
| 31 | KorAP.OwnMenu = { |
| 32 | create : function (params) { |
| 33 | return Object.create(menuClass) |
| 34 | .upgradeTo(KorAP.OwnMenu) |
| 35 | ._init(KorAP.OwnMenuItem, undefined, params); |
| 36 | } |
| 37 | }; |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 38 | |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 39 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 40 | // HintMenuItem |
| 41 | KorAP.HintMenuItem = { |
| 42 | create : function (params) { |
| 43 | return Object.create(menuItemClass) |
| 44 | .upgradeTo(KorAP.HintMenuItem) |
| 45 | ._init(params); |
| 46 | }, |
| 47 | content : function (content) { |
| 48 | if (arguments.length === 1) { |
| 49 | this._content = content; |
| 50 | }; |
| 51 | return this._content; |
| 52 | }, |
| 53 | _init : function (params) { |
| 54 | if (params[0] === undefined || params[1] === undefined) |
| 55 | throw new Error("Missing parameters"); |
| 56 | |
| 57 | this._name = params[0]; |
| 58 | this._action = params[1]; |
| 59 | this._lcField = ' ' + this._name.toLowerCase(); |
| 60 | |
| 61 | if (params.length > 2) { |
| 62 | this._desc = params[2]; |
| 63 | this._lcField += " " + this._desc.toLowerCase(); |
| 64 | }; |
| 65 | |
| 66 | return this; |
| 67 | }, |
| 68 | |
| 69 | name : function () { |
| 70 | return this._name; |
| 71 | }, |
| 72 | action : function () { |
| 73 | return this._action; |
| 74 | }, |
| 75 | desc : function () { |
| 76 | return this._desc; |
| 77 | }, |
| 78 | element : function () { |
| 79 | // already defined |
| 80 | if (this._element !== undefined) |
| 81 | return this._element; |
| 82 | |
| 83 | // Create list item |
| 84 | var li = document.createElement("li"); |
| 85 | li.setAttribute("data-action", this._action); |
| 86 | |
| 87 | // Create title |
| 88 | var name = document.createElement("strong"); |
| 89 | name.appendChild(document.createTextNode(this._name)); |
| 90 | |
| 91 | li.appendChild(name); |
| 92 | |
| 93 | // Create description |
| 94 | if (this._desc !== undefined) { |
| 95 | var desc = document.createElement("span"); |
| 96 | desc.appendChild(document.createTextNode(this._desc)); |
| 97 | li.appendChild(desc); |
| 98 | }; |
| 99 | return this._element = li; |
| 100 | } |
| 101 | }; |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 102 | |
| 103 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 104 | // HintMenu |
| 105 | KorAP.HintMenu = { |
| 106 | create : function (context, params) { |
| 107 | var obj = Object.create(menuClass) |
| 108 | .upgradeTo(KorAP.HintMenu) |
| 109 | ._init(KorAP.HintMenuItem, undefined, params); |
| 110 | obj._context = context; |
| 111 | return obj; |
| 112 | } |
| 113 | }; |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 114 | |
| 115 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 116 | // The ComplexMenuItem |
| 117 | KorAP.ComplexMenuItem = { |
| 118 | create : function (params) { |
| 119 | return Object.create(menuItemClass) |
| 120 | .upgradeTo(KorAP.ComplexMenuItem) |
| 121 | ._init(params); |
| 122 | }, |
| 123 | content : function (content) { |
| 124 | if (arguments.length === 1) { |
| 125 | this._content = content; |
| 126 | }; |
| 127 | return this._content; |
| 128 | }, |
| 129 | _init : function (params) { |
| 130 | if (params[0] === undefined) |
| 131 | throw new Error("Missing parameters"); |
| 132 | |
| 133 | var r = document.createElement('div'); |
| 134 | for (var i = 1; i <= params.length; i++) { |
| 135 | var h = document.createElement('h' + i); |
| 136 | h.appendChild(document.createTextNode(params[i-1])); |
| 137 | r.appendChild(h); |
| 138 | }; |
| 139 | |
| 140 | this._content = r; |
| 141 | this._lcField = ' ' + this.content().textContent.toLowerCase(); |
| 142 | |
| 143 | return this; |
| 144 | } |
| 145 | }; |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 146 | |
| 147 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 148 | describe('KorAP.MenuItem', function () { |
| 149 | it('should be initializable', function () { |
| 150 | expect( |
| 151 | function() { menuItemClass.create([]) } |
| 152 | ).toThrow(new Error("Missing parameters")); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 153 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 154 | expect( |
| 155 | function() { KorAP.OwnMenuItem.create([]) } |
| 156 | ).toThrow(new Error("Missing parameters")); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 157 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 158 | var mi = KorAP.OwnMenuItem.create(["Baum"]); |
| 159 | expect(mi.element().firstChild.nodeValue).toEqual('Baum'); |
| 160 | expect(mi.lcField()).toEqual(' baum'); |
| 161 | }); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 162 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 163 | it('shouldn\'t have a reference to the menu', function () { |
| 164 | var menuItem = KorAP.OwnMenuItem.create(['Test']); |
| 165 | expect(menuItem.menu()).toBe(undefined); |
| 166 | }); |
| 167 | |
| 168 | it('should be activatable and deactivateable by class', function () { |
| 169 | var menuItem = KorAP.OwnMenuItem.create(['Test']); |
| 170 | |
| 171 | expect(menuItem.active()).toBe(false); |
| 172 | expect(menuItem.element().getAttribute("class")).toBe(null); |
| 173 | menuItem.active(true); |
| 174 | expect(menuItem.active()).toBe(true); |
| 175 | expect(menuItem.element().getAttribute("class")).toEqual("active"); |
| 176 | menuItem.active(false); // Is active |
| 177 | expect(menuItem.active()).toBe(false); |
| 178 | expect(menuItem.element().getAttribute("class")).toEqual(""); |
| 179 | menuItem.active(true); |
| 180 | expect(menuItem.active()).toBe(true); |
| 181 | expect(menuItem.element().getAttribute("class")).toEqual("active"); |
| 182 | |
| 183 | menuItem = KorAP.OwnMenuItem.create(['Spiegel']); |
| 184 | expect(menuItem.active()).toBe(false); |
| 185 | expect(menuItem.element().getAttribute("class")).toBe(null); |
| 186 | menuItem.active(false); // Is not active |
| 187 | expect(menuItem.active()).toBe(false); |
| 188 | expect(menuItem.element().getAttribute("class")).toBe(null); |
| 189 | }); |
| 190 | |
| 191 | it('should be set to boundary', function () { |
| 192 | var menuItem = KorAP.OwnMenuItem.create(['CoreNLP']); |
| 193 | expect(menuItem.active()).toBe(false); |
| 194 | expect(menuItem.element().getAttribute("class")).toBe(null); |
| 195 | |
| 196 | // Set active |
| 197 | menuItem.active(true); |
| 198 | expect(menuItem.active()).toBe(true); |
| 199 | expect(menuItem.noMore()).toBe(false); |
| 200 | expect(menuItem.element().getAttribute("class")).toEqual("active"); |
| 201 | |
| 202 | // Set no more |
| 203 | menuItem.noMore(true); |
| 204 | expect(menuItem.active()).toBe(true); |
| 205 | expect(menuItem.noMore()).toBe(true); |
| 206 | expect(menuItem.element().getAttribute("class")).toEqual("active no-more"); |
| 207 | |
| 208 | // No no more |
| 209 | menuItem.noMore(false); |
| 210 | expect(menuItem.active()).toBe(true); |
| 211 | expect(menuItem.noMore()).toBe(false); |
| 212 | expect(menuItem.element().getAttribute("class")).toEqual("active"); |
| 213 | |
| 214 | // Set no more, deactivate |
| 215 | menuItem.noMore(true); |
| 216 | menuItem.active(false); |
| 217 | expect(menuItem.active()).toBe(false); |
| 218 | expect(menuItem.noMore()).toBe(true); |
| 219 | expect(menuItem.element().getAttribute("class")).toEqual("no-more"); |
| 220 | |
| 221 | // Set active |
| 222 | menuItem.active(true); |
| 223 | expect(menuItem.active()).toBe(true); |
| 224 | expect(menuItem.noMore()).toBe(true); |
| 225 | expect(menuItem.element().getAttribute("class")).toEqual("no-more active"); |
| 226 | }); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 227 | |
| 228 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 229 | it('should be highlightable', function () { |
| 230 | // Highlight in the middle |
| 231 | var menuItem = KorAP.OwnMenuItem.create(['CoreNLP']); |
| 232 | menuItem.highlight("ren"); |
| 233 | expect(menuItem.element().innerHTML).toEqual("Co<mark>reN</mark>LP"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 234 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 235 | menuItem.lowlight(); |
| 236 | expect(menuItem.element().innerHTML).toEqual("CoreNLP"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 237 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 238 | var plain = "<div><h1>CoreNLP</h1><h2>corenlp/</h2></div>"; |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 239 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 240 | // Starting highlight |
| 241 | menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']); |
| 242 | menuItem.highlight("cor"); |
| 243 | expect(menuItem.element().innerHTML).toEqual("<div><h1><mark>Cor</mark>eNLP</h1><h2><mark>cor</mark>enlp/</h2></div>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 244 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 245 | menuItem.lowlight(); |
| 246 | expect(menuItem.element().innerHTML).toEqual(plain); |
Nils Diewald | 6e43ffd | 2015-03-25 18:55:39 +0000 | [diff] [blame] | 247 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 248 | // Starting highlight - short |
| 249 | menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']); |
| 250 | menuItem.highlight("c"); |
| 251 | expect(menuItem.element().innerHTML).toEqual("<div><h1><mark>C</mark>oreNLP</h1><h2><mark>c</mark>orenlp/</h2></div>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 252 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 253 | menuItem.lowlight(); |
| 254 | expect(menuItem.element().innerHTML).toEqual(plain); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 255 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 256 | // Highlight at the end |
| 257 | menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']); |
| 258 | menuItem.highlight("nlp"); |
| 259 | expect(menuItem.element().innerHTML).toEqual("<div><h1>Core<mark>NLP</mark></h1><h2>core<mark>nlp</mark>/</h2></div>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 260 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 261 | menuItem.lowlight(); |
| 262 | expect(menuItem.element().innerHTML).toEqual(plain); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 263 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 264 | // Highlight at the end - short |
| 265 | menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']); |
| 266 | menuItem.highlight("p"); |
| 267 | expect(menuItem.element().innerHTML).toEqual("<div><h1>CoreNL<mark>P</mark></h1><h2>corenl<mark>p</mark>/</h2></div>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 268 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 269 | menuItem.lowlight(); |
| 270 | expect(menuItem.element().innerHTML).toEqual(plain); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 271 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 272 | // No highlight |
| 273 | menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']); |
| 274 | menuItem.highlight("xp"); |
| 275 | expect(menuItem.element().innerHTML).toEqual(plain); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 276 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 277 | menuItem.lowlight(); |
| 278 | expect(menuItem.element().innerHTML).toEqual(plain); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 279 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 280 | // Highlight in the middle - first |
| 281 | menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']); |
| 282 | menuItem.highlight("ren"); |
| 283 | 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>"); |
| 284 | |
| 285 | plain = "<div><h1>CoreNLP</h1><h2>corenlp/</h2><h3>This is my Example</h3></div>" |
| 286 | |
| 287 | menuItem.lowlight(); |
| 288 | expect(menuItem.element().innerHTML).toEqual(plain); |
| 289 | |
| 290 | // Highlight in the middle - second |
| 291 | menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']); |
| 292 | menuItem.highlight("ampl"); |
| 293 | expect(menuItem.element().innerHTML).toEqual("<div><h1>CoreNLP</h1><h2>corenlp/</h2><h3>This is my Ex<mark>ampl</mark>e</h3></div>"); |
| 294 | |
| 295 | menuItem.lowlight(); |
| 296 | expect(menuItem.element().innerHTML).toEqual(plain); |
| 297 | |
| 298 | // Highlight in the middle - both |
| 299 | menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']); |
| 300 | menuItem.highlight("e"); |
| 301 | 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>"); |
| 302 | |
| 303 | menuItem.lowlight(); |
| 304 | expect(menuItem.element().innerHTML).toEqual(plain); |
| 305 | |
| 306 | // Highlight in the end - second |
| 307 | menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']); |
| 308 | menuItem.highlight("le"); |
| 309 | expect(menuItem.element().innerHTML).toEqual("<div><h1>CoreNLP</h1><h2>corenlp/</h2><h3>This is my Examp<mark>le</mark></h3></div>"); |
| 310 | |
| 311 | menuItem.lowlight(); |
| 312 | expect(menuItem.element().innerHTML).toEqual(plain); |
| 313 | |
| 314 | // Highlight at the beginning - second |
| 315 | menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']); |
| 316 | menuItem.highlight("this"); |
| 317 | expect(menuItem.element().innerHTML).toEqual("<div><h1>CoreNLP</h1><h2>corenlp/</h2><h3><mark>This</mark> is my Example</h3></div>"); |
| 318 | |
| 319 | menuItem.lowlight(); |
| 320 | expect(menuItem.element().innerHTML).toEqual(plain); |
| 321 | }); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 322 | }); |
| 323 | |
| 324 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 325 | describe('KorAP.Menu', function () { |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 326 | var list = [ |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 327 | ["Constituency", "c=", "Example 1"], |
| 328 | ["Lemma", "l="], |
| 329 | ["Morphology", "m=", "Example 2"], |
| 330 | ["Part-of-Speech", "p="], |
| 331 | ["Syntax", "syn="] |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 332 | ]; |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 333 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 334 | var demolist = [ |
| 335 | ['Titel', 'title'], |
| 336 | ['Untertitel', 'subTitle'], |
| 337 | ['Veröffentlichungsdatum', 'pubDate'], |
| 338 | ['Länge', 'length'], |
| 339 | ['Autor', 'author'] |
| 340 | ]; |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 341 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 342 | var demolonglist = [ |
| 343 | ['Titel', 'title'], |
| 344 | ['Untertitel', 'subTitle'], |
| 345 | ['Veröffentlichungsdatum', 'pubDate'], |
| 346 | ['Länge', 'length'], |
| 347 | ['Autor', 'author'], |
| 348 | ['Genre', 'genre'], |
| 349 | ['corpusID', 'corpusID'], |
| 350 | ['docID', 'docID'], |
| 351 | ['textID', 'textID'], |
| 352 | ]; |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 353 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 354 | it('should be initializable', function () { |
| 355 | var list = [ |
| 356 | ["Constituency"], |
| 357 | ["Lemma"], |
| 358 | ["Morphology"], |
| 359 | ["Part-of-Speech"], |
| 360 | ["Syntax"] |
| 361 | ]; |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 362 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 363 | var menu = KorAP.OwnMenu.create(list); |
Akron | c1457bf | 2015-06-11 19:24:00 +0200 | [diff] [blame] | 364 | menu._firstActive = true; |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 365 | expect(menu.itemClass()).toEqual(KorAP.OwnMenuItem); |
| 366 | expect(menu.element().nodeName).toEqual('UL'); |
| 367 | expect(menu.element().style.opacity).toEqual("0"); |
| 368 | expect(menu.limit()).toEqual(8); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 369 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 370 | menu.limit(9); |
| 371 | expect(menu.limit()).toEqual(9); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 372 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 373 | menu.limit(8); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 374 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 375 | // view |
| 376 | menu.show(); |
| 377 | |
| 378 | // First element in list |
| 379 | expect(menu.item(0).active()).toBe(true); |
| 380 | expect(menu.item(0).noMore()).toBe(true); |
| 381 | |
| 382 | // Middle element in list |
| 383 | expect(menu.item(2).active()).toBe(false); |
| 384 | expect(menu.item(2).noMore()).toBe(false); |
| 385 | |
| 386 | // Last element in list |
| 387 | expect(menu.item(menu.length() - 1).active()).toBe(false); |
| 388 | expect(menu.item(menu.length() - 1).noMore()).toBe(true); |
| 389 | }); |
| 390 | |
| 391 | it('should have a reference to the menu', function () { |
| 392 | var menu = KorAP.HintMenu.create("cnx/", list); |
| 393 | expect(menu.item(0).menu()).toEqual(menu); |
| 394 | |
| 395 | menu = KorAP.HintMenu.create("cnx/", list); |
| 396 | expect(menu.element().menu).toEqual(menu); |
| 397 | }); |
| 398 | |
| 399 | |
| 400 | it('should be visible', function () { |
| 401 | var menu = KorAP.HintMenu.create("cnx/", list); |
| 402 | expect(menu.delete()).toBe(undefined); |
| 403 | menu.limit(3); |
| 404 | |
| 405 | expect(menu.show()).toBe(true); |
| 406 | |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 407 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>"); |
| 408 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Lemma</strong>"); |
| 409 | expect(menu.element().childNodes[3].getAttribute("data-action")).toEqual("l="); |
| 410 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
| 411 | expect(menu.element().childNodes[5]).toBe(undefined); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 412 | |
| 413 | // Check boundaries |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 414 | expect(menu.element().childNodes[2].classList.contains("no-more")).toBe(true); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 415 | expect(menu.element().childNodes[3].classList.contains("no-more")).toBe(false); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 416 | expect(menu.element().childNodes[4].classList.contains("no-more")).toBe(false); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 417 | }); |
| 418 | |
| 419 | it('should be filterable', function () { |
| 420 | var menu = KorAP.HintMenu.create("cnx/", list); |
| 421 | menu.limit(3); |
| 422 | expect(menu.prefix("o").show()).toBe(true); |
| 423 | expect(menu.element().childNodes[0].innerHTML).toEqual("o"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 424 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>"); |
| 425 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>"); |
| 426 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>"); |
| 427 | expect(menu.element().childNodes[5]).toBe(undefined); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 428 | |
| 429 | // Check boundaries |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 430 | expect(menu.element().childNodes[2].classList.contains("no-more")).toBe(true); |
| 431 | expect(menu.element().childNodes[3].classList.contains("no-more")).toBe(false); |
| 432 | expect(menu.element().childNodes[4].classList.contains("no-more")).toBe(true); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 433 | |
| 434 | menu.limit(2); |
| 435 | |
| 436 | expect(menu.prefix("o").show()).toBe(true); |
| 437 | expect(menu.element().childNodes[0].innerHTML).toEqual("o"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 438 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>"); |
| 439 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>"); |
| 440 | expect(menu.element().childNodes[4]).toBe(undefined); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 441 | |
| 442 | // Check boundaries |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 443 | expect(menu.element().childNodes[2].classList.contains("no-more")).toBe(true); |
| 444 | expect(menu.element().childNodes[3].classList.contains("no-more")).toBe(false); |
| 445 | expect(menu.element().childNodes[4]).toBe(undefined); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 446 | |
| 447 | expect(menu.prefix("e").show()).toBe(true); |
| 448 | expect(menu.element().childNodes[0].innerHTML).toEqual("e"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 449 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>"); |
| 450 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>"); |
| 451 | expect(menu.element().childNodes[4]).toBe(undefined); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 452 | |
| 453 | menu.limit(5); |
| 454 | expect(menu.prefix("a").show()).toBe(true); |
| 455 | expect(menu.element().childNodes[0].innerHTML).toEqual("a"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 456 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Constituency</strong><span>Ex<mark>a</mark>mple 1</span>"); |
| 457 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Lemm<mark>a</mark></strong>"); |
| 458 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Morphology</strong><span>Ex<mark>a</mark>mple 2</span>"); |
| 459 | expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>P<mark>a</mark>rt-of-Speech</strong>"); |
| 460 | expect(menu.element().childNodes[6].innerHTML).toEqual("<strong>Synt<mark>a</mark>x</strong>"); |
| 461 | expect(menu.element().childNodes[7]).toBe(undefined); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 462 | }); |
| 463 | |
| 464 | |
| 465 | it('should be nextable', function () { |
| 466 | var menu = KorAP.HintMenu.create("cnx/", list); |
Akron | c1457bf | 2015-06-11 19:24:00 +0200 | [diff] [blame] | 467 | menu._firstActive = true; |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 468 | |
| 469 | // Show only 3 items |
| 470 | menu.limit(3); |
| 471 | expect(menu.show()).toBe(true); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 472 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 473 | expect(menu.shownItem(0).active()).toBe(true); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 474 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Lemma</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 475 | expect(menu.shownItem(1).active()).toBe(false); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 476 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 477 | expect(menu.shownItem(2).active()).toBe(false); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 478 | expect(menu.element().childNodes[5]).toBe(undefined); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 479 | |
| 480 | // Activate next (1) |
| 481 | menu.next(); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 482 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 483 | expect(menu.shownItem(0).active()).toBe(false); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 484 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Lemma</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 485 | expect(menu.shownItem(1).active()).toBe(true); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 486 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 487 | expect(menu.shownItem(2).active()).toBe(false); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 488 | expect(menu.element().childNodes[5]).toBe(undefined); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 489 | |
| 490 | // Activate next (2) |
| 491 | menu.next(); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 492 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 493 | expect(menu.shownItem(0).active()).toBe(false); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 494 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Lemma</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 495 | expect(menu.shownItem(1).active()).toBe(false); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 496 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 497 | expect(menu.shownItem(2).active()).toBe(true); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 498 | expect(menu.element().childNodes[5]).toBe(undefined); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 499 | |
| 500 | // Activate next (3) |
| 501 | // scroll! |
| 502 | menu.next(); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 503 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Lemma</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 504 | expect(menu.shownItem(0).active()).toBe(false); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 505 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 506 | expect(menu.shownItem(1).active()).toBe(false); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 507 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Part-of-Speech</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 508 | expect(menu.shownItem(2).active()).toBe(true); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 509 | expect(menu.element().childNodes[5]).toBe(undefined); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 510 | |
| 511 | // Activate next (4) |
| 512 | menu.next(); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 513 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 514 | expect(menu.shownItem(0).active()).toBe(false); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 515 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Part-of-Speech</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 516 | expect(menu.shownItem(1).active()).toBe(false); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 517 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Syntax</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 518 | expect(menu.shownItem(2).active()).toBe(true); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 519 | expect(menu.element().childNodes[5]).toBe(undefined); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 520 | |
| 521 | // Activate next (5) - ROLL |
| 522 | menu.next(); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 523 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 524 | expect(menu.shownItem(0).active()).toBe(true); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 525 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Lemma</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 526 | expect(menu.shownItem(1).active()).toBe(false); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 527 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 528 | expect(menu.shownItem(2).active()).toBe(false); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 529 | expect(menu.element().childNodes[5]).toBe(undefined); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 530 | |
| 531 | // Active next (6) |
| 532 | menu.next(); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 533 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 534 | expect(menu.shownItem(0).active()).toBe(false); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 535 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Lemma</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 536 | expect(menu.shownItem(1).active()).toBe(true); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 537 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 538 | expect(menu.shownItem(2).active()).toBe(false); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 539 | expect(menu.element().childNodes[5]).toBe(undefined); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 540 | }); |
| 541 | |
| 542 | it('should be prevable', function () { |
| 543 | var menu = KorAP.HintMenu.create("cnx/", list); |
Akron | c1457bf | 2015-06-11 19:24:00 +0200 | [diff] [blame] | 544 | menu._firstActive = true; |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 545 | menu.limit(3); |
| 546 | expect(menu.show()).toBe(true); |
| 547 | |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 548 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 549 | expect(menu.shownItem(0).active()).toBe(true); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 550 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Lemma</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 551 | expect(menu.shownItem(1).active()).toBe(false); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 552 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 553 | expect(menu.shownItem(2).active()).toBe(false); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 554 | expect(menu.element().childNodes[5]).toBe(undefined); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 555 | |
| 556 | // Activate prev (1) - roll to bottom |
| 557 | menu.prev(); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 558 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 559 | expect(menu.shownItem(0).active()).toBe(false); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 560 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Part-of-Speech</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 561 | expect(menu.shownItem(1).active()).toBe(false); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 562 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Syntax</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 563 | expect(menu.shownItem(2).active()).toBe(true); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 564 | expect(menu.element().childNodes[5]).toBe(undefined); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 565 | |
| 566 | // Activate prev (2) |
| 567 | menu.prev(); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 568 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 569 | expect(menu.shownItem(0).active()).toBe(false); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 570 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Part-of-Speech</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 571 | expect(menu.shownItem(1).active()).toBe(true); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 572 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Syntax</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 573 | expect(menu.shownItem(2).active()).toBe(false); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 574 | expect(menu.element().childNodes[5]).toBe(undefined); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 575 | |
| 576 | // Activate prev (3) |
| 577 | menu.prev(); |
| 578 | expect(menu.shownItem(0).name()).toEqual("Morphology"); |
| 579 | expect(menu.shownItem(0).active()).toBe(true); |
| 580 | expect(menu.shownItem(1).name()).toEqual("Part-of-Speech"); |
| 581 | expect(menu.shownItem(1).active()).toBe(false); |
| 582 | expect(menu.shownItem(2).name()).toEqual("Syntax"); |
| 583 | expect(menu.shownItem(2).active()).toBe(false); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 584 | expect(menu.element().childNodes[5]).toBe(undefined); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 585 | |
| 586 | // Activate prev (4) |
| 587 | menu.prev(); |
| 588 | expect(menu.shownItem(0).name()).toEqual("Lemma"); |
| 589 | expect(menu.shownItem(0).active()).toBe(true); |
| 590 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
| 591 | expect(menu.shownItem(1).active()).toBe(false); |
| 592 | expect(menu.shownItem(2).name()).toEqual("Part-of-Speech"); |
| 593 | expect(menu.shownItem(2).active()).toBe(false); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 594 | expect(menu.element().childNodes[5]).toBe(undefined); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 595 | |
| 596 | // Activate prev (5) |
| 597 | menu.prev(); |
| 598 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
| 599 | expect(menu.shownItem(0).active()).toBe(true); |
| 600 | expect(menu.shownItem(1).name()).toEqual("Lemma"); |
| 601 | expect(menu.shownItem(1).active()).toBe(false); |
| 602 | expect(menu.shownItem(2).name()).toEqual("Morphology"); |
| 603 | expect(menu.shownItem(2).active()).toBe(false); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 604 | expect(menu.element().childNodes[5]).toBe(undefined); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 605 | |
| 606 | // Activate next (1) |
| 607 | menu.next(); |
| 608 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
| 609 | expect(menu.shownItem(0).active()).toBe(false); |
| 610 | expect(menu.shownItem(1).name()).toEqual("Lemma"); |
| 611 | expect(menu.shownItem(1).active()).toBe(true); |
| 612 | expect(menu.shownItem(2).name()).toEqual("Morphology"); |
| 613 | expect(menu.shownItem(2).active()).toBe(false); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 614 | expect(menu.element().childNodes[5]).toBe(undefined); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 615 | |
| 616 | // Activate prev (6) |
| 617 | menu.prev(); |
| 618 | |
| 619 | // Activate prev (7) |
| 620 | menu.prev(); |
| 621 | expect(menu.shownItem(0).name()).toEqual("Morphology"); |
| 622 | expect(menu.shownItem(0).active()).toBe(false); |
| 623 | expect(menu.shownItem(1).name()).toEqual("Part-of-Speech"); |
| 624 | expect(menu.shownItem(1).active()).toBe(false); |
| 625 | expect(menu.shownItem(2).name()).toEqual("Syntax"); |
| 626 | expect(menu.shownItem(2).active()).toBe(true); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 627 | expect(menu.element().childNodes[5]).toBe(undefined); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 628 | }); |
| 629 | |
| 630 | |
| 631 | it('should be navigatable and filterable (prefix = "o")', function () { |
| 632 | var menu = KorAP.HintMenu.create("cnx/", list); |
Akron | c1457bf | 2015-06-11 19:24:00 +0200 | [diff] [blame] | 633 | menu._firstActive = true; |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 634 | menu.limit(2); |
| 635 | |
| 636 | expect(menu.prefix("o").show()).toBe(true); |
| 637 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 638 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 639 | expect(menu.shownItem(0).active()).toBe(true); |
| 640 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 641 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 642 | expect(menu.shownItem(1).active()).toBe(false); |
| 643 | expect(menu.shownItem(2)).toBe(undefined); |
| 644 | |
| 645 | // Next (1) |
| 646 | menu.next(); |
| 647 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 648 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 649 | expect(menu.shownItem(0).active()).toBe(false); |
| 650 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 651 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 652 | expect(menu.shownItem(1).active()).toBe(true); |
| 653 | expect(menu.shownItem(2)).toBe(undefined); |
| 654 | |
| 655 | // Next (2) |
| 656 | menu.next(); |
| 657 | expect(menu.shownItem(0).name()).toEqual("Morphology"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 658 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 659 | expect(menu.shownItem(0).active()).toBe(false); |
| 660 | expect(menu.shownItem(1).name()).toEqual("Part-of-Speech"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 661 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 662 | expect(menu.shownItem(1).active()).toBe(true); |
| 663 | expect(menu.shownItem(2)).toBe(undefined); |
| 664 | |
| 665 | // Next (3) - to prefix |
| 666 | menu.next(); |
| 667 | expect(menu.shownItem(0).name()).toEqual("Morphology"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 668 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 669 | expect(menu.shownItem(0).active()).toBe(false); |
| 670 | expect(menu.shownItem(1).name()).toEqual("Part-of-Speech"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 671 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 672 | expect(menu.shownItem(1).active()).toBe(false); |
| 673 | expect(menu.shownItem(2)).toBe(undefined); |
| 674 | |
| 675 | menu.next(); |
| 676 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 677 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 678 | expect(menu.shownItem(0).active()).toBe(true); |
| 679 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 680 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 681 | expect(menu.shownItem(1).active()).toBe(false); |
| 682 | expect(menu.shownItem(2)).toBe(undefined); |
| 683 | }); |
| 684 | |
| 685 | |
| 686 | it('should be navigatable and filterable (prefix = "ex", "e")', function () { |
| 687 | var menu = KorAP.HintMenu.create("cnx/", list); |
Akron | c1457bf | 2015-06-11 19:24:00 +0200 | [diff] [blame] | 688 | menu._firstActive = true; |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 689 | |
| 690 | menu.limit(2); |
| 691 | expect(menu.prefix("ex").show()).toBe(true); |
| 692 | |
| 693 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 694 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Constituency</strong><span><mark>Ex</mark>ample 1</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 695 | expect(menu.shownItem(0).active()).toBe(true); |
| 696 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 697 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span><mark>Ex</mark>ample 2</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 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"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 704 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Constituency</strong><span><mark>Ex</mark>ample 1</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 705 | expect(menu.shownItem(0).active()).toBe(false); |
| 706 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 707 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span><mark>Ex</mark>ample 2</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 708 | expect(menu.shownItem(1).active()).toBe(true); |
| 709 | expect(menu.shownItem(2)).toBe(undefined); |
| 710 | |
| 711 | // Next (2) |
| 712 | menu.next(); |
| 713 | |
| 714 | expect(menu.prefix()).toEqual('ex'); |
| 715 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 716 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Constituency</strong><span><mark>Ex</mark>ample 1</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 717 | expect(menu.shownItem(0).active()).toBe(false); |
| 718 | |
| 719 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 720 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span><mark>Ex</mark>ample 2</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 721 | expect(menu.shownItem(1).active()).toBe(false); |
| 722 | expect(menu.shownItem(2)).toBe(undefined); |
| 723 | |
| 724 | // Reset limit |
| 725 | menu.limit(5); |
| 726 | |
| 727 | // Change show |
| 728 | expect(menu.prefix("e").show()).toBe(true); |
| 729 | expect(menu._prefix.active()).toBe(false); |
| 730 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 731 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 732 | expect(menu.shownItem(0).active()).toBe(true); |
| 733 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 734 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 735 | expect(menu.shownItem(1).active()).toBe(false); |
| 736 | expect(menu.shownItem(2)).toBe(undefined); |
| 737 | |
| 738 | // Next (1) |
| 739 | menu.next(); |
| 740 | expect(menu._prefix.active()).toBe(false); |
| 741 | expect(menu.prefix()).toEqual('e'); |
| 742 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 743 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 744 | expect(menu.shownItem(0).active()).toBe(false); |
| 745 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 746 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 747 | expect(menu.shownItem(1).active()).toBe(true); |
| 748 | expect(menu.shownItem(2)).toBe(undefined); |
| 749 | |
| 750 | // Next (2) |
| 751 | menu.next(); |
| 752 | expect(menu._prefix.active()).toBe(true); |
| 753 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 754 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 755 | expect(menu.shownItem(0).active()).toBe(false); |
| 756 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 757 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 758 | expect(menu.shownItem(1).active()).toBe(false); |
| 759 | expect(menu.shownItem(2)).toBe(undefined); |
| 760 | |
| 761 | // Next (3) |
| 762 | menu.next(); |
| 763 | expect(menu._prefix.active()).toBe(false); |
| 764 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 765 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 766 | expect(menu.shownItem(0).active()).toBe(true); |
| 767 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 768 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 769 | expect(menu.shownItem(1).active()).toBe(false); |
| 770 | expect(menu.shownItem(2)).toBe(undefined); |
| 771 | }); |
| 772 | |
| 773 | |
| 774 | it('shouldn\'t be viewable with failing prefix', function () { |
| 775 | var menu = KorAP.HintMenu.create("cnx/", list); |
| 776 | menu.limit(2); |
| 777 | expect(menu.prefix("exit").show()).toBe(false); |
| 778 | }); |
| 779 | |
Akron | 37513a6 | 2015-11-17 01:07:11 +0100 | [diff] [blame] | 780 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 781 | it('should be navigatable with prefix', function () { |
| 782 | var menu = KorAP.HintMenu.create("cnx/", demolist); |
Akron | c1457bf | 2015-06-11 19:24:00 +0200 | [diff] [blame] | 783 | menu._firstActive = true; |
| 784 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 785 | menu.limit(3); |
| 786 | |
| 787 | expect(menu.show()).toBe(true); |
| 788 | expect(menu.prefix()).toEqual(""); |
| 789 | |
| 790 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 791 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Titel</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 792 | expect(menu.shownItem(0).active()).toBe(true); |
| 793 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 794 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Untertitel</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 795 | expect(menu.shownItem(1).active()).toBe(false); |
| 796 | expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 797 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 798 | expect(menu.shownItem(2).active()).toBe(false); |
| 799 | expect(menu.shownItem(3)).toBe(undefined); |
| 800 | |
| 801 | menu._prefix.add('a'); |
| 802 | expect(menu.show()).toBe(true); |
| 803 | expect(menu.prefix()).toEqual("a"); |
| 804 | expect(menu.shownItem(0).name()).toEqual("Autor"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 805 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong><mark>A</mark>utor</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 806 | |
| 807 | menu._prefix.add('u'); |
| 808 | expect(menu.show()).toBe(true); |
| 809 | expect(menu.prefix()).toEqual("au"); |
| 810 | expect(menu.shownItem(0).name()).toEqual("Autor"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 811 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong><mark>Au</mark>tor</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 812 | |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 813 | menu._prefix.chop(); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 814 | expect(menu.show()).toBe(true); |
| 815 | expect(menu.prefix()).toEqual("a"); |
| 816 | expect(menu.shownItem(0).name()).toEqual("Autor"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 817 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong><mark>A</mark>utor</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 818 | |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 819 | menu._prefix.chop(); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 820 | expect(menu.show()).toBe(true); |
| 821 | expect(menu.prefix()).toEqual(""); |
| 822 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 823 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Titel</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 824 | expect(menu.shownItem(0).active()).toBe(true); |
| 825 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 826 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Untertitel</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 827 | expect(menu.shownItem(1).active()).toBe(false); |
| 828 | expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 829 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 830 | expect(menu.shownItem(2).active()).toBe(false); |
| 831 | expect(menu.shownItem(3)).toBe(undefined); |
| 832 | |
| 833 | // Forward |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 834 | menu._prefix.chop(); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 835 | expect(menu.show()).toBe(true); |
| 836 | expect(menu.prefix()).toEqual(""); |
| 837 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 838 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Titel</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 839 | expect(menu.shownItem(0).active()).toBe(true); |
| 840 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 841 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Untertitel</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 842 | expect(menu.shownItem(1).active()).toBe(false); |
| 843 | expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 844 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 845 | expect(menu.shownItem(2).active()).toBe(false); |
| 846 | |
| 847 | // Forward |
| 848 | menu.next(); |
| 849 | expect(menu.prefix()).toEqual(""); |
| 850 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 851 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Titel</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 852 | expect(menu.shownItem(0).active()).toBe(false); |
| 853 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 854 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Untertitel</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 855 | expect(menu.shownItem(1).active()).toBe(true); |
| 856 | expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 857 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 858 | expect(menu.shownItem(2).active()).toBe(false); |
| 859 | expect(menu.shownItem(3)).toBe(undefined); |
| 860 | |
| 861 | // Forward |
| 862 | menu.next(); |
| 863 | expect(menu.prefix()).toEqual(""); |
| 864 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 865 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Titel</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 866 | expect(menu.shownItem(0).active()).toBe(false); |
| 867 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 868 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Untertitel</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 869 | expect(menu.shownItem(1).active()).toBe(false); |
| 870 | expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 871 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 872 | expect(menu.shownItem(2).active()).toBe(true); |
| 873 | expect(menu.shownItem(3)).toBe(undefined); |
| 874 | |
| 875 | // Forward |
| 876 | menu.next(); |
| 877 | expect(menu.prefix()).toEqual(""); |
| 878 | expect(menu.shownItem(0).name()).toEqual("Untertitel"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 879 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertitel</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 880 | expect(menu.shownItem(0).active()).toBe(false); |
| 881 | expect(menu.shownItem(1).name()).toEqual("Veröffentlichungsdatum"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 882 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 883 | expect(menu.shownItem(1).active()).toBe(false); |
| 884 | expect(menu.shownItem(2).name()).toEqual("Länge"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 885 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Länge</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 886 | expect(menu.shownItem(2).active()).toBe(true); |
| 887 | expect(menu.shownItem(3)).toBe(undefined); |
| 888 | |
| 889 | // Forward |
| 890 | menu.next(); |
| 891 | expect(menu.prefix()).toEqual(""); |
| 892 | expect(menu.shownItem(0).name()).toEqual("Veröffentlichungsdatum"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 893 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 894 | expect(menu.shownItem(0).active()).toBe(false); |
| 895 | expect(menu.shownItem(1).name()).toEqual("Länge"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 896 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Länge</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 897 | expect(menu.shownItem(1).active()).toBe(false); |
| 898 | expect(menu.shownItem(2).name()).toEqual("Autor"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 899 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Autor</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 900 | expect(menu.shownItem(2).active()).toBe(true); |
| 901 | expect(menu.shownItem(3)).toBe(undefined); |
| 902 | |
| 903 | // Forward |
| 904 | menu.next(); |
| 905 | expect(menu.prefix()).toEqual(""); |
| 906 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 907 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Titel</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 908 | expect(menu.shownItem(0).active()).toBe(true); |
| 909 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 910 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Untertitel</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 911 | expect(menu.shownItem(1).active()).toBe(false); |
| 912 | expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 913 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 914 | expect(menu.shownItem(2).active()).toBe(false); |
| 915 | }); |
| 916 | |
| 917 | |
| 918 | it('should be navigatable with a prefix (1)', function () { |
| 919 | var menu = KorAP.HintMenu.create("cnx/", demolist); |
Akron | c1457bf | 2015-06-11 19:24:00 +0200 | [diff] [blame] | 920 | menu._firstActive = true; |
| 921 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 922 | menu.limit(3); |
| 923 | |
| 924 | expect(menu.show()).toBe(true); |
| 925 | expect(menu.prefix()).toEqual(""); |
| 926 | |
| 927 | menu.prefix('el'); |
| 928 | expect(menu.show()).toBe(true); |
| 929 | |
| 930 | expect(menu.prefix()).toEqual("el"); |
| 931 | expect(menu._prefix.active()).toEqual(false); |
| 932 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 933 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 934 | expect(menu.shownItem(0).active()).toBe(true); |
| 935 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 936 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 937 | expect(menu.shownItem(1).active()).toBe(false); |
| 938 | expect(menu.shownItem(2)).toBe(undefined); |
| 939 | |
| 940 | // Forward |
| 941 | menu.next(); |
| 942 | expect(menu.prefix()).toEqual("el"); |
| 943 | expect(menu._prefix.active()).toEqual(false); |
| 944 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 945 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 946 | expect(menu.shownItem(0).active()).toBe(false); |
| 947 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 948 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 949 | expect(menu.shownItem(1).active()).toBe(true); |
| 950 | expect(menu.shownItem(2)).toBe(undefined); |
| 951 | |
| 952 | // Forward |
| 953 | menu.next(); |
| 954 | expect(menu.prefix()).toEqual("el"); |
| 955 | expect(menu._prefix.active()).toEqual(true); |
| 956 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 957 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 958 | expect(menu.shownItem(0).active()).toBe(false); |
| 959 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 960 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 961 | expect(menu.shownItem(1).active()).toBe(false); |
| 962 | expect(menu.shownItem(2)).toBe(undefined); |
| 963 | |
| 964 | // Backward |
| 965 | menu.prev(); |
| 966 | expect(menu.prefix()).toEqual("el"); |
| 967 | expect(menu._prefix.active()).toEqual(false); |
| 968 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 969 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 970 | expect(menu.shownItem(0).active()).toBe(false); |
| 971 | |
| 972 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 973 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 974 | expect(menu.shownItem(1).active()).toBe(true); |
| 975 | expect(menu.shownItem(2)).toBe(undefined); |
| 976 | }); |
| 977 | |
| 978 | |
| 979 | it('should be navigatable with a prefix (2)', function () { |
| 980 | var menu = KorAP.HintMenu.create("cnx/", demolist); |
Akron | c1457bf | 2015-06-11 19:24:00 +0200 | [diff] [blame] | 981 | menu._firstActive = true; |
| 982 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 983 | menu.limit(3); |
| 984 | expect(menu.show()).toBe(true); |
| 985 | expect(menu.prefix()).toEqual(""); |
| 986 | menu.prefix('el'); |
| 987 | expect(menu.show()).toBe(true); |
| 988 | |
| 989 | expect(menu.prefix()).toEqual("el"); |
| 990 | expect(menu._prefix.active()).toEqual(false); |
| 991 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 992 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 993 | expect(menu.shownItem(0).active()).toBe(true); |
| 994 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 995 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 996 | expect(menu.shownItem(1).active()).toBe(false); |
| 997 | expect(menu.shownItem(2)).toBe(undefined); |
| 998 | |
| 999 | // Backward |
| 1000 | menu.prev(); |
| 1001 | expect(menu._prefix.active()).toEqual(true); |
| 1002 | |
| 1003 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 1004 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1005 | expect(menu.shownItem(0).active()).toBe(false); |
| 1006 | |
| 1007 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 1008 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1009 | expect(menu.shownItem(1).active()).toBe(false); |
| 1010 | expect(menu.shownItem(2)).toBe(undefined); |
| 1011 | |
| 1012 | // Backward |
| 1013 | menu.prev(); |
| 1014 | expect(menu._prefix.active()).toEqual(false); |
| 1015 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 1016 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1017 | expect(menu.shownItem(0).active()).toBe(false); |
| 1018 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 1019 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1020 | expect(menu.shownItem(1).active()).toBe(true); |
| 1021 | expect(menu.shownItem(2)).toBe(undefined); |
| 1022 | }); |
| 1023 | |
| 1024 | it('should be navigatable with a prefix (3)', function () { |
| 1025 | var menu = KorAP.HintMenu.create("cnx/", demolist); |
Akron | c1457bf | 2015-06-11 19:24:00 +0200 | [diff] [blame] | 1026 | menu._firstActive = true; |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1027 | menu.limit(3); |
| 1028 | expect(menu.show()).toBe(true); |
| 1029 | expect(menu.prefix()).toEqual(""); |
| 1030 | menu.prefix('el'); |
| 1031 | expect(menu.show()).toBe(true); |
| 1032 | |
| 1033 | expect(menu.prefix()).toEqual("el"); |
| 1034 | expect(menu._prefix.active()).toEqual(false); |
| 1035 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 1036 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1037 | expect(menu.shownItem(0).active()).toBe(true); |
| 1038 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 1039 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1040 | expect(menu.shownItem(1).active()).toBe(false); |
| 1041 | expect(menu.shownItem(2)).toBe(undefined); |
| 1042 | |
| 1043 | // Backward |
| 1044 | menu.prev(); |
| 1045 | expect(menu._prefix.active()).toEqual(true); |
| 1046 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 1047 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1048 | expect(menu.shownItem(0).active()).toBe(false); |
| 1049 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 1050 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1051 | expect(menu.shownItem(1).active()).toBe(false); |
| 1052 | expect(menu.shownItem(2)).toBe(undefined); |
| 1053 | |
| 1054 | |
| 1055 | // Forward |
| 1056 | menu.next(); |
| 1057 | expect(menu.prefix()).toEqual("el"); |
| 1058 | expect(menu._prefix.active()).toEqual(false); |
| 1059 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 1060 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1061 | expect(menu.shownItem(0).active()).toBe(true); |
| 1062 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 1063 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1064 | expect(menu.shownItem(1).active()).toBe(false); |
| 1065 | expect(menu.shownItem(2)).toBe(undefined); |
| 1066 | |
| 1067 | }); |
| 1068 | |
| 1069 | xit('should be page downable'); |
| 1070 | xit('should be page upable'); |
| 1071 | |
Akron | 37513a6 | 2015-11-17 01:07:11 +0100 | [diff] [blame] | 1072 | it('should scroll to a chosen value', function () { |
| 1073 | var menu = KorAP.OwnMenu.create(demolist); |
| 1074 | menu.limit(3); |
| 1075 | this._active = 5; |
| 1076 | }); |
| 1077 | |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 1078 | xit('should highlight a chosen value'); |
| 1079 | }); |
| 1080 | |
| 1081 | describe('KorAP.Prefix', function () { |
| 1082 | it('should be initializable', function () { |
| 1083 | var p = prefixClass.create(); |
| 1084 | expect(p.element().classList.contains('pref')).toBeTruthy(); |
| 1085 | expect(p.isSet()).not.toBeTruthy(); |
| 1086 | |
| 1087 | /* |
| 1088 | expect(mi.lcField()).toEqual(' baum'); |
| 1089 | */ |
| 1090 | |
| 1091 | }); |
| 1092 | |
| 1093 | it('should be modifiable', function () { |
| 1094 | var p = prefixClass.create(); |
| 1095 | expect(p.value()).toEqual(''); |
| 1096 | expect(p.element().firstChild).toBeNull(); |
| 1097 | |
| 1098 | // Set string |
| 1099 | expect(p.value('Test')).toEqual('Test'); |
| 1100 | expect(p.value()).toEqual('Test'); |
| 1101 | expect(p.element().firstChild.nodeValue).toEqual('Test'); |
| 1102 | |
| 1103 | // Add string |
| 1104 | expect(p.add('ified')).toEqual('Testified'); |
| 1105 | expect(p.value()).toEqual('Testified'); |
| 1106 | expect(p.element().firstChild.nodeValue).toEqual('Testified'); |
| 1107 | |
| 1108 | // Clear string |
| 1109 | p.clear(); |
| 1110 | expect(p.value()).toEqual(''); |
| 1111 | expect(p.element().firstChild).toBeNull(); |
| 1112 | |
| 1113 | // Set string |
| 1114 | expect(p.value('Test')).toEqual('Test'); |
| 1115 | expect(p.value()).toEqual('Test'); |
| 1116 | expect(p.element().firstChild.nodeValue).toEqual('Test'); |
| 1117 | |
| 1118 | expect(p.chop()).toEqual('Tes'); |
| 1119 | expect(p.value()).toEqual('Tes'); |
| 1120 | expect(p.element().firstChild.nodeValue).toEqual('Tes'); |
| 1121 | |
| 1122 | expect(p.chop()).toEqual('Te'); |
| 1123 | expect(p.value()).toEqual('Te'); |
| 1124 | expect(p.element().firstChild.nodeValue).toEqual('Te'); |
| 1125 | |
| 1126 | expect(p.chop()).toEqual('T'); |
| 1127 | expect(p.value()).toEqual('T'); |
| 1128 | expect(p.element().firstChild.nodeValue).toEqual('T'); |
| 1129 | |
| 1130 | expect(p.chop()).toEqual(''); |
| 1131 | expect(p.value()).toEqual(''); |
| 1132 | expect(p.element().firstChild).toBeNull(); |
| 1133 | }); |
| 1134 | |
| 1135 | it('should be activatable', function () { |
| 1136 | var p = prefixClass.create(); |
| 1137 | expect(p.value()).toEqual(''); |
| 1138 | expect(p.element().firstChild).toBeNull(); |
| 1139 | |
| 1140 | expect(p.value('Test')).toEqual('Test'); |
| 1141 | expect(p.element().firstChild.nodeValue).toEqual('Test'); |
| 1142 | |
| 1143 | expect(p.active()).not.toBeTruthy(); |
| 1144 | expect(p.element().classList.contains('active')).not.toBeTruthy(); |
| 1145 | |
| 1146 | p.active(true); |
| 1147 | expect(p.active()).toBeTruthy(); |
| 1148 | expect(p.element().classList.contains('active')).toBeTruthy(); |
| 1149 | }); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 1150 | }); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 1151 | |
| 1152 | describe('KorAP.LengthField', function () { |
| 1153 | it('should be initializable', function () { |
| 1154 | var l = lengthFieldClass.create(); |
| 1155 | expect(l.element().classList.contains('lengthField')).toBeTruthy(); |
| 1156 | expect(l.element().children.length).toEqual(0); |
| 1157 | }); |
| 1158 | |
| 1159 | it('should be extensible', function () { |
| 1160 | var l = lengthFieldClass.create(); |
| 1161 | l.add('Baum'); |
| 1162 | expect(l.element().children.length).toEqual(1); |
| 1163 | expect(l.element().children[0].nodeName).toEqual('SPAN'); |
| 1164 | expect(l.element().children[0].textContent).toEqual('Baum-'); |
| 1165 | l.add('Fragezeichen'); |
| 1166 | expect(l.element().children.length).toEqual(2); |
| 1167 | expect(l.element().children[1].nodeName).toEqual('SPAN'); |
| 1168 | expect(l.element().children[1].textContent).toEqual('Fragezeichen-'); |
| 1169 | }); |
| 1170 | |
| 1171 | it('should be correctly initializable', function () { |
| 1172 | var list = [ |
| 1173 | ["Constituency"], |
| 1174 | ["Lemma"], |
| 1175 | ["Morphology"], |
| 1176 | ["Part-of-Speech"], |
| 1177 | ["Syntax"] |
| 1178 | ]; |
| 1179 | |
| 1180 | var menu = KorAP.OwnMenu.create(list); |
| 1181 | |
| 1182 | expect(menu.lengthField().element().children.length).toEqual(5); |
| 1183 | }); |
| 1184 | }); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 1185 | }); |