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