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