Akron | 47c086c | 2016-05-18 21:22:06 +0200 | [diff] [blame] | 1 | define(['menu', 'menu/item', 'menu/prefix', 'menu/lengthField'], |
| 2 | function (menuClass, menuItemClass, prefixClass, lengthFieldClass) { |
Akron | 1ff3ac2 | 2016-04-28 16:30:45 +0200 | [diff] [blame] | 3 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 4 | // The OwnMenu item |
| 5 | KorAP.OwnMenuItem = { |
| 6 | create : function (params) { |
| 7 | return Object.create(menuItemClass).upgradeTo(KorAP.OwnMenuItem)._init(params); |
| 8 | }, |
| 9 | content : function (content) { |
| 10 | if (arguments.length === 1) { |
| 11 | this._content = content; |
| 12 | }; |
| 13 | return this._content; |
| 14 | }, |
| 15 | _init : function (params) { |
| 16 | if (params[0] === undefined) |
| 17 | throw new Error("Missing parameters"); |
| 18 | |
| 19 | this._content = document.createTextNode(params[0]); |
| 20 | this._lcField = ' ' + this.content().textContent.toLowerCase(); |
| 21 | |
| 22 | return this; |
| 23 | } |
| 24 | }; |
| 25 | |
| 26 | // The OwnMenu |
| 27 | KorAP.OwnMenu = { |
Akron | 7524be1 | 2016-06-01 17:31:33 +0200 | [diff] [blame] | 28 | create : function (list) { |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 29 | return Object.create(menuClass) |
| 30 | .upgradeTo(KorAP.OwnMenu) |
Akron | 7524be1 | 2016-06-01 17:31:33 +0200 | [diff] [blame] | 31 | ._init(list, { itemClass : KorAP.OwnMenuItem }); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 32 | } |
| 33 | }; |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 34 | |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 35 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 36 | // HintMenuItem |
| 37 | KorAP.HintMenuItem = { |
| 38 | create : function (params) { |
| 39 | return Object.create(menuItemClass) |
| 40 | .upgradeTo(KorAP.HintMenuItem) |
| 41 | ._init(params); |
| 42 | }, |
| 43 | content : function (content) { |
| 44 | if (arguments.length === 1) { |
| 45 | this._content = content; |
| 46 | }; |
| 47 | return this._content; |
| 48 | }, |
| 49 | _init : function (params) { |
| 50 | if (params[0] === undefined || params[1] === undefined) |
| 51 | throw new Error("Missing parameters"); |
| 52 | |
| 53 | this._name = params[0]; |
| 54 | this._action = params[1]; |
| 55 | this._lcField = ' ' + this._name.toLowerCase(); |
| 56 | |
| 57 | if (params.length > 2) { |
| 58 | this._desc = params[2]; |
| 59 | this._lcField += " " + this._desc.toLowerCase(); |
| 60 | }; |
| 61 | |
| 62 | return this; |
| 63 | }, |
| 64 | |
| 65 | name : function () { |
| 66 | return this._name; |
| 67 | }, |
| 68 | action : function () { |
| 69 | return this._action; |
| 70 | }, |
| 71 | desc : function () { |
| 72 | return this._desc; |
| 73 | }, |
| 74 | element : function () { |
| 75 | // already defined |
| 76 | if (this._element !== undefined) |
| 77 | return this._element; |
| 78 | |
| 79 | // Create list item |
| 80 | var li = document.createElement("li"); |
| 81 | li.setAttribute("data-action", this._action); |
| 82 | |
| 83 | // Create title |
| 84 | var name = document.createElement("strong"); |
| 85 | name.appendChild(document.createTextNode(this._name)); |
| 86 | |
| 87 | li.appendChild(name); |
| 88 | |
| 89 | // Create description |
| 90 | if (this._desc !== undefined) { |
| 91 | var desc = document.createElement("span"); |
| 92 | desc.appendChild(document.createTextNode(this._desc)); |
| 93 | li.appendChild(desc); |
| 94 | }; |
| 95 | return this._element = li; |
| 96 | } |
| 97 | }; |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 98 | |
| 99 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 100 | // HintMenu |
| 101 | KorAP.HintMenu = { |
Akron | 7524be1 | 2016-06-01 17:31:33 +0200 | [diff] [blame] | 102 | create : function (context, list) { |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 103 | var obj = Object.create(menuClass) |
| 104 | .upgradeTo(KorAP.HintMenu) |
Akron | 7524be1 | 2016-06-01 17:31:33 +0200 | [diff] [blame] | 105 | ._init(list, {itemClass : KorAP.HintMenuItem}); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 106 | obj._context = context; |
| 107 | return obj; |
| 108 | } |
| 109 | }; |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 110 | |
| 111 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 112 | // The ComplexMenuItem |
| 113 | KorAP.ComplexMenuItem = { |
| 114 | create : function (params) { |
| 115 | return Object.create(menuItemClass) |
| 116 | .upgradeTo(KorAP.ComplexMenuItem) |
| 117 | ._init(params); |
| 118 | }, |
| 119 | content : function (content) { |
| 120 | if (arguments.length === 1) { |
| 121 | this._content = content; |
| 122 | }; |
| 123 | return this._content; |
| 124 | }, |
| 125 | _init : function (params) { |
| 126 | if (params[0] === undefined) |
| 127 | throw new Error("Missing parameters"); |
| 128 | |
| 129 | var r = document.createElement('div'); |
| 130 | for (var i = 1; i <= params.length; i++) { |
| 131 | var h = document.createElement('h' + i); |
| 132 | h.appendChild(document.createTextNode(params[i-1])); |
| 133 | r.appendChild(h); |
| 134 | }; |
| 135 | |
| 136 | this._content = r; |
| 137 | this._lcField = ' ' + this.content().textContent.toLowerCase(); |
| 138 | |
| 139 | return this; |
| 140 | } |
| 141 | }; |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 142 | |
| 143 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 144 | describe('KorAP.MenuItem', function () { |
| 145 | it('should be initializable', function () { |
| 146 | expect( |
| 147 | function() { menuItemClass.create([]) } |
| 148 | ).toThrow(new Error("Missing parameters")); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 149 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 150 | expect( |
| 151 | function() { KorAP.OwnMenuItem.create([]) } |
| 152 | ).toThrow(new Error("Missing parameters")); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 153 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 154 | var mi = KorAP.OwnMenuItem.create(["Baum"]); |
| 155 | expect(mi.element().firstChild.nodeValue).toEqual('Baum'); |
| 156 | expect(mi.lcField()).toEqual(' baum'); |
| 157 | }); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 158 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 159 | it('shouldn\'t have a reference to the menu', function () { |
| 160 | var menuItem = KorAP.OwnMenuItem.create(['Test']); |
| 161 | expect(menuItem.menu()).toBe(undefined); |
| 162 | }); |
| 163 | |
| 164 | it('should be activatable and deactivateable by class', function () { |
| 165 | var menuItem = KorAP.OwnMenuItem.create(['Test']); |
| 166 | |
| 167 | expect(menuItem.active()).toBe(false); |
| 168 | expect(menuItem.element().getAttribute("class")).toBe(null); |
| 169 | menuItem.active(true); |
| 170 | expect(menuItem.active()).toBe(true); |
| 171 | expect(menuItem.element().getAttribute("class")).toEqual("active"); |
| 172 | menuItem.active(false); // Is active |
| 173 | expect(menuItem.active()).toBe(false); |
| 174 | expect(menuItem.element().getAttribute("class")).toEqual(""); |
| 175 | menuItem.active(true); |
| 176 | expect(menuItem.active()).toBe(true); |
| 177 | expect(menuItem.element().getAttribute("class")).toEqual("active"); |
| 178 | |
| 179 | menuItem = KorAP.OwnMenuItem.create(['Spiegel']); |
| 180 | expect(menuItem.active()).toBe(false); |
| 181 | expect(menuItem.element().getAttribute("class")).toBe(null); |
| 182 | menuItem.active(false); // Is not active |
| 183 | expect(menuItem.active()).toBe(false); |
| 184 | expect(menuItem.element().getAttribute("class")).toBe(null); |
| 185 | }); |
| 186 | |
| 187 | it('should be set to boundary', function () { |
| 188 | var menuItem = KorAP.OwnMenuItem.create(['CoreNLP']); |
| 189 | expect(menuItem.active()).toBe(false); |
| 190 | expect(menuItem.element().getAttribute("class")).toBe(null); |
| 191 | |
| 192 | // Set active |
| 193 | menuItem.active(true); |
| 194 | expect(menuItem.active()).toBe(true); |
| 195 | expect(menuItem.noMore()).toBe(false); |
| 196 | expect(menuItem.element().getAttribute("class")).toEqual("active"); |
| 197 | |
| 198 | // Set no more |
| 199 | menuItem.noMore(true); |
| 200 | expect(menuItem.active()).toBe(true); |
| 201 | expect(menuItem.noMore()).toBe(true); |
| 202 | expect(menuItem.element().getAttribute("class")).toEqual("active no-more"); |
| 203 | |
| 204 | // No no more |
| 205 | menuItem.noMore(false); |
| 206 | expect(menuItem.active()).toBe(true); |
| 207 | expect(menuItem.noMore()).toBe(false); |
| 208 | expect(menuItem.element().getAttribute("class")).toEqual("active"); |
| 209 | |
| 210 | // Set no more, deactivate |
| 211 | menuItem.noMore(true); |
| 212 | menuItem.active(false); |
| 213 | expect(menuItem.active()).toBe(false); |
| 214 | expect(menuItem.noMore()).toBe(true); |
| 215 | expect(menuItem.element().getAttribute("class")).toEqual("no-more"); |
| 216 | |
| 217 | // Set active |
| 218 | menuItem.active(true); |
| 219 | expect(menuItem.active()).toBe(true); |
| 220 | expect(menuItem.noMore()).toBe(true); |
| 221 | expect(menuItem.element().getAttribute("class")).toEqual("no-more active"); |
| 222 | }); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 223 | |
| 224 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 225 | it('should be highlightable', function () { |
| 226 | // Highlight in the middle |
| 227 | var menuItem = KorAP.OwnMenuItem.create(['CoreNLP']); |
| 228 | menuItem.highlight("ren"); |
| 229 | expect(menuItem.element().innerHTML).toEqual("Co<mark>reN</mark>LP"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 230 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 231 | menuItem.lowlight(); |
| 232 | expect(menuItem.element().innerHTML).toEqual("CoreNLP"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 233 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 234 | var plain = "<div><h1>CoreNLP</h1><h2>corenlp/</h2></div>"; |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 235 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 236 | // Starting highlight |
| 237 | menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']); |
| 238 | menuItem.highlight("cor"); |
| 239 | expect(menuItem.element().innerHTML).toEqual("<div><h1><mark>Cor</mark>eNLP</h1><h2><mark>cor</mark>enlp/</h2></div>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 240 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 241 | menuItem.lowlight(); |
| 242 | expect(menuItem.element().innerHTML).toEqual(plain); |
Nils Diewald | 6e43ffd | 2015-03-25 18:55:39 +0000 | [diff] [blame] | 243 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 244 | // Starting highlight - short |
| 245 | menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']); |
| 246 | menuItem.highlight("c"); |
| 247 | expect(menuItem.element().innerHTML).toEqual("<div><h1><mark>C</mark>oreNLP</h1><h2><mark>c</mark>orenlp/</h2></div>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 248 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 249 | menuItem.lowlight(); |
| 250 | expect(menuItem.element().innerHTML).toEqual(plain); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 251 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 252 | // Highlight at the end |
| 253 | menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']); |
| 254 | menuItem.highlight("nlp"); |
| 255 | expect(menuItem.element().innerHTML).toEqual("<div><h1>Core<mark>NLP</mark></h1><h2>core<mark>nlp</mark>/</h2></div>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 256 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 257 | menuItem.lowlight(); |
| 258 | expect(menuItem.element().innerHTML).toEqual(plain); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 259 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 260 | // Highlight at the end - short |
| 261 | menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']); |
| 262 | menuItem.highlight("p"); |
| 263 | expect(menuItem.element().innerHTML).toEqual("<div><h1>CoreNL<mark>P</mark></h1><h2>corenl<mark>p</mark>/</h2></div>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 264 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 265 | menuItem.lowlight(); |
| 266 | expect(menuItem.element().innerHTML).toEqual(plain); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 267 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 268 | // No highlight |
| 269 | menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']); |
| 270 | menuItem.highlight("xp"); |
| 271 | expect(menuItem.element().innerHTML).toEqual(plain); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 272 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 273 | menuItem.lowlight(); |
| 274 | expect(menuItem.element().innerHTML).toEqual(plain); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 275 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 276 | // Highlight in the middle - first |
| 277 | menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']); |
| 278 | menuItem.highlight("ren"); |
| 279 | expect(menuItem.element().innerHTML).toEqual("<div><h1>Co<mark>reN</mark>LP</h1><h2>co<mark>ren</mark>lp/</h2><h3>This is my Example</h3></div>"); |
| 280 | |
| 281 | plain = "<div><h1>CoreNLP</h1><h2>corenlp/</h2><h3>This is my Example</h3></div>" |
| 282 | |
| 283 | menuItem.lowlight(); |
| 284 | expect(menuItem.element().innerHTML).toEqual(plain); |
| 285 | |
| 286 | // Highlight in the middle - second |
| 287 | menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']); |
| 288 | menuItem.highlight("ampl"); |
| 289 | expect(menuItem.element().innerHTML).toEqual("<div><h1>CoreNLP</h1><h2>corenlp/</h2><h3>This is my Ex<mark>ampl</mark>e</h3></div>"); |
| 290 | |
| 291 | menuItem.lowlight(); |
| 292 | expect(menuItem.element().innerHTML).toEqual(plain); |
| 293 | |
| 294 | // Highlight in the middle - both |
| 295 | menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']); |
| 296 | menuItem.highlight("e"); |
| 297 | expect(menuItem.element().innerHTML).toEqual("<div><h1>Cor<mark>e</mark>NLP</h1><h2>cor<mark>e</mark>nlp/</h2><h3>This is my <mark>E</mark>xampl<mark>e</mark></h3></div>"); |
| 298 | |
| 299 | menuItem.lowlight(); |
| 300 | expect(menuItem.element().innerHTML).toEqual(plain); |
| 301 | |
| 302 | // Highlight in the end - second |
| 303 | menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']); |
| 304 | menuItem.highlight("le"); |
| 305 | expect(menuItem.element().innerHTML).toEqual("<div><h1>CoreNLP</h1><h2>corenlp/</h2><h3>This is my Examp<mark>le</mark></h3></div>"); |
| 306 | |
| 307 | menuItem.lowlight(); |
| 308 | expect(menuItem.element().innerHTML).toEqual(plain); |
| 309 | |
| 310 | // Highlight at the beginning - second |
| 311 | menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']); |
| 312 | menuItem.highlight("this"); |
| 313 | expect(menuItem.element().innerHTML).toEqual("<div><h1>CoreNLP</h1><h2>corenlp/</h2><h3><mark>This</mark> is my Example</h3></div>"); |
| 314 | |
| 315 | menuItem.lowlight(); |
| 316 | expect(menuItem.element().innerHTML).toEqual(plain); |
| 317 | }); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 318 | }); |
| 319 | |
| 320 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 321 | describe('KorAP.Menu', function () { |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 322 | var list = [ |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 323 | ["Constituency", "c=", "Example 1"], |
| 324 | ["Lemma", "l="], |
| 325 | ["Morphology", "m=", "Example 2"], |
| 326 | ["Part-of-Speech", "p="], |
| 327 | ["Syntax", "syn="] |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 328 | ]; |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 329 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 330 | var demolist = [ |
| 331 | ['Titel', 'title'], |
| 332 | ['Untertitel', 'subTitle'], |
| 333 | ['Veröffentlichungsdatum', 'pubDate'], |
| 334 | ['Länge', 'length'], |
| 335 | ['Autor', 'author'] |
| 336 | ]; |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 337 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 338 | var demolonglist = [ |
| 339 | ['Titel', 'title'], |
| 340 | ['Untertitel', 'subTitle'], |
| 341 | ['Veröffentlichungsdatum', 'pubDate'], |
| 342 | ['Länge', 'length'], |
| 343 | ['Autor', 'author'], |
| 344 | ['Genre', 'genre'], |
| 345 | ['corpusID', 'corpusID'], |
| 346 | ['docID', 'docID'], |
| 347 | ['textID', 'textID'], |
| 348 | ]; |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 349 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 350 | it('should be initializable', function () { |
| 351 | var list = [ |
| 352 | ["Constituency"], |
| 353 | ["Lemma"], |
| 354 | ["Morphology"], |
| 355 | ["Part-of-Speech"], |
| 356 | ["Syntax"] |
| 357 | ]; |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 358 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 359 | var menu = KorAP.OwnMenu.create(list); |
Akron | c1457bf | 2015-06-11 19:24:00 +0200 | [diff] [blame] | 360 | menu._firstActive = true; |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 361 | expect(menu.itemClass()).toEqual(KorAP.OwnMenuItem); |
| 362 | expect(menu.element().nodeName).toEqual('UL'); |
Akron | f0c31ed | 2016-06-11 11:27:01 +0200 | [diff] [blame^] | 363 | expect(menu.element().classList.contains('visible')).toBeFalsy(); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 364 | expect(menu.limit()).toEqual(8); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 365 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 366 | menu.limit(9); |
| 367 | expect(menu.limit()).toEqual(9); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 368 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 369 | menu.limit(8); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 370 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 371 | // view |
| 372 | menu.show(); |
| 373 | |
| 374 | // First element in list |
| 375 | expect(menu.item(0).active()).toBe(true); |
| 376 | expect(menu.item(0).noMore()).toBe(true); |
| 377 | |
| 378 | // Middle element in list |
| 379 | expect(menu.item(2).active()).toBe(false); |
| 380 | expect(menu.item(2).noMore()).toBe(false); |
| 381 | |
| 382 | // Last element in list |
| 383 | expect(menu.item(menu.length() - 1).active()).toBe(false); |
| 384 | expect(menu.item(menu.length() - 1).noMore()).toBe(true); |
| 385 | }); |
| 386 | |
| 387 | it('should have a reference to the menu', function () { |
| 388 | var menu = KorAP.HintMenu.create("cnx/", list); |
| 389 | expect(menu.item(0).menu()).toEqual(menu); |
| 390 | |
| 391 | menu = KorAP.HintMenu.create("cnx/", list); |
| 392 | expect(menu.element().menu).toEqual(menu); |
| 393 | }); |
| 394 | |
| 395 | |
| 396 | it('should be visible', function () { |
| 397 | var menu = KorAP.HintMenu.create("cnx/", list); |
Akron | a92fd8d | 2016-05-24 21:13:41 +0200 | [diff] [blame] | 398 | expect(menu.removeItems()).toBe(undefined); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 399 | menu.limit(3); |
| 400 | |
| 401 | expect(menu.show()).toBe(true); |
| 402 | |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 403 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>"); |
| 404 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Lemma</strong>"); |
| 405 | expect(menu.element().childNodes[4].getAttribute("data-action")).toEqual("l="); |
| 406 | expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
| 407 | expect(menu.element().childNodes[6]).toBe(undefined); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 408 | |
| 409 | // Check boundaries |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 410 | expect(menu.element().childNodes[3].classList.contains("no-more")).toBe(true); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame] | 411 | expect(menu.element().childNodes[4].classList.contains("no-more")).toBe(false); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 412 | expect(menu.element().childNodes[5].classList.contains("no-more")).toBe(false); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 413 | }); |
| 414 | |
| 415 | it('should be filterable', function () { |
| 416 | var menu = KorAP.HintMenu.create("cnx/", list); |
| 417 | menu.limit(3); |
| 418 | expect(menu.prefix("o").show()).toBe(true); |
| 419 | expect(menu.element().childNodes[0].innerHTML).toEqual("o"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 420 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>"); |
| 421 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>"); |
| 422 | expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>"); |
| 423 | expect(menu.element().childNodes[6]).toBe(undefined); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 424 | |
| 425 | // Check boundaries |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 426 | expect(menu.element().childNodes[3].classList.contains("no-more")).toBe(true); |
| 427 | expect(menu.element().childNodes[4].classList.contains("no-more")).toBe(false); |
| 428 | expect(menu.element().childNodes[5].classList.contains("no-more")).toBe(true); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 429 | |
| 430 | menu.limit(2); |
| 431 | |
| 432 | expect(menu.prefix("o").show()).toBe(true); |
| 433 | expect(menu.element().childNodes[0].innerHTML).toEqual("o"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 434 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>"); |
| 435 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>"); |
| 436 | expect(menu.element().childNodes[5]).toBe(undefined); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 437 | |
| 438 | // Check boundaries |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 439 | expect(menu.element().childNodes[3].classList.contains("no-more")).toBe(true); |
| 440 | expect(menu.element().childNodes[4].classList.contains("no-more")).toBe(false); |
| 441 | expect(menu.element().childNodes[5]).toBe(undefined); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 442 | |
| 443 | expect(menu.prefix("e").show()).toBe(true); |
| 444 | expect(menu.element().childNodes[0].innerHTML).toEqual("e"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 445 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>"); |
| 446 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>"); |
| 447 | expect(menu.element().childNodes[5]).toBe(undefined); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 448 | |
| 449 | menu.limit(5); |
| 450 | expect(menu.prefix("a").show()).toBe(true); |
| 451 | expect(menu.element().childNodes[0].innerHTML).toEqual("a"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 452 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constituency</strong><span>Ex<mark>a</mark>mple 1</span>"); |
| 453 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Lemm<mark>a</mark></strong>"); |
| 454 | expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Morphology</strong><span>Ex<mark>a</mark>mple 2</span>"); |
| 455 | expect(menu.element().childNodes[6].innerHTML).toEqual("<strong>P<mark>a</mark>rt-of-Speech</strong>"); |
| 456 | expect(menu.element().childNodes[7].innerHTML).toEqual("<strong>Synt<mark>a</mark>x</strong>"); |
| 457 | expect(menu.element().childNodes[8]).toBe(undefined); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 458 | }); |
| 459 | |
| 460 | |
| 461 | it('should be nextable', function () { |
| 462 | var menu = KorAP.HintMenu.create("cnx/", list); |
Akron | c1457bf | 2015-06-11 19:24:00 +0200 | [diff] [blame] | 463 | menu._firstActive = true; |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 464 | |
| 465 | // Show only 3 items |
| 466 | menu.limit(3); |
| 467 | expect(menu.show()).toBe(true); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 468 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 469 | expect(menu.shownItem(0).active()).toBe(true); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 470 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Lemma</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 471 | expect(menu.shownItem(1).active()).toBe(false); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 472 | expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 473 | expect(menu.shownItem(2).active()).toBe(false); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 474 | expect(menu.element().childNodes[6]).toBe(undefined); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 475 | |
| 476 | // Activate next (1) |
| 477 | menu.next(); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 478 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 479 | expect(menu.shownItem(0).active()).toBe(false); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 480 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Lemma</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 481 | expect(menu.shownItem(1).active()).toBe(true); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 482 | expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 483 | expect(menu.shownItem(2).active()).toBe(false); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 484 | expect(menu.element().childNodes[6]).toBe(undefined); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 485 | |
| 486 | // Activate next (2) |
| 487 | menu.next(); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 488 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 489 | expect(menu.shownItem(0).active()).toBe(false); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 490 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Lemma</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 491 | expect(menu.shownItem(1).active()).toBe(false); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 492 | expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 493 | expect(menu.shownItem(2).active()).toBe(true); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 494 | expect(menu.element().childNodes[6]).toBe(undefined); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 495 | |
| 496 | // Activate next (3) |
| 497 | // scroll! |
| 498 | menu.next(); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 499 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Lemma</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 500 | expect(menu.shownItem(0).active()).toBe(false); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 501 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 502 | expect(menu.shownItem(1).active()).toBe(false); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 503 | expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Part-of-Speech</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 504 | expect(menu.shownItem(2).active()).toBe(true); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 505 | expect(menu.element().childNodes[6]).toBe(undefined); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 506 | |
| 507 | // Activate next (4) |
| 508 | menu.next(); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 509 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 510 | expect(menu.shownItem(0).active()).toBe(false); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 511 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Part-of-Speech</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 512 | expect(menu.shownItem(1).active()).toBe(false); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 513 | expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Syntax</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 514 | expect(menu.shownItem(2).active()).toBe(true); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 515 | expect(menu.element().childNodes[6]).toBe(undefined); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 516 | |
| 517 | // Activate next (5) - ROLL |
| 518 | menu.next(); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 519 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 520 | expect(menu.shownItem(0).active()).toBe(true); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 521 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Lemma</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 522 | expect(menu.shownItem(1).active()).toBe(false); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 523 | expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 524 | expect(menu.shownItem(2).active()).toBe(false); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 525 | expect(menu.element().childNodes[6]).toBe(undefined); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 526 | |
| 527 | // Active next (6) |
| 528 | menu.next(); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 529 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 530 | expect(menu.shownItem(0).active()).toBe(false); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 531 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Lemma</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 532 | expect(menu.shownItem(1).active()).toBe(true); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 533 | expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 534 | expect(menu.shownItem(2).active()).toBe(false); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 535 | expect(menu.element().childNodes[6]).toBe(undefined); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 536 | }); |
| 537 | |
Akron | 9c4d1ae | 2016-05-25 21:43:22 +0200 | [diff] [blame] | 538 | it('should be nextable without active field', function () { |
| 539 | var menu = KorAP.HintMenu.create("cnx/", list); |
| 540 | menu.limit(3); |
| 541 | expect(menu.show()).toBe(true); |
| 542 | menu.next(); |
| 543 | expect(menu.shownItem(0).active()).toEqual(true); |
| 544 | }); |
| 545 | |
| 546 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 547 | it('should be prevable', function () { |
| 548 | var menu = KorAP.HintMenu.create("cnx/", list); |
Akron | c1457bf | 2015-06-11 19:24:00 +0200 | [diff] [blame] | 549 | menu._firstActive = true; |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 550 | menu.limit(3); |
| 551 | expect(menu.show()).toBe(true); |
| 552 | |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 553 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 554 | expect(menu.shownItem(0).active()).toBe(true); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 555 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Lemma</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 556 | expect(menu.shownItem(1).active()).toBe(false); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 557 | expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 558 | expect(menu.shownItem(2).active()).toBe(false); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 559 | expect(menu.element().childNodes[6]).toBe(undefined); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 560 | |
| 561 | // Activate prev (1) - roll to bottom |
| 562 | menu.prev(); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 563 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 564 | expect(menu.shownItem(0).active()).toBe(false); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 565 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Part-of-Speech</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 566 | expect(menu.shownItem(1).active()).toBe(false); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 567 | expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Syntax</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 568 | expect(menu.shownItem(2).active()).toBe(true); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 569 | expect(menu.element().childNodes[6]).toBe(undefined); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 570 | |
| 571 | // Activate prev (2) |
| 572 | menu.prev(); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 573 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 574 | expect(menu.shownItem(0).active()).toBe(false); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 575 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Part-of-Speech</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 576 | expect(menu.shownItem(1).active()).toBe(true); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 577 | expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Syntax</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 578 | expect(menu.shownItem(2).active()).toBe(false); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 579 | expect(menu.element().childNodes[6]).toBe(undefined); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 580 | |
| 581 | // Activate prev (3) |
| 582 | menu.prev(); |
| 583 | expect(menu.shownItem(0).name()).toEqual("Morphology"); |
| 584 | expect(menu.shownItem(0).active()).toBe(true); |
| 585 | expect(menu.shownItem(1).name()).toEqual("Part-of-Speech"); |
| 586 | expect(menu.shownItem(1).active()).toBe(false); |
| 587 | expect(menu.shownItem(2).name()).toEqual("Syntax"); |
| 588 | expect(menu.shownItem(2).active()).toBe(false); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 589 | expect(menu.element().childNodes[6]).toBe(undefined); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 590 | |
| 591 | // Activate prev (4) |
| 592 | menu.prev(); |
| 593 | expect(menu.shownItem(0).name()).toEqual("Lemma"); |
| 594 | expect(menu.shownItem(0).active()).toBe(true); |
| 595 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
| 596 | expect(menu.shownItem(1).active()).toBe(false); |
| 597 | expect(menu.shownItem(2).name()).toEqual("Part-of-Speech"); |
| 598 | expect(menu.shownItem(2).active()).toBe(false); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 599 | expect(menu.element().childNodes[6]).toBe(undefined); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 600 | |
| 601 | // Activate prev (5) |
| 602 | menu.prev(); |
| 603 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
| 604 | expect(menu.shownItem(0).active()).toBe(true); |
| 605 | expect(menu.shownItem(1).name()).toEqual("Lemma"); |
| 606 | expect(menu.shownItem(1).active()).toBe(false); |
| 607 | expect(menu.shownItem(2).name()).toEqual("Morphology"); |
| 608 | expect(menu.shownItem(2).active()).toBe(false); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 609 | expect(menu.element().childNodes[6]).toBe(undefined); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 610 | |
| 611 | // Activate next (1) |
| 612 | menu.next(); |
| 613 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
| 614 | expect(menu.shownItem(0).active()).toBe(false); |
| 615 | expect(menu.shownItem(1).name()).toEqual("Lemma"); |
| 616 | expect(menu.shownItem(1).active()).toBe(true); |
| 617 | expect(menu.shownItem(2).name()).toEqual("Morphology"); |
| 618 | expect(menu.shownItem(2).active()).toBe(false); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 619 | expect(menu.element().childNodes[6]).toBe(undefined); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 620 | |
| 621 | // Activate prev (6) |
| 622 | menu.prev(); |
| 623 | |
| 624 | // Activate prev (7) |
| 625 | menu.prev(); |
| 626 | expect(menu.shownItem(0).name()).toEqual("Morphology"); |
| 627 | expect(menu.shownItem(0).active()).toBe(false); |
| 628 | expect(menu.shownItem(1).name()).toEqual("Part-of-Speech"); |
| 629 | expect(menu.shownItem(1).active()).toBe(false); |
| 630 | expect(menu.shownItem(2).name()).toEqual("Syntax"); |
| 631 | expect(menu.shownItem(2).active()).toBe(true); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 632 | expect(menu.element().childNodes[6]).toBe(undefined); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 633 | }); |
| 634 | |
Akron | 9c4d1ae | 2016-05-25 21:43:22 +0200 | [diff] [blame] | 635 | it('should be prevable without active field', function () { |
| 636 | var menu = KorAP.HintMenu.create("cnx/", list); |
| 637 | menu.limit(3); |
| 638 | expect(menu.show()).toBe(true); |
| 639 | menu.prev(); |
| 640 | expect(menu.shownItem(2).active()).toEqual(true); |
| 641 | expect(menu.shownItem(2).lcField()).toEqual(' syntax'); |
| 642 | }); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 643 | |
| 644 | it('should be navigatable and filterable (prefix = "o")', function () { |
| 645 | var menu = KorAP.HintMenu.create("cnx/", list); |
Akron | c1457bf | 2015-06-11 19:24:00 +0200 | [diff] [blame] | 646 | menu._firstActive = true; |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 647 | menu.limit(2); |
| 648 | |
| 649 | expect(menu.prefix("o").show()).toBe(true); |
| 650 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 651 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 652 | expect(menu.shownItem(0).active()).toBe(true); |
| 653 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 654 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 655 | expect(menu.shownItem(1).active()).toBe(false); |
| 656 | expect(menu.shownItem(2)).toBe(undefined); |
| 657 | |
| 658 | // Next (1) |
| 659 | menu.next(); |
| 660 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 661 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 662 | expect(menu.shownItem(0).active()).toBe(false); |
| 663 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 664 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 665 | expect(menu.shownItem(1).active()).toBe(true); |
| 666 | expect(menu.shownItem(2)).toBe(undefined); |
| 667 | |
| 668 | // Next (2) |
| 669 | menu.next(); |
| 670 | expect(menu.shownItem(0).name()).toEqual("Morphology"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 671 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 672 | expect(menu.shownItem(0).active()).toBe(false); |
| 673 | expect(menu.shownItem(1).name()).toEqual("Part-of-Speech"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 674 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 675 | expect(menu.shownItem(1).active()).toBe(true); |
| 676 | expect(menu.shownItem(2)).toBe(undefined); |
| 677 | |
| 678 | // Next (3) - to prefix |
| 679 | menu.next(); |
| 680 | expect(menu.shownItem(0).name()).toEqual("Morphology"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 681 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 682 | expect(menu.shownItem(0).active()).toBe(false); |
| 683 | expect(menu.shownItem(1).name()).toEqual("Part-of-Speech"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 684 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 685 | expect(menu.shownItem(1).active()).toBe(false); |
| 686 | expect(menu.shownItem(2)).toBe(undefined); |
| 687 | |
| 688 | menu.next(); |
| 689 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 690 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 691 | expect(menu.shownItem(0).active()).toBe(true); |
| 692 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 693 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 694 | expect(menu.shownItem(1).active()).toBe(false); |
| 695 | expect(menu.shownItem(2)).toBe(undefined); |
| 696 | }); |
| 697 | |
| 698 | |
| 699 | it('should be navigatable and filterable (prefix = "ex", "e")', function () { |
| 700 | var menu = KorAP.HintMenu.create("cnx/", list); |
Akron | c1457bf | 2015-06-11 19:24:00 +0200 | [diff] [blame] | 701 | menu._firstActive = true; |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 702 | |
| 703 | menu.limit(2); |
| 704 | expect(menu.prefix("ex").show()).toBe(true); |
| 705 | |
| 706 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 707 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constituency</strong><span><mark>Ex</mark>ample 1</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 708 | expect(menu.shownItem(0).active()).toBe(true); |
| 709 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 710 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Morphology</strong><span><mark>Ex</mark>ample 2</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 711 | expect(menu.shownItem(1).active()).toBe(false); |
| 712 | expect(menu.shownItem(2)).toBe(undefined); |
| 713 | |
| 714 | // Next (1) |
| 715 | menu.next(); |
| 716 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 717 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constituency</strong><span><mark>Ex</mark>ample 1</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 718 | expect(menu.shownItem(0).active()).toBe(false); |
| 719 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 720 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Morphology</strong><span><mark>Ex</mark>ample 2</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 721 | expect(menu.shownItem(1).active()).toBe(true); |
| 722 | expect(menu.shownItem(2)).toBe(undefined); |
| 723 | |
| 724 | // Next (2) |
| 725 | menu.next(); |
| 726 | |
| 727 | expect(menu.prefix()).toEqual('ex'); |
| 728 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 729 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constituency</strong><span><mark>Ex</mark>ample 1</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 730 | expect(menu.shownItem(0).active()).toBe(false); |
| 731 | |
| 732 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 733 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Morphology</strong><span><mark>Ex</mark>ample 2</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 734 | expect(menu.shownItem(1).active()).toBe(false); |
| 735 | expect(menu.shownItem(2)).toBe(undefined); |
| 736 | |
| 737 | // Reset limit |
| 738 | menu.limit(5); |
| 739 | |
| 740 | // Change show |
| 741 | expect(menu.prefix("e").show()).toBe(true); |
| 742 | expect(menu._prefix.active()).toBe(false); |
| 743 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 744 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 745 | expect(menu.shownItem(0).active()).toBe(true); |
| 746 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 747 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 748 | expect(menu.shownItem(1).active()).toBe(false); |
| 749 | expect(menu.shownItem(2)).toBe(undefined); |
| 750 | |
| 751 | // Next (1) |
| 752 | menu.next(); |
| 753 | expect(menu._prefix.active()).toBe(false); |
| 754 | expect(menu.prefix()).toEqual('e'); |
| 755 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 756 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 757 | expect(menu.shownItem(0).active()).toBe(false); |
| 758 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 759 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 760 | expect(menu.shownItem(1).active()).toBe(true); |
| 761 | expect(menu.shownItem(2)).toBe(undefined); |
| 762 | |
| 763 | // Next (2) |
| 764 | menu.next(); |
| 765 | expect(menu._prefix.active()).toBe(true); |
| 766 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 767 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 768 | expect(menu.shownItem(0).active()).toBe(false); |
| 769 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 770 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 771 | expect(menu.shownItem(1).active()).toBe(false); |
| 772 | expect(menu.shownItem(2)).toBe(undefined); |
| 773 | |
| 774 | // Next (3) |
| 775 | menu.next(); |
| 776 | expect(menu._prefix.active()).toBe(false); |
| 777 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 778 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 779 | expect(menu.shownItem(0).active()).toBe(true); |
| 780 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 781 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 782 | expect(menu.shownItem(1).active()).toBe(false); |
| 783 | expect(menu.shownItem(2)).toBe(undefined); |
| 784 | }); |
| 785 | |
| 786 | |
Akron | a92fd8d | 2016-05-24 21:13:41 +0200 | [diff] [blame] | 787 | it('should choose prefix with failing prefix (1)', function () { |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 788 | var menu = KorAP.HintMenu.create("cnx/", list); |
| 789 | menu.limit(2); |
Akron | 6ed1399 | 2016-05-23 18:06:05 +0200 | [diff] [blame] | 790 | expect(menu.prefix("exit").show()).toBe(true); |
Akron | a92fd8d | 2016-05-24 21:13:41 +0200 | [diff] [blame] | 791 | expect(menu.element().querySelector('li')).toBe(null); |
| 792 | expect(menu.shownItem(0)).toBeUndefined(); |
| 793 | expect(menu._prefix.active()).toBe(true); |
| 794 | }); |
| 795 | |
| 796 | |
| 797 | it('should choose prefix with failing prefix (2)', function () { |
| 798 | var menu = KorAP.HintMenu.create("cnx/", list); |
| 799 | menu.limit(2); |
| 800 | expect(menu.show()).toBe(true); |
| 801 | expect(menu.prefix("exit").show()).toBe(true); |
| 802 | expect(menu.element().querySelector('li')).toBe(null); |
Akron | 6ed1399 | 2016-05-23 18:06:05 +0200 | [diff] [blame] | 803 | expect(menu.shownItem(0)).toBeUndefined(); |
| 804 | expect(menu._prefix.active()).toBe(true); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 805 | }); |
| 806 | |
Akron | b38afb2 | 2016-05-25 19:30:01 +0200 | [diff] [blame] | 807 | it('should ignore navigation with failing prefix', function () { |
| 808 | var menu = KorAP.HintMenu.create("cnx/", list); |
| 809 | menu.limit(2); |
| 810 | expect(menu.show()).toBe(true); |
| 811 | |
| 812 | menu.next(); |
| 813 | |
| 814 | expect(menu.prefix("exit").show()).toBe(true); |
| 815 | expect(menu.element().querySelector('li')).toBe(null); |
| 816 | expect(menu.shownItem(0)).toBeUndefined(); |
| 817 | expect(menu._prefix.active()).toBe(true); |
| 818 | |
| 819 | menu.next(); |
| 820 | expect(menu._prefix.active()).toBe(true); |
| 821 | |
| 822 | menu.prev(); |
| 823 | expect(menu._prefix.active()).toBe(true); |
| 824 | |
| 825 | }); |
Akron | 37513a6 | 2015-11-17 01:07:11 +0100 | [diff] [blame] | 826 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 827 | it('should be navigatable with prefix', function () { |
| 828 | var menu = KorAP.HintMenu.create("cnx/", demolist); |
Akron | c1457bf | 2015-06-11 19:24:00 +0200 | [diff] [blame] | 829 | menu._firstActive = true; |
| 830 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 831 | menu.limit(3); |
| 832 | |
| 833 | expect(menu.show()).toBe(true); |
| 834 | expect(menu.prefix()).toEqual(""); |
| 835 | |
| 836 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 837 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Titel</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 838 | expect(menu.shownItem(0).active()).toBe(true); |
| 839 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 840 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertitel</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 841 | expect(menu.shownItem(1).active()).toBe(false); |
| 842 | expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 843 | expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 844 | expect(menu.shownItem(2).active()).toBe(false); |
| 845 | expect(menu.shownItem(3)).toBe(undefined); |
| 846 | |
| 847 | menu._prefix.add('a'); |
| 848 | expect(menu.show()).toBe(true); |
| 849 | expect(menu.prefix()).toEqual("a"); |
| 850 | expect(menu.shownItem(0).name()).toEqual("Autor"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 851 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong><mark>A</mark>utor</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 852 | |
| 853 | menu._prefix.add('u'); |
| 854 | expect(menu.show()).toBe(true); |
| 855 | expect(menu.prefix()).toEqual("au"); |
| 856 | expect(menu.shownItem(0).name()).toEqual("Autor"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 857 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong><mark>Au</mark>tor</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 858 | |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 859 | menu._prefix.chop(); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 860 | expect(menu.show()).toBe(true); |
| 861 | expect(menu.prefix()).toEqual("a"); |
| 862 | expect(menu.shownItem(0).name()).toEqual("Autor"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 863 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong><mark>A</mark>utor</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 864 | |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 865 | menu._prefix.chop(); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 866 | expect(menu.show()).toBe(true); |
| 867 | expect(menu.prefix()).toEqual(""); |
| 868 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 869 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Titel</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 870 | expect(menu.shownItem(0).active()).toBe(true); |
| 871 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 872 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertitel</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 873 | expect(menu.shownItem(1).active()).toBe(false); |
| 874 | expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 875 | expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 876 | expect(menu.shownItem(2).active()).toBe(false); |
| 877 | expect(menu.shownItem(3)).toBe(undefined); |
| 878 | |
| 879 | // Forward |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 880 | menu._prefix.chop(); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 881 | expect(menu.show()).toBe(true); |
| 882 | expect(menu.prefix()).toEqual(""); |
| 883 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 884 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Titel</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 885 | expect(menu.shownItem(0).active()).toBe(true); |
| 886 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 887 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertitel</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 888 | expect(menu.shownItem(1).active()).toBe(false); |
| 889 | expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 890 | expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 891 | expect(menu.shownItem(2).active()).toBe(false); |
| 892 | |
| 893 | // Forward |
| 894 | menu.next(); |
| 895 | expect(menu.prefix()).toEqual(""); |
| 896 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 897 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Titel</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 898 | expect(menu.shownItem(0).active()).toBe(false); |
| 899 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 900 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertitel</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 901 | expect(menu.shownItem(1).active()).toBe(true); |
| 902 | expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 903 | expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 904 | expect(menu.shownItem(2).active()).toBe(false); |
| 905 | expect(menu.shownItem(3)).toBe(undefined); |
| 906 | |
| 907 | // Forward |
| 908 | menu.next(); |
| 909 | expect(menu.prefix()).toEqual(""); |
| 910 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 911 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Titel</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 912 | expect(menu.shownItem(0).active()).toBe(false); |
| 913 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 914 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertitel</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 915 | expect(menu.shownItem(1).active()).toBe(false); |
| 916 | expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 917 | expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 918 | expect(menu.shownItem(2).active()).toBe(true); |
| 919 | expect(menu.shownItem(3)).toBe(undefined); |
| 920 | |
| 921 | // Forward |
| 922 | menu.next(); |
| 923 | expect(menu.prefix()).toEqual(""); |
| 924 | expect(menu.shownItem(0).name()).toEqual("Untertitel"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 925 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Untertitel</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 926 | expect(menu.shownItem(0).active()).toBe(false); |
| 927 | expect(menu.shownItem(1).name()).toEqual("Veröffentlichungsdatum"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 928 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 929 | expect(menu.shownItem(1).active()).toBe(false); |
| 930 | expect(menu.shownItem(2).name()).toEqual("Länge"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 931 | expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Länge</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 932 | expect(menu.shownItem(2).active()).toBe(true); |
| 933 | expect(menu.shownItem(3)).toBe(undefined); |
| 934 | |
| 935 | // Forward |
| 936 | menu.next(); |
| 937 | expect(menu.prefix()).toEqual(""); |
| 938 | expect(menu.shownItem(0).name()).toEqual("Veröffentlichungsdatum"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 939 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 940 | expect(menu.shownItem(0).active()).toBe(false); |
| 941 | expect(menu.shownItem(1).name()).toEqual("Länge"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 942 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Länge</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 943 | expect(menu.shownItem(1).active()).toBe(false); |
| 944 | expect(menu.shownItem(2).name()).toEqual("Autor"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 945 | expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Autor</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 946 | expect(menu.shownItem(2).active()).toBe(true); |
| 947 | expect(menu.shownItem(3)).toBe(undefined); |
| 948 | |
| 949 | // Forward |
| 950 | menu.next(); |
| 951 | expect(menu.prefix()).toEqual(""); |
| 952 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 953 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Titel</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 954 | expect(menu.shownItem(0).active()).toBe(true); |
| 955 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 956 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertitel</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 957 | expect(menu.shownItem(1).active()).toBe(false); |
| 958 | expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 959 | expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 960 | expect(menu.shownItem(2).active()).toBe(false); |
| 961 | }); |
| 962 | |
| 963 | |
| 964 | it('should be navigatable with a prefix (1)', function () { |
| 965 | var menu = KorAP.HintMenu.create("cnx/", demolist); |
Akron | c1457bf | 2015-06-11 19:24:00 +0200 | [diff] [blame] | 966 | menu._firstActive = true; |
| 967 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 968 | menu.limit(3); |
| 969 | |
| 970 | expect(menu.show()).toBe(true); |
| 971 | expect(menu.prefix()).toEqual(""); |
| 972 | |
Akron | 6ffad5d | 2016-05-24 17:16:58 +0200 | [diff] [blame] | 973 | // Add prefix in uppercase - but check in lowercase |
| 974 | menu.prefix('El'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 975 | expect(menu.show()).toBe(true); |
| 976 | |
Akron | 6ffad5d | 2016-05-24 17:16:58 +0200 | [diff] [blame] | 977 | expect(menu.prefix()).toEqual("El"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 978 | expect(menu._prefix.active()).toEqual(false); |
| 979 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 980 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 981 | expect(menu.shownItem(0).active()).toBe(true); |
| 982 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 983 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 984 | expect(menu.shownItem(1).active()).toBe(false); |
| 985 | expect(menu.shownItem(2)).toBe(undefined); |
| 986 | |
| 987 | // Forward |
| 988 | menu.next(); |
Akron | 6ffad5d | 2016-05-24 17:16:58 +0200 | [diff] [blame] | 989 | expect(menu.prefix()).toEqual("El"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 990 | expect(menu._prefix.active()).toEqual(false); |
| 991 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 992 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 993 | expect(menu.shownItem(0).active()).toBe(false); |
| 994 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 995 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 996 | expect(menu.shownItem(1).active()).toBe(true); |
| 997 | expect(menu.shownItem(2)).toBe(undefined); |
| 998 | |
| 999 | // Forward |
| 1000 | menu.next(); |
Akron | 6ffad5d | 2016-05-24 17:16:58 +0200 | [diff] [blame] | 1001 | expect(menu.prefix()).toEqual("El"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1002 | expect(menu._prefix.active()).toEqual(true); |
| 1003 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 1004 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1005 | expect(menu.shownItem(0).active()).toBe(false); |
| 1006 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 1007 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1008 | expect(menu.shownItem(1).active()).toBe(false); |
| 1009 | expect(menu.shownItem(2)).toBe(undefined); |
| 1010 | |
| 1011 | // Backward |
| 1012 | menu.prev(); |
Akron | 6ffad5d | 2016-05-24 17:16:58 +0200 | [diff] [blame] | 1013 | expect(menu.prefix()).toEqual("El"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1014 | expect(menu._prefix.active()).toEqual(false); |
| 1015 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 1016 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1017 | expect(menu.shownItem(0).active()).toBe(false); |
| 1018 | |
| 1019 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 1020 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1021 | expect(menu.shownItem(1).active()).toBe(true); |
| 1022 | expect(menu.shownItem(2)).toBe(undefined); |
| 1023 | }); |
| 1024 | |
| 1025 | |
| 1026 | it('should be navigatable with a prefix (2)', function () { |
| 1027 | var menu = KorAP.HintMenu.create("cnx/", demolist); |
Akron | c1457bf | 2015-06-11 19:24:00 +0200 | [diff] [blame] | 1028 | menu._firstActive = true; |
| 1029 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1030 | menu.limit(3); |
| 1031 | expect(menu.show()).toBe(true); |
| 1032 | expect(menu.prefix()).toEqual(""); |
| 1033 | menu.prefix('el'); |
| 1034 | expect(menu.show()).toBe(true); |
| 1035 | |
| 1036 | expect(menu.prefix()).toEqual("el"); |
| 1037 | expect(menu._prefix.active()).toEqual(false); |
| 1038 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 1039 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1040 | expect(menu.shownItem(0).active()).toBe(true); |
| 1041 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 1042 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1043 | expect(menu.shownItem(1).active()).toBe(false); |
| 1044 | expect(menu.shownItem(2)).toBe(undefined); |
| 1045 | |
| 1046 | // Backward |
| 1047 | menu.prev(); |
| 1048 | expect(menu._prefix.active()).toEqual(true); |
| 1049 | |
| 1050 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 1051 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1052 | expect(menu.shownItem(0).active()).toBe(false); |
| 1053 | |
| 1054 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 1055 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1056 | expect(menu.shownItem(1).active()).toBe(false); |
| 1057 | expect(menu.shownItem(2)).toBe(undefined); |
| 1058 | |
| 1059 | // Backward |
| 1060 | menu.prev(); |
| 1061 | expect(menu._prefix.active()).toEqual(false); |
| 1062 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 1063 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1064 | expect(menu.shownItem(0).active()).toBe(false); |
| 1065 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 1066 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1067 | expect(menu.shownItem(1).active()).toBe(true); |
| 1068 | expect(menu.shownItem(2)).toBe(undefined); |
| 1069 | }); |
| 1070 | |
| 1071 | it('should be navigatable with a prefix (3)', function () { |
| 1072 | var menu = KorAP.HintMenu.create("cnx/", demolist); |
Akron | c1457bf | 2015-06-11 19:24:00 +0200 | [diff] [blame] | 1073 | menu._firstActive = true; |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1074 | menu.limit(3); |
| 1075 | expect(menu.show()).toBe(true); |
| 1076 | expect(menu.prefix()).toEqual(""); |
| 1077 | menu.prefix('el'); |
| 1078 | expect(menu.show()).toBe(true); |
| 1079 | |
| 1080 | expect(menu.prefix()).toEqual("el"); |
| 1081 | expect(menu._prefix.active()).toEqual(false); |
| 1082 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 1083 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1084 | expect(menu.shownItem(0).active()).toBe(true); |
| 1085 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 1086 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1087 | expect(menu.shownItem(1).active()).toBe(false); |
| 1088 | expect(menu.shownItem(2)).toBe(undefined); |
| 1089 | |
| 1090 | // Backward |
| 1091 | menu.prev(); |
| 1092 | expect(menu._prefix.active()).toEqual(true); |
| 1093 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 1094 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1095 | expect(menu.shownItem(0).active()).toBe(false); |
| 1096 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 1097 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1098 | expect(menu.shownItem(1).active()).toBe(false); |
| 1099 | expect(menu.shownItem(2)).toBe(undefined); |
| 1100 | |
| 1101 | |
| 1102 | // Forward |
| 1103 | menu.next(); |
| 1104 | expect(menu.prefix()).toEqual("el"); |
| 1105 | expect(menu._prefix.active()).toEqual(false); |
| 1106 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 1107 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1108 | expect(menu.shownItem(0).active()).toBe(true); |
| 1109 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 1110 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1111 | expect(menu.shownItem(1).active()).toBe(false); |
| 1112 | expect(menu.shownItem(2)).toBe(undefined); |
| 1113 | |
| 1114 | }); |
| 1115 | |
Akron | 47c086c | 2016-05-18 21:22:06 +0200 | [diff] [blame] | 1116 | it('should show screens by offset', function () { |
| 1117 | var menu = KorAP.HintMenu.create('cnx/', demolist); |
| 1118 | menu.limit(3); |
| 1119 | expect(menu.show()).toBe(true); |
| 1120 | |
| 1121 | expect(menu.shownItem(0).active()).toBe(false); |
| 1122 | expect(menu.shownItem(1).active()).toBe(false); |
| 1123 | expect(menu.shownItem(2).active()).toBe(false); |
| 1124 | |
Akron | 5240b8c | 2016-05-20 09:17:41 +0200 | [diff] [blame] | 1125 | // Highlight the first entry |
Akron | 47c086c | 2016-05-18 21:22:06 +0200 | [diff] [blame] | 1126 | menu.next(); |
| 1127 | |
| 1128 | expect(menu.shownItem(0).active()).toBe(true); |
| 1129 | expect(menu.shownItem(1).active()).toBe(false); |
| 1130 | expect(menu.shownItem(2).active()).toBe(false); |
| 1131 | |
Akron | 5240b8c | 2016-05-20 09:17:41 +0200 | [diff] [blame] | 1132 | // Highlight the second entry |
Akron | 47c086c | 2016-05-18 21:22:06 +0200 | [diff] [blame] | 1133 | menu.next(); |
| 1134 | |
| 1135 | expect(menu.shownItem(0).active()).toBe(false); |
| 1136 | expect(menu.shownItem(1).active()).toBe(true); |
| 1137 | expect(menu.shownItem(2).active()).toBe(false); |
| 1138 | expect(menu.shownItem(3)).toBe(undefined); |
| 1139 | |
| 1140 | expect(menu.shownItem(0).lcField()).toEqual(' titel'); |
| 1141 | expect(menu.shownItem(1).lcField()).toEqual(' untertitel'); |
| 1142 | |
Akron | 5240b8c | 2016-05-20 09:17:41 +0200 | [diff] [blame] | 1143 | // Move to first screen |
Akron | 47c086c | 2016-05-18 21:22:06 +0200 | [diff] [blame] | 1144 | menu.screen(0); |
Akron | 5240b8c | 2016-05-20 09:17:41 +0200 | [diff] [blame] | 1145 | expect(menu.shownItem(0).lcField()).toEqual(' titel'); |
| 1146 | expect(menu.shownItem(1).lcField()).toEqual(' untertitel'); |
Akron | 47c086c | 2016-05-18 21:22:06 +0200 | [diff] [blame] | 1147 | expect(menu.shownItem(0).active()).toBe(false); |
| 1148 | expect(menu.shownItem(1).active()).toBe(true); |
| 1149 | expect(menu.shownItem(2).active()).toBe(false); |
| 1150 | expect(menu.shownItem(3)).toBe(undefined); |
Akron | cb351d6 | 2016-05-19 23:10:33 +0200 | [diff] [blame] | 1151 | |
Akron | 5240b8c | 2016-05-20 09:17:41 +0200 | [diff] [blame] | 1152 | // Move to second screen |
Akron | 47c086c | 2016-05-18 21:22:06 +0200 | [diff] [blame] | 1153 | menu.screen(1); |
Akron | 5240b8c | 2016-05-20 09:17:41 +0200 | [diff] [blame] | 1154 | expect(menu.shownItem(0).lcField()).toEqual(' untertitel'); |
Akron | 47c086c | 2016-05-18 21:22:06 +0200 | [diff] [blame] | 1155 | expect(menu.shownItem(0).active()).toBe(true); |
Akron | 47c086c | 2016-05-18 21:22:06 +0200 | [diff] [blame] | 1156 | expect(menu.shownItem(1).active()).toBe(false); |
| 1157 | expect(menu.shownItem(2).active()).toBe(false); |
Akron | 5240b8c | 2016-05-20 09:17:41 +0200 | [diff] [blame] | 1158 | expect(menu.shownItem(3)).toBe(undefined); |
| 1159 | |
| 1160 | menu.screen(2); |
| 1161 | expect(menu.shownItem(0).lcField()).toEqual(' veröffentlichungsdatum'); |
| 1162 | expect(menu.shownItem(0).active()).toBe(false); |
| 1163 | expect(menu.shownItem(1).active()).toBe(false); |
| 1164 | expect(menu.shownItem(2).active()).toBe(false); |
| 1165 | expect(menu.shownItem(3)).toBe(undefined); |
| 1166 | |
| 1167 | menu.screen(1); |
| 1168 | expect(menu.shownItem(0).lcField()).toEqual(' untertitel'); |
| 1169 | expect(menu.shownItem(0).active()).toBe(true); |
| 1170 | expect(menu.shownItem(1).active()).toBe(false); |
| 1171 | expect(menu.shownItem(2).active()).toBe(false); |
| 1172 | expect(menu.shownItem(3)).toBe(undefined); |
Akron | 47c086c | 2016-05-18 21:22:06 +0200 | [diff] [blame] | 1173 | }); |
| 1174 | |
Akron | 6ed1399 | 2016-05-23 18:06:05 +0200 | [diff] [blame] | 1175 | it('should show screens by offset when prefixed', function () { |
| 1176 | var menu = KorAP.HintMenu.create('cnx/', demolist); |
| 1177 | menu.limit(3); |
| 1178 | expect(menu.prefix("e").show()).toBe(true); |
| 1179 | expect(menu.shownItem(0).active()).toBe(false); |
| 1180 | expect(menu.shownItem(1).active()).toBe(false); |
| 1181 | expect(menu.shownItem(2).active()).toBe(false); |
| 1182 | |
| 1183 | expect(menu.shownItem(0).element().innerHTML).toEqual('<strong>Tit<mark>e</mark>l</strong>'); |
| 1184 | menu.screen(1); |
| 1185 | expect(menu.shownItem(0).element().innerHTML).toEqual('<strong>Unt<mark>e</mark>rtit<mark>e</mark>l</strong>'); |
| 1186 | }); |
| 1187 | |
Akron | 47c086c | 2016-05-18 21:22:06 +0200 | [diff] [blame] | 1188 | |
Akron | 3c2730f | 2016-05-24 15:08:29 +0200 | [diff] [blame] | 1189 | it('should be page downable', function () { |
| 1190 | var menu = KorAP.OwnMenu.create(demolonglist); |
| 1191 | menu.limit(3); |
| 1192 | |
| 1193 | expect(menu.show(0)).toBe(true); |
| 1194 | |
| 1195 | expect(menu.shownItem(0).active()).toBe(true); |
| 1196 | expect(menu.shownItem(0).lcField()).toEqual(' titel'); |
| 1197 | expect(menu.shownItem(1).active()).toBe(false); |
| 1198 | expect(menu.shownItem(2).active()).toBe(false); |
| 1199 | expect(menu.shownItem(3)).toBe(undefined); |
| 1200 | |
| 1201 | menu.pageDown(); |
| 1202 | |
| 1203 | expect(menu.shownItem(0).lcField()).toEqual(' länge'); |
| 1204 | expect(menu.shownItem(0).active()).toBe(false); |
| 1205 | expect(menu.shownItem(1).active()).toBe(false); |
| 1206 | expect(menu.shownItem(2).active()).toBe(false); |
| 1207 | |
| 1208 | menu.pageDown(); |
| 1209 | |
| 1210 | expect(menu.shownItem(0).lcField()).toEqual(' corpusid'); |
| 1211 | expect(menu.shownItem(0).active()).toBe(false); |
| 1212 | expect(menu.shownItem(1).active()).toBe(false); |
| 1213 | expect(menu.shownItem(2).active()).toBe(false); |
| 1214 | |
| 1215 | // Doesn't matter |
| 1216 | menu.pageDown(); |
| 1217 | |
| 1218 | expect(menu.shownItem(0).lcField()).toEqual(' corpusid'); |
| 1219 | expect(menu.shownItem(0).active()).toBe(false); |
| 1220 | expect(menu.shownItem(1).active()).toBe(false); |
| 1221 | expect(menu.shownItem(2).active()).toBe(false); |
| 1222 | }); |
| 1223 | |
Akron | 6ac5844 | 2016-05-24 16:52:29 +0200 | [diff] [blame] | 1224 | it('should be page downable with prefix', function () { |
| 1225 | var menu = KorAP.OwnMenu.create(demolonglist); |
| 1226 | menu.limit(3); |
| 1227 | |
| 1228 | expect(menu.prefix('e').show(0)).toBe(true); |
| 1229 | |
| 1230 | expect(menu.shownItem(0).active()).toBe(true); |
| 1231 | expect(menu.shownItem(0).lcField()).toEqual(' titel'); |
| 1232 | expect(menu.shownItem(1).active()).toBe(false); |
| 1233 | expect(menu.shownItem(1).lcField()).toEqual(' untertitel'); |
| 1234 | expect(menu.shownItem(2).active()).toBe(false); |
| 1235 | expect(menu.shownItem(2).lcField()).toEqual(' veröffentlichungsdatum'); |
| 1236 | expect(menu.shownItem(3)).toBe(undefined); |
| 1237 | |
| 1238 | menu.pageDown(); |
| 1239 | |
| 1240 | expect(menu.shownItem(0).active()).toBe(false); |
| 1241 | expect(menu.shownItem(0).lcField()).toEqual(' länge'); |
| 1242 | expect(menu.shownItem(1).active()).toBe(false); |
| 1243 | expect(menu.shownItem(1).lcField()).toEqual(' genre'); |
| 1244 | expect(menu.shownItem(2).active()).toBe(false); |
| 1245 | expect(menu.shownItem(2).lcField()).toEqual(' textid'); |
| 1246 | |
| 1247 | // Doesn't matter |
| 1248 | menu.pageDown(); |
| 1249 | |
| 1250 | expect(menu.shownItem(0).active()).toBe(false); |
| 1251 | expect(menu.shownItem(0).lcField()).toEqual(' länge'); |
| 1252 | expect(menu.shownItem(1).active()).toBe(false); |
| 1253 | expect(menu.shownItem(1).lcField()).toEqual(' genre'); |
| 1254 | expect(menu.shownItem(2).active()).toBe(false); |
| 1255 | expect(menu.shownItem(2).lcField()).toEqual(' textid'); |
| 1256 | }); |
| 1257 | |
| 1258 | |
Akron | 3c2730f | 2016-05-24 15:08:29 +0200 | [diff] [blame] | 1259 | it('should be page upable', function () { |
| 1260 | var menu = KorAP.OwnMenu.create(demolonglist); |
| 1261 | menu.limit(3); |
| 1262 | |
| 1263 | // Choose the final value |
| 1264 | expect(menu.show(1000)).toBe(true); |
| 1265 | |
| 1266 | expect(menu.shownItem(0).active()).toBe(false); |
| 1267 | expect(menu.shownItem(1).active()).toBe(false); |
| 1268 | expect(menu.shownItem(2).active()).toBe(true); |
| 1269 | expect(menu.shownItem(2).lcField()).toEqual(' textid'); |
| 1270 | expect(menu.shownItem(3)).toBe(undefined); |
| 1271 | |
| 1272 | menu.pageUp(); |
| 1273 | |
| 1274 | expect(menu.shownItem(0).lcField()).toEqual(' länge'); |
| 1275 | expect(menu.shownItem(0).active()).toBe(false); |
| 1276 | expect(menu.shownItem(1).active()).toBe(false); |
| 1277 | expect(menu.shownItem(2).active()).toBe(false); |
| 1278 | |
| 1279 | menu.pageUp(); |
| 1280 | |
| 1281 | expect(menu.shownItem(0).lcField()).toEqual(' titel'); |
| 1282 | expect(menu.shownItem(0).active()).toBe(false); |
| 1283 | expect(menu.shownItem(1).active()).toBe(false); |
| 1284 | expect(menu.shownItem(2).active()).toBe(false); |
| 1285 | |
| 1286 | // Doesn't matter |
| 1287 | menu.pageUp(); |
| 1288 | |
| 1289 | expect(menu.shownItem(0).lcField()).toEqual(' titel'); |
| 1290 | expect(menu.shownItem(0).active()).toBe(false); |
| 1291 | expect(menu.shownItem(1).active()).toBe(false); |
| 1292 | expect(menu.shownItem(2).active()).toBe(false); |
| 1293 | }); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1294 | |
Akron | 6ac5844 | 2016-05-24 16:52:29 +0200 | [diff] [blame] | 1295 | it('should be page upable with prefix', function () { |
| 1296 | var menu = KorAP.OwnMenu.create(demolonglist); |
| 1297 | menu.limit(3); |
| 1298 | |
| 1299 | // Choose the final value |
| 1300 | expect(menu.prefix("e").show(1000)).toBe(true); |
| 1301 | |
| 1302 | expect(menu.shownItem(0).active()).toBe(false); |
| 1303 | expect(menu.shownItem(0).lcField()).toEqual(' länge'); |
| 1304 | expect(menu.shownItem(1).active()).toBe(false); |
| 1305 | expect(menu.shownItem(1).lcField()).toEqual(' genre'); |
| 1306 | expect(menu.shownItem(2).active()).toBe(true); |
| 1307 | expect(menu.shownItem(2).lcField()).toEqual(' textid'); |
| 1308 | expect(menu.shownItem(3)).toBe(undefined); |
| 1309 | |
| 1310 | menu.pageUp(); |
| 1311 | |
| 1312 | expect(menu.shownItem(0).lcField()).toEqual(' titel'); |
| 1313 | expect(menu.shownItem(0).active()).toBe(false); |
| 1314 | expect(menu.shownItem(1).active()).toBe(false); |
| 1315 | expect(menu.shownItem(1).lcField()).toEqual(' untertitel'); |
| 1316 | expect(menu.shownItem(2).active()).toBe(false); |
| 1317 | expect(menu.shownItem(2).lcField()).toEqual(' veröffentlichungsdatum'); |
| 1318 | |
| 1319 | // Doesn't matter |
| 1320 | menu.pageUp(); |
| 1321 | |
| 1322 | expect(menu.shownItem(0).lcField()).toEqual(' titel'); |
| 1323 | expect(menu.shownItem(0).active()).toBe(false); |
| 1324 | expect(menu.shownItem(1).active()).toBe(false); |
| 1325 | expect(menu.shownItem(1).lcField()).toEqual(' untertitel'); |
| 1326 | expect(menu.shownItem(2).active()).toBe(false); |
| 1327 | expect(menu.shownItem(2).lcField()).toEqual(' veröffentlichungsdatum'); |
| 1328 | }); |
| 1329 | |
Akron | 0b92f69 | 2016-05-25 22:37:13 +0200 | [diff] [blame] | 1330 | it('should scroll to a chosen value (1)', function () { |
Akron | 37513a6 | 2015-11-17 01:07:11 +0100 | [diff] [blame] | 1331 | var menu = KorAP.OwnMenu.create(demolist); |
| 1332 | menu.limit(3); |
Akron | 6ed1399 | 2016-05-23 18:06:05 +0200 | [diff] [blame] | 1333 | |
| 1334 | // Choose value 1 |
| 1335 | expect(menu.show(1)).toBe(true); |
| 1336 | |
| 1337 | expect(menu.shownItem(0).active()).toBe(false); |
| 1338 | expect(menu.shownItem(0).lcField()).toEqual(' titel'); |
| 1339 | expect(menu.shownItem(1).active()).toBe(true); |
| 1340 | expect(menu.shownItem(2).active()).toBe(false); |
| 1341 | expect(menu.shownItem(3)).toBe(undefined); |
| 1342 | |
| 1343 | // Choose value 2 |
| 1344 | expect(menu.show(2)).toBe(true); |
| 1345 | |
| 1346 | expect(menu.shownItem(0).active()).toBe(false); |
| 1347 | expect(menu.shownItem(0).lcField()).toEqual(' titel'); |
| 1348 | expect(menu.shownItem(1).active()).toBe(false); |
| 1349 | expect(menu.shownItem(2).active()).toBe(true); |
| 1350 | expect(menu.shownItem(3)).toBe(undefined); |
Akron | 37513a6 | 2015-11-17 01:07:11 +0100 | [diff] [blame] | 1351 | }); |
| 1352 | |
Akron | 0b92f69 | 2016-05-25 22:37:13 +0200 | [diff] [blame] | 1353 | it('should scroll to a chosen value (2)', function () { |
| 1354 | var menu = KorAP.OwnMenu.create(demolonglist); |
| 1355 | |
| 1356 | // Choose value 3 |
| 1357 | expect(menu.limit(3).show(3)).toBe(true); |
| 1358 | expect(menu.shownItem(0).lcField()).toEqual(' länge'); |
| 1359 | expect(menu.shownItem(0).active()).toBe(true); |
| 1360 | expect(menu.shownItem(1).active()).toBe(false); |
| 1361 | expect(menu.shownItem(2).active()).toBe(false); |
| 1362 | expect(menu.shownItem(3)).toBe(undefined); |
| 1363 | }); |
| 1364 | |
| 1365 | xit('should scroll to a chosen value after prefixing, if the chosen value is live'); |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 1366 | }); |
| 1367 | |
| 1368 | describe('KorAP.Prefix', function () { |
| 1369 | it('should be initializable', function () { |
| 1370 | var p = prefixClass.create(); |
| 1371 | expect(p.element().classList.contains('pref')).toBeTruthy(); |
| 1372 | expect(p.isSet()).not.toBeTruthy(); |
| 1373 | |
| 1374 | /* |
| 1375 | expect(mi.lcField()).toEqual(' baum'); |
| 1376 | */ |
| 1377 | |
| 1378 | }); |
| 1379 | |
| 1380 | it('should be modifiable', function () { |
| 1381 | var p = prefixClass.create(); |
| 1382 | expect(p.value()).toEqual(''); |
| 1383 | expect(p.element().firstChild).toBeNull(); |
| 1384 | |
| 1385 | // Set string |
| 1386 | expect(p.value('Test')).toEqual('Test'); |
| 1387 | expect(p.value()).toEqual('Test'); |
| 1388 | expect(p.element().firstChild.nodeValue).toEqual('Test'); |
| 1389 | |
| 1390 | // Add string |
| 1391 | expect(p.add('ified')).toEqual('Testified'); |
| 1392 | expect(p.value()).toEqual('Testified'); |
| 1393 | expect(p.element().firstChild.nodeValue).toEqual('Testified'); |
| 1394 | |
| 1395 | // Clear string |
| 1396 | p.clear(); |
| 1397 | expect(p.value()).toEqual(''); |
| 1398 | expect(p.element().firstChild).toBeNull(); |
| 1399 | |
| 1400 | // Set string |
| 1401 | expect(p.value('Test')).toEqual('Test'); |
| 1402 | expect(p.value()).toEqual('Test'); |
| 1403 | expect(p.element().firstChild.nodeValue).toEqual('Test'); |
| 1404 | |
| 1405 | expect(p.chop()).toEqual('Tes'); |
| 1406 | expect(p.value()).toEqual('Tes'); |
| 1407 | expect(p.element().firstChild.nodeValue).toEqual('Tes'); |
| 1408 | |
| 1409 | expect(p.chop()).toEqual('Te'); |
| 1410 | expect(p.value()).toEqual('Te'); |
| 1411 | expect(p.element().firstChild.nodeValue).toEqual('Te'); |
| 1412 | |
| 1413 | expect(p.chop()).toEqual('T'); |
| 1414 | expect(p.value()).toEqual('T'); |
| 1415 | expect(p.element().firstChild.nodeValue).toEqual('T'); |
| 1416 | |
| 1417 | expect(p.chop()).toEqual(''); |
| 1418 | expect(p.value()).toEqual(''); |
| 1419 | expect(p.element().firstChild).toBeNull(); |
| 1420 | }); |
| 1421 | |
| 1422 | it('should be activatable', function () { |
| 1423 | var p = prefixClass.create(); |
| 1424 | expect(p.value()).toEqual(''); |
| 1425 | expect(p.element().firstChild).toBeNull(); |
| 1426 | |
| 1427 | expect(p.value('Test')).toEqual('Test'); |
| 1428 | expect(p.element().firstChild.nodeValue).toEqual('Test'); |
| 1429 | |
| 1430 | expect(p.active()).not.toBeTruthy(); |
| 1431 | expect(p.element().classList.contains('active')).not.toBeTruthy(); |
| 1432 | |
| 1433 | p.active(true); |
| 1434 | expect(p.active()).toBeTruthy(); |
| 1435 | expect(p.element().classList.contains('active')).toBeTruthy(); |
| 1436 | }); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 1437 | }); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame] | 1438 | |
| 1439 | describe('KorAP.LengthField', function () { |
| 1440 | it('should be initializable', function () { |
| 1441 | var l = lengthFieldClass.create(); |
| 1442 | expect(l.element().classList.contains('lengthField')).toBeTruthy(); |
| 1443 | expect(l.element().children.length).toEqual(0); |
| 1444 | }); |
| 1445 | |
| 1446 | it('should be extensible', function () { |
| 1447 | var l = lengthFieldClass.create(); |
Akron | 1ff3ac2 | 2016-04-28 16:30:45 +0200 | [diff] [blame] | 1448 | l.add(['Baum']); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame] | 1449 | expect(l.element().children.length).toEqual(1); |
| 1450 | expect(l.element().children[0].nodeName).toEqual('SPAN'); |
Akron | 1ff3ac2 | 2016-04-28 16:30:45 +0200 | [diff] [blame] | 1451 | expect(l.element().children[0].textContent).toEqual('Baum--'); |
| 1452 | l.add(['Fragezeichen']); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame] | 1453 | expect(l.element().children.length).toEqual(2); |
| 1454 | expect(l.element().children[1].nodeName).toEqual('SPAN'); |
Akron | 1ff3ac2 | 2016-04-28 16:30:45 +0200 | [diff] [blame] | 1455 | expect(l.element().children[1].textContent).toEqual('Fragezeichen--'); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame] | 1456 | }); |
| 1457 | |
| 1458 | it('should be correctly initializable', function () { |
| 1459 | var list = [ |
| 1460 | ["Constituency"], |
| 1461 | ["Lemma"], |
| 1462 | ["Morphology"], |
| 1463 | ["Part-of-Speech"], |
| 1464 | ["Syntax"] |
| 1465 | ]; |
| 1466 | |
| 1467 | var menu = KorAP.OwnMenu.create(list); |
| 1468 | |
| 1469 | expect(menu.lengthField().element().children.length).toEqual(5); |
| 1470 | }); |
| 1471 | }); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 1472 | |
| 1473 | describe('KorAP.Slider', function () { |
Akron | 97752a7 | 2016-05-25 14:43:07 +0200 | [diff] [blame] | 1474 | |
| 1475 | var demolonglist = [ |
| 1476 | ['Titel', 'title'], |
| 1477 | ['Untertitel', 'subTitle'], |
| 1478 | ['Veröffentlichungsdatum', 'pubDate'], |
| 1479 | ['Länge', 'length'], |
| 1480 | ['Autor', 'author'], |
| 1481 | ['Genre', 'genre'], |
| 1482 | ['corpusID', 'corpusID'], |
| 1483 | ['docID', 'docID'], |
| 1484 | ['textID', 'textID'], |
| 1485 | ]; |
| 1486 | |
Akron | 6ed1399 | 2016-05-23 18:06:05 +0200 | [diff] [blame] | 1487 | it('should correctly be initializable', function () { |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 1488 | var list = [ |
| 1489 | ["Constituency"], |
| 1490 | ["Lemma"], |
| 1491 | ["Morphology"], |
| 1492 | ["Part-of-Speech"], |
| 1493 | ["Syntax"] |
| 1494 | ]; |
| 1495 | |
| 1496 | var menu = KorAP.OwnMenu.create(list); |
| 1497 | |
| 1498 | menu._firstActive = true; |
| 1499 | menu.limit(3); |
| 1500 | |
| 1501 | expect(menu.show()).toBe(true); |
| 1502 | |
| 1503 | expect(menu.shownItem(0).active()).toBe(true); |
| 1504 | expect(menu.shownItem(1).active()).toBe(false); |
| 1505 | expect(menu.shownItem(2).active()).toBe(false); |
| 1506 | expect(menu.slider().offset()).toEqual(0); |
| 1507 | expect(menu.position).toEqual(0); |
Akron | 6ed1399 | 2016-05-23 18:06:05 +0200 | [diff] [blame] | 1508 | }); |
| 1509 | |
| 1510 | it('should correctly move on arrow keys', function () { |
| 1511 | var list = [ |
| 1512 | ["Constituency"], |
| 1513 | ["Lemma"], |
| 1514 | ["Morphology"], |
| 1515 | ["Part-of-Speech"], |
| 1516 | ["Syntax"] |
| 1517 | ]; |
| 1518 | |
| 1519 | var menu = KorAP.OwnMenu.create(list); |
| 1520 | |
| 1521 | menu._firstActive = true; |
| 1522 | menu.limit(3); |
| 1523 | |
| 1524 | expect(menu.show()).toBe(true); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 1525 | |
| 1526 | menu.next(); |
| 1527 | expect(menu.shownItem(0).active()).toBe(false); |
| 1528 | expect(menu.shownItem(1).active()).toBe(true); |
| 1529 | expect(menu.shownItem(2).active()).toBe(false); |
| 1530 | expect(menu.slider().offset()).toEqual(0); |
| 1531 | expect(menu.position).toEqual(1); |
| 1532 | |
| 1533 | menu.next(); |
| 1534 | expect(menu.shownItem(0).active()).toBe(false); |
| 1535 | expect(menu.shownItem(1).active()).toBe(false); |
| 1536 | expect(menu.shownItem(2).active()).toBe(true); |
| 1537 | expect(menu.slider().offset()).toEqual(0); |
| 1538 | expect(menu.position).toEqual(2); |
| 1539 | |
| 1540 | menu.next(); |
| 1541 | expect(menu.shownItem(0).active()).toBe(false); |
| 1542 | expect(menu.shownItem(1).active()).toBe(false); |
| 1543 | expect(menu.shownItem(2).active()).toBe(true); |
| 1544 | expect(menu.slider().offset()).toEqual(1); |
| 1545 | expect(menu.position).toEqual(3); |
| 1546 | |
| 1547 | menu.next(); |
| 1548 | expect(menu.shownItem(0).active()).toBe(false); |
| 1549 | expect(menu.shownItem(1).active()).toBe(false); |
| 1550 | expect(menu.shownItem(2).active()).toBe(true); |
| 1551 | expect(menu.slider().offset()).toEqual(2); |
| 1552 | expect(menu.position).toEqual(4); |
| 1553 | |
| 1554 | menu.next(); |
| 1555 | expect(menu.shownItem(0).active()).toBe(true); |
| 1556 | expect(menu.shownItem(1).active()).toBe(false); |
| 1557 | expect(menu.shownItem(2).active()).toBe(false); |
| 1558 | expect(menu.slider().offset()).toEqual(0); |
| 1559 | expect(menu.position).toEqual(0); |
| 1560 | |
| 1561 | expect(menu.slider()._slider.style.height).toEqual('60%'); |
Akron | 6ed1399 | 2016-05-23 18:06:05 +0200 | [diff] [blame] | 1562 | }); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 1563 | |
Akron | 97752a7 | 2016-05-25 14:43:07 +0200 | [diff] [blame] | 1564 | it('should correctly resize on prefixing', function () { |
| 1565 | var menu = KorAP.OwnMenu.create(demolonglist); |
| 1566 | menu._firstActive = true; |
| 1567 | menu.limit(3); |
| 1568 | |
| 1569 | expect(menu.show()).toBe(true); |
| 1570 | expect(menu.slider().offset()).toEqual(0); |
| 1571 | expect(menu.slider().length()).toEqual(9); |
| 1572 | |
| 1573 | expect(menu.prefix("e").show()).toBe(true); |
| 1574 | expect(menu.slider().length()).toEqual(6); |
| 1575 | |
| 1576 | expect(menu.prefix("el").show()).toBe(true); |
| 1577 | expect(menu.slider().length()).toEqual(2); |
| 1578 | |
| 1579 | expect(menu.prefix("e").show()).toBe(true); |
| 1580 | expect(menu.slider().length()).toEqual(6); |
| 1581 | |
| 1582 | expect(menu.prefix("").show()).toBe(true); |
| 1583 | expect(menu.slider().length()).toEqual(9); |
| 1584 | }); |
| 1585 | |
| 1586 | |
Akron | 6ed1399 | 2016-05-23 18:06:05 +0200 | [diff] [blame] | 1587 | it('should correctly move the list on mousemove', function () { |
| 1588 | var list = [ |
| 1589 | ["Constituency"], |
| 1590 | ["Lemma"], |
| 1591 | ["Morphology"], |
| 1592 | ["Part-of-Speech"], |
| 1593 | ["Syntax"] |
| 1594 | ]; |
| 1595 | |
| 1596 | var menu = KorAP.OwnMenu.create(list); |
| 1597 | |
| 1598 | menu._firstActive = true; |
| 1599 | menu.limit(3); |
| 1600 | |
| 1601 | expect(menu.show()).toBe(true); |
| 1602 | |
| 1603 | expect(menu.shownItem(0).active()).toBe(true); |
| 1604 | expect(menu.shownItem(1).active()).toBe(false); |
| 1605 | expect(menu.shownItem(2).active()).toBe(false); |
| 1606 | expect(menu.slider().offset()).toEqual(0); |
| 1607 | |
| 1608 | // This will normally be done on |
| 1609 | menu.slider()._rulerHeight = 100; |
| 1610 | menu.slider()._sliderHeight = 40; |
Akron | 71b91e4 | 2016-06-01 22:12:43 +0200 | [diff] [blame] | 1611 | menu.slider()._event.initOffset = 0; |
Akron | 6ed1399 | 2016-05-23 18:06:05 +0200 | [diff] [blame] | 1612 | expect(menu.slider().length()).toEqual(5); |
| 1613 | |
| 1614 | menu.slider().movetoRel(10); |
| 1615 | expect(menu.slider().offset()).toEqual(0); |
Akron | 71b91e4 | 2016-06-01 22:12:43 +0200 | [diff] [blame] | 1616 | |
Akron | 6ed1399 | 2016-05-23 18:06:05 +0200 | [diff] [blame] | 1617 | expect(menu.shownItem(0).active()).toBe(true); |
| 1618 | expect(menu.shownItem(0).lcField()).toEqual(' constituency'); |
| 1619 | menu.slider().movetoRel(24); |
| 1620 | expect(menu.slider().offset()).toEqual(0); |
| 1621 | menu.slider().movetoRel(25); |
| 1622 | expect(menu.slider().offset()).toEqual(0); |
| 1623 | |
| 1624 | menu.slider().movetoRel(30); |
| 1625 | expect(menu.slider().offset()).toEqual(1); |
| 1626 | menu.slider().movetoRel(59); |
| 1627 | expect(menu.slider().offset()).toEqual(1); |
| 1628 | expect(menu.shownItem(0).active()).toBe(false); |
| 1629 | expect(menu.shownItem(0).lcField()).toEqual(' lemma'); |
| 1630 | |
| 1631 | // Everything > 60 is offset 2 |
| 1632 | menu.slider().movetoRel(60); |
| 1633 | expect(menu.slider().offset()).toEqual(2); |
| 1634 | menu.slider().movetoRel(180); |
| 1635 | expect(menu.slider().offset()).toEqual(2); |
| 1636 | expect(menu.shownItem(0).active()).toBe(false); |
| 1637 | expect(menu.shownItem(0).lcField()).toEqual(' morphology'); |
Akron | 5a1f5bb | 2016-05-23 22:00:39 +0200 | [diff] [blame] | 1638 | |
| 1639 | expect(menu.shownItem(1).active()).toBe(false); |
| 1640 | expect(menu.shownItem(2).active()).toBe(false); |
| 1641 | |
| 1642 | // When the active cursor moves again - scroll to viewport |
| 1643 | // cursor is before viewport |
| 1644 | menu.next(); |
| 1645 | expect(menu.shownItem(0).active()).toBe(true); |
| 1646 | expect(menu.shownItem(0).lcField()).toEqual(' lemma'); |
| 1647 | expect(menu.shownItem(1).active()).toBe(false); |
| 1648 | expect(menu.shownItem(2).active()).toBe(false); |
| 1649 | |
| 1650 | menu.next(); |
| 1651 | menu.next(); |
| 1652 | expect(menu.shownItem(0).active()).toBe(false); |
| 1653 | expect(menu.shownItem(0).lcField()).toEqual(' lemma'); |
| 1654 | expect(menu.shownItem(1).active()).toBe(false); |
| 1655 | expect(menu.shownItem(1).lcField()).toEqual(' morphology'); |
| 1656 | expect(menu.shownItem(2).active()).toBe(true); |
| 1657 | expect(menu.shownItem(2).lcField()).toEqual(' part-of-speech'); |
| 1658 | |
| 1659 | menu.slider().movetoRel(0); |
| 1660 | expect(menu.slider().offset()).toEqual(0); |
| 1661 | expect(menu.shownItem(0).active()).toBe(false); |
| 1662 | expect(menu.shownItem(0).lcField()).toEqual(' constituency'); |
| 1663 | expect(menu.shownItem(1).active()).toBe(false); |
| 1664 | expect(menu.shownItem(1).lcField()).toEqual(' lemma'); |
| 1665 | expect(menu.shownItem(2).active()).toBe(false); |
| 1666 | expect(menu.shownItem(2).lcField()).toEqual(' morphology'); |
| 1667 | |
| 1668 | // cursor is after viewport |
| 1669 | menu.next(); |
| 1670 | expect(menu.slider().offset()).toEqual(2); |
| 1671 | expect(menu.shownItem(0).active()).toBe(false); |
| 1672 | expect(menu.shownItem(0).lcField()).toEqual(' morphology'); |
| 1673 | expect(menu.shownItem(1).active()).toBe(false); |
| 1674 | expect(menu.shownItem(1).lcField()).toEqual(' part-of-speech'); |
| 1675 | expect(menu.shownItem(2).active()).toBe(true); |
| 1676 | expect(menu.shownItem(2).lcField()).toEqual(' syntax'); |
| 1677 | |
| 1678 | menu.slider().movetoRel(0); |
| 1679 | expect(menu.slider().offset()).toEqual(0); |
| 1680 | expect(menu.shownItem(0).active()).toBe(false); |
| 1681 | expect(menu.shownItem(0).lcField()).toEqual(' constituency'); |
| 1682 | expect(menu.shownItem(1).active()).toBe(false); |
| 1683 | expect(menu.shownItem(1).lcField()).toEqual(' lemma'); |
| 1684 | expect(menu.shownItem(2).active()).toBe(false); |
| 1685 | expect(menu.shownItem(2).lcField()).toEqual(' morphology'); |
| 1686 | |
| 1687 | menu.prev(); |
| 1688 | expect(menu.slider().offset()).toEqual(2); |
| 1689 | expect(menu.shownItem(0).lcField()).toEqual(' morphology'); |
| 1690 | expect(menu.shownItem(0).active()).toBe(false); |
| 1691 | expect(menu.shownItem(1).lcField()).toEqual(' part-of-speech'); |
| 1692 | expect(menu.shownItem(1).active()).toBe(true); |
| 1693 | expect(menu.shownItem(2).lcField()).toEqual(' syntax'); |
| 1694 | expect(menu.shownItem(2).active()).toBe(false); |
| 1695 | |
| 1696 | menu.prev(); |
| 1697 | menu.prev(); |
| 1698 | expect(menu.slider().offset()).toEqual(1); |
| 1699 | expect(menu.shownItem(0).lcField()).toEqual(' lemma'); |
| 1700 | expect(menu.shownItem(0).active()).toBe(true); |
| 1701 | expect(menu.shownItem(1).lcField()).toEqual(' morphology'); |
| 1702 | expect(menu.shownItem(1).active()).toBe(false); |
| 1703 | expect(menu.shownItem(2).lcField()).toEqual(' part-of-speech'); |
| 1704 | expect(menu.shownItem(2).active()).toBe(false); |
| 1705 | |
| 1706 | menu.slider().movetoRel(100); |
| 1707 | expect(menu.slider().offset()).toEqual(2); |
| 1708 | expect(menu.shownItem(0).lcField()).toEqual(' morphology'); |
| 1709 | expect(menu.shownItem(0).active()).toBe(false); |
| 1710 | expect(menu.shownItem(1).lcField()).toEqual(' part-of-speech'); |
| 1711 | expect(menu.shownItem(1).active()).toBe(false); |
| 1712 | expect(menu.shownItem(2).lcField()).toEqual(' syntax'); |
| 1713 | expect(menu.shownItem(2).active()).toBe(false); |
| 1714 | |
| 1715 | menu.prev(); |
| 1716 | expect(menu.slider().offset()).toEqual(0); |
| 1717 | expect(menu.shownItem(0).lcField()).toEqual(' constituency'); |
| 1718 | expect(menu.shownItem(0).active()).toBe(true); |
| 1719 | expect(menu.shownItem(1).lcField()).toEqual(' lemma'); |
| 1720 | expect(menu.shownItem(1).active()).toBe(false); |
| 1721 | expect(menu.shownItem(2).lcField()).toEqual(' morphology'); |
| 1722 | expect(menu.shownItem(2).active()).toBe(false); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 1723 | }); |
| 1724 | }); |
Akron | 7524be1 | 2016-06-01 17:31:33 +0200 | [diff] [blame] | 1725 | |
| 1726 | describe('KorAP.MenuBenchmark', function () { |
| 1727 | var menu = menuClass.create([ |
| 1728 | ['Titel', 'title'], |
| 1729 | ['Untertitel', 'subTitle'], |
| 1730 | ['Veröffentlichungsdatum', 'pubDate'], |
| 1731 | ['Länge', 'length'], |
| 1732 | ['Autor', 'author'] |
| 1733 | ]); |
| 1734 | |
| 1735 | menu.limit(3).show(); |
| 1736 | |
| 1737 | // Some actions |
| 1738 | menu.next(); |
| 1739 | menu.next(); |
| 1740 | menu.prev(); |
| 1741 | menu.prev(); |
| 1742 | menu.prev(); |
| 1743 | |
| 1744 | menu.pageDown(); |
| 1745 | menu.pageUp(); |
| 1746 | |
| 1747 | // There is no fourth item in the list! |
| 1748 | menu.prefix('e').show(4); |
| 1749 | menu.next(); |
| 1750 | menu.next(); |
| 1751 | menu.prev(); |
| 1752 | menu.prev(); |
| 1753 | menu.prev(); |
| 1754 | }); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 1755 | }); |