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