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 | |
| 779 | it('should be navigatable with prefix', function () { |
| 780 | var menu = KorAP.HintMenu.create("cnx/", demolist); |
Akron | c1457bf | 2015-06-11 19:24:00 +0200 | [diff] [blame^] | 781 | menu._firstActive = true; |
| 782 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 783 | menu.limit(3); |
| 784 | |
| 785 | expect(menu.show()).toBe(true); |
| 786 | expect(menu.prefix()).toEqual(""); |
| 787 | |
| 788 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
| 789 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Titel</strong>"); |
| 790 | expect(menu.shownItem(0).active()).toBe(true); |
| 791 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
| 792 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertitel</strong>"); |
| 793 | expect(menu.shownItem(1).active()).toBe(false); |
| 794 | expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum"); |
| 795 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>"); |
| 796 | expect(menu.shownItem(2).active()).toBe(false); |
| 797 | expect(menu.shownItem(3)).toBe(undefined); |
| 798 | |
| 799 | menu._prefix.add('a'); |
| 800 | expect(menu.show()).toBe(true); |
| 801 | expect(menu.prefix()).toEqual("a"); |
| 802 | expect(menu.shownItem(0).name()).toEqual("Autor"); |
| 803 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong><mark>A</mark>utor</strong>"); |
| 804 | |
| 805 | menu._prefix.add('u'); |
| 806 | expect(menu.show()).toBe(true); |
| 807 | expect(menu.prefix()).toEqual("au"); |
| 808 | expect(menu.shownItem(0).name()).toEqual("Autor"); |
| 809 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong><mark>Au</mark>tor</strong>"); |
| 810 | |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 811 | menu._prefix.chop(); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 812 | expect(menu.show()).toBe(true); |
| 813 | expect(menu.prefix()).toEqual("a"); |
| 814 | expect(menu.shownItem(0).name()).toEqual("Autor"); |
| 815 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong><mark>A</mark>utor</strong>"); |
| 816 | |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 817 | menu._prefix.chop(); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 818 | expect(menu.show()).toBe(true); |
| 819 | expect(menu.prefix()).toEqual(""); |
| 820 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
| 821 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Titel</strong>"); |
| 822 | expect(menu.shownItem(0).active()).toBe(true); |
| 823 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
| 824 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertitel</strong>"); |
| 825 | expect(menu.shownItem(1).active()).toBe(false); |
| 826 | expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum"); |
| 827 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>"); |
| 828 | expect(menu.shownItem(2).active()).toBe(false); |
| 829 | expect(menu.shownItem(3)).toBe(undefined); |
| 830 | |
| 831 | // Forward |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 832 | menu._prefix.chop(); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 833 | expect(menu.show()).toBe(true); |
| 834 | expect(menu.prefix()).toEqual(""); |
| 835 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
| 836 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Titel</strong>"); |
| 837 | expect(menu.shownItem(0).active()).toBe(true); |
| 838 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
| 839 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertitel</strong>"); |
| 840 | expect(menu.shownItem(1).active()).toBe(false); |
| 841 | expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum"); |
| 842 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>"); |
| 843 | expect(menu.shownItem(2).active()).toBe(false); |
| 844 | |
| 845 | // Forward |
| 846 | menu.next(); |
| 847 | expect(menu.prefix()).toEqual(""); |
| 848 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
| 849 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Titel</strong>"); |
| 850 | expect(menu.shownItem(0).active()).toBe(false); |
| 851 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
| 852 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertitel</strong>"); |
| 853 | expect(menu.shownItem(1).active()).toBe(true); |
| 854 | expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum"); |
| 855 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>"); |
| 856 | expect(menu.shownItem(2).active()).toBe(false); |
| 857 | expect(menu.shownItem(3)).toBe(undefined); |
| 858 | |
| 859 | // Forward |
| 860 | menu.next(); |
| 861 | expect(menu.prefix()).toEqual(""); |
| 862 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
| 863 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Titel</strong>"); |
| 864 | expect(menu.shownItem(0).active()).toBe(false); |
| 865 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
| 866 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertitel</strong>"); |
| 867 | expect(menu.shownItem(1).active()).toBe(false); |
| 868 | expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum"); |
| 869 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>"); |
| 870 | expect(menu.shownItem(2).active()).toBe(true); |
| 871 | expect(menu.shownItem(3)).toBe(undefined); |
| 872 | |
| 873 | // Forward |
| 874 | menu.next(); |
| 875 | expect(menu.prefix()).toEqual(""); |
| 876 | expect(menu.shownItem(0).name()).toEqual("Untertitel"); |
| 877 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Untertitel</strong>"); |
| 878 | expect(menu.shownItem(0).active()).toBe(false); |
| 879 | expect(menu.shownItem(1).name()).toEqual("Veröffentlichungsdatum"); |
| 880 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>"); |
| 881 | expect(menu.shownItem(1).active()).toBe(false); |
| 882 | expect(menu.shownItem(2).name()).toEqual("Länge"); |
| 883 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Länge</strong>"); |
| 884 | expect(menu.shownItem(2).active()).toBe(true); |
| 885 | expect(menu.shownItem(3)).toBe(undefined); |
| 886 | |
| 887 | // Forward |
| 888 | menu.next(); |
| 889 | expect(menu.prefix()).toEqual(""); |
| 890 | expect(menu.shownItem(0).name()).toEqual("Veröffentlichungsdatum"); |
| 891 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>"); |
| 892 | expect(menu.shownItem(0).active()).toBe(false); |
| 893 | expect(menu.shownItem(1).name()).toEqual("Länge"); |
| 894 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Länge</strong>"); |
| 895 | expect(menu.shownItem(1).active()).toBe(false); |
| 896 | expect(menu.shownItem(2).name()).toEqual("Autor"); |
| 897 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Autor</strong>"); |
| 898 | expect(menu.shownItem(2).active()).toBe(true); |
| 899 | expect(menu.shownItem(3)).toBe(undefined); |
| 900 | |
| 901 | // Forward |
| 902 | menu.next(); |
| 903 | expect(menu.prefix()).toEqual(""); |
| 904 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
| 905 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Titel</strong>"); |
| 906 | expect(menu.shownItem(0).active()).toBe(true); |
| 907 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
| 908 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertitel</strong>"); |
| 909 | expect(menu.shownItem(1).active()).toBe(false); |
| 910 | expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum"); |
| 911 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>"); |
| 912 | expect(menu.shownItem(2).active()).toBe(false); |
| 913 | }); |
| 914 | |
| 915 | |
| 916 | it('should be navigatable with a prefix (1)', function () { |
| 917 | var menu = KorAP.HintMenu.create("cnx/", demolist); |
Akron | c1457bf | 2015-06-11 19:24:00 +0200 | [diff] [blame^] | 918 | menu._firstActive = true; |
| 919 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 920 | menu.limit(3); |
| 921 | |
| 922 | expect(menu.show()).toBe(true); |
| 923 | expect(menu.prefix()).toEqual(""); |
| 924 | |
| 925 | menu.prefix('el'); |
| 926 | expect(menu.show()).toBe(true); |
| 927 | |
| 928 | expect(menu.prefix()).toEqual("el"); |
| 929 | expect(menu._prefix.active()).toEqual(false); |
| 930 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
| 931 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
| 932 | expect(menu.shownItem(0).active()).toBe(true); |
| 933 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
| 934 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
| 935 | expect(menu.shownItem(1).active()).toBe(false); |
| 936 | expect(menu.shownItem(2)).toBe(undefined); |
| 937 | |
| 938 | // Forward |
| 939 | menu.next(); |
| 940 | expect(menu.prefix()).toEqual("el"); |
| 941 | expect(menu._prefix.active()).toEqual(false); |
| 942 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
| 943 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
| 944 | expect(menu.shownItem(0).active()).toBe(false); |
| 945 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
| 946 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
| 947 | expect(menu.shownItem(1).active()).toBe(true); |
| 948 | expect(menu.shownItem(2)).toBe(undefined); |
| 949 | |
| 950 | // Forward |
| 951 | menu.next(); |
| 952 | expect(menu.prefix()).toEqual("el"); |
| 953 | expect(menu._prefix.active()).toEqual(true); |
| 954 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
| 955 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
| 956 | expect(menu.shownItem(0).active()).toBe(false); |
| 957 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
| 958 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
| 959 | expect(menu.shownItem(1).active()).toBe(false); |
| 960 | expect(menu.shownItem(2)).toBe(undefined); |
| 961 | |
| 962 | // Backward |
| 963 | menu.prev(); |
| 964 | expect(menu.prefix()).toEqual("el"); |
| 965 | expect(menu._prefix.active()).toEqual(false); |
| 966 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
| 967 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
| 968 | expect(menu.shownItem(0).active()).toBe(false); |
| 969 | |
| 970 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
| 971 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
| 972 | expect(menu.shownItem(1).active()).toBe(true); |
| 973 | expect(menu.shownItem(2)).toBe(undefined); |
| 974 | }); |
| 975 | |
| 976 | |
| 977 | it('should be navigatable with a prefix (2)', function () { |
| 978 | var menu = KorAP.HintMenu.create("cnx/", demolist); |
Akron | c1457bf | 2015-06-11 19:24:00 +0200 | [diff] [blame^] | 979 | menu._firstActive = true; |
| 980 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 981 | menu.limit(3); |
| 982 | expect(menu.show()).toBe(true); |
| 983 | expect(menu.prefix()).toEqual(""); |
| 984 | menu.prefix('el'); |
| 985 | expect(menu.show()).toBe(true); |
| 986 | |
| 987 | expect(menu.prefix()).toEqual("el"); |
| 988 | expect(menu._prefix.active()).toEqual(false); |
| 989 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
| 990 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
| 991 | expect(menu.shownItem(0).active()).toBe(true); |
| 992 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
| 993 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
| 994 | expect(menu.shownItem(1).active()).toBe(false); |
| 995 | expect(menu.shownItem(2)).toBe(undefined); |
| 996 | |
| 997 | // Backward |
| 998 | menu.prev(); |
| 999 | expect(menu._prefix.active()).toEqual(true); |
| 1000 | |
| 1001 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
| 1002 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
| 1003 | expect(menu.shownItem(0).active()).toBe(false); |
| 1004 | |
| 1005 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
| 1006 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
| 1007 | expect(menu.shownItem(1).active()).toBe(false); |
| 1008 | expect(menu.shownItem(2)).toBe(undefined); |
| 1009 | |
| 1010 | // Backward |
| 1011 | menu.prev(); |
| 1012 | expect(menu._prefix.active()).toEqual(false); |
| 1013 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
| 1014 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
| 1015 | expect(menu.shownItem(0).active()).toBe(false); |
| 1016 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
| 1017 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
| 1018 | expect(menu.shownItem(1).active()).toBe(true); |
| 1019 | expect(menu.shownItem(2)).toBe(undefined); |
| 1020 | }); |
| 1021 | |
| 1022 | it('should be navigatable with a prefix (3)', function () { |
| 1023 | var menu = KorAP.HintMenu.create("cnx/", demolist); |
Akron | c1457bf | 2015-06-11 19:24:00 +0200 | [diff] [blame^] | 1024 | menu._firstActive = true; |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1025 | menu.limit(3); |
| 1026 | expect(menu.show()).toBe(true); |
| 1027 | expect(menu.prefix()).toEqual(""); |
| 1028 | menu.prefix('el'); |
| 1029 | expect(menu.show()).toBe(true); |
| 1030 | |
| 1031 | expect(menu.prefix()).toEqual("el"); |
| 1032 | expect(menu._prefix.active()).toEqual(false); |
| 1033 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
| 1034 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
| 1035 | expect(menu.shownItem(0).active()).toBe(true); |
| 1036 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
| 1037 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
| 1038 | expect(menu.shownItem(1).active()).toBe(false); |
| 1039 | expect(menu.shownItem(2)).toBe(undefined); |
| 1040 | |
| 1041 | // Backward |
| 1042 | menu.prev(); |
| 1043 | expect(menu._prefix.active()).toEqual(true); |
| 1044 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
| 1045 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
| 1046 | expect(menu.shownItem(0).active()).toBe(false); |
| 1047 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
| 1048 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
| 1049 | expect(menu.shownItem(1).active()).toBe(false); |
| 1050 | expect(menu.shownItem(2)).toBe(undefined); |
| 1051 | |
| 1052 | |
| 1053 | // Forward |
| 1054 | menu.next(); |
| 1055 | expect(menu.prefix()).toEqual("el"); |
| 1056 | expect(menu._prefix.active()).toEqual(false); |
| 1057 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
| 1058 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
| 1059 | expect(menu.shownItem(0).active()).toBe(true); |
| 1060 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
| 1061 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
| 1062 | expect(menu.shownItem(1).active()).toBe(false); |
| 1063 | expect(menu.shownItem(2)).toBe(undefined); |
| 1064 | |
| 1065 | }); |
| 1066 | |
| 1067 | xit('should be page downable'); |
| 1068 | xit('should be page upable'); |
| 1069 | |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 1070 | xit('should scroll to a chosen value'); |
| 1071 | xit('should highlight a chosen value'); |
| 1072 | }); |
| 1073 | |
| 1074 | describe('KorAP.Prefix', function () { |
| 1075 | it('should be initializable', function () { |
| 1076 | var p = prefixClass.create(); |
| 1077 | expect(p.element().classList.contains('pref')).toBeTruthy(); |
| 1078 | expect(p.isSet()).not.toBeTruthy(); |
| 1079 | |
| 1080 | /* |
| 1081 | expect(mi.lcField()).toEqual(' baum'); |
| 1082 | */ |
| 1083 | |
| 1084 | }); |
| 1085 | |
| 1086 | it('should be modifiable', function () { |
| 1087 | var p = prefixClass.create(); |
| 1088 | expect(p.value()).toEqual(''); |
| 1089 | expect(p.element().firstChild).toBeNull(); |
| 1090 | |
| 1091 | // Set string |
| 1092 | expect(p.value('Test')).toEqual('Test'); |
| 1093 | expect(p.value()).toEqual('Test'); |
| 1094 | expect(p.element().firstChild.nodeValue).toEqual('Test'); |
| 1095 | |
| 1096 | // Add string |
| 1097 | expect(p.add('ified')).toEqual('Testified'); |
| 1098 | expect(p.value()).toEqual('Testified'); |
| 1099 | expect(p.element().firstChild.nodeValue).toEqual('Testified'); |
| 1100 | |
| 1101 | // Clear string |
| 1102 | p.clear(); |
| 1103 | expect(p.value()).toEqual(''); |
| 1104 | expect(p.element().firstChild).toBeNull(); |
| 1105 | |
| 1106 | // Set string |
| 1107 | expect(p.value('Test')).toEqual('Test'); |
| 1108 | expect(p.value()).toEqual('Test'); |
| 1109 | expect(p.element().firstChild.nodeValue).toEqual('Test'); |
| 1110 | |
| 1111 | expect(p.chop()).toEqual('Tes'); |
| 1112 | expect(p.value()).toEqual('Tes'); |
| 1113 | expect(p.element().firstChild.nodeValue).toEqual('Tes'); |
| 1114 | |
| 1115 | expect(p.chop()).toEqual('Te'); |
| 1116 | expect(p.value()).toEqual('Te'); |
| 1117 | expect(p.element().firstChild.nodeValue).toEqual('Te'); |
| 1118 | |
| 1119 | expect(p.chop()).toEqual('T'); |
| 1120 | expect(p.value()).toEqual('T'); |
| 1121 | expect(p.element().firstChild.nodeValue).toEqual('T'); |
| 1122 | |
| 1123 | expect(p.chop()).toEqual(''); |
| 1124 | expect(p.value()).toEqual(''); |
| 1125 | expect(p.element().firstChild).toBeNull(); |
| 1126 | }); |
| 1127 | |
| 1128 | it('should be activatable', function () { |
| 1129 | var p = prefixClass.create(); |
| 1130 | expect(p.value()).toEqual(''); |
| 1131 | expect(p.element().firstChild).toBeNull(); |
| 1132 | |
| 1133 | expect(p.value('Test')).toEqual('Test'); |
| 1134 | expect(p.element().firstChild.nodeValue).toEqual('Test'); |
| 1135 | |
| 1136 | expect(p.active()).not.toBeTruthy(); |
| 1137 | expect(p.element().classList.contains('active')).not.toBeTruthy(); |
| 1138 | |
| 1139 | p.active(true); |
| 1140 | expect(p.active()).toBeTruthy(); |
| 1141 | expect(p.element().classList.contains('active')).toBeTruthy(); |
| 1142 | }); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 1143 | }); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 1144 | }); |