Akron | fac1647 | 2018-07-26 16:47:21 +0200 | [diff] [blame] | 1 | define(['hint', 'hint/input', 'hint/contextanalyzer', 'hint/menu', 'hint/item'], function (hintClass, inputClass, contextClass, menuClass, menuItemClass) { |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 2 | |
Akron | fac1647 | 2018-07-26 16:47:21 +0200 | [diff] [blame] | 3 | function emitKeyboardEvent (element, type, keyCode) { |
| 4 | // event type : keydown, keyup, keypress |
| 5 | // http://stackoverflow.com/questions/596481/simulate-javascript-key-events |
| 6 | // http://stackoverflow.com/questions/961532/firing-a-keyboard-event-in-javascript |
| 7 | var keyboardEvent = document.createEvent("KeyboardEvent"); |
| 8 | var initMethod = typeof keyboardEvent.initKeyboardEvent !== 'undefined' ? |
| 9 | "initKeyboardEvent" : "initKeyEvent"; |
| 10 | keyboardEvent[initMethod]( |
| 11 | type, |
| 12 | true, // bubbles |
| 13 | true, // cancelable |
| 14 | window, // viewArg: should be window |
| 15 | false, // ctrlKeyArg |
| 16 | false, // altKeyArg |
| 17 | false, // shiftKeyArg |
| 18 | false, // metaKeyArg |
| 19 | keyCode, // keyCodeArg : unsigned long the virtual key code, else 0 |
| 20 | 0 // charCodeArgs : unsigned long the Unicode character |
| 21 | // associated with the depressed key, else 0 |
| 22 | ); |
| 23 | element.dispatchEvent(keyboardEvent); |
| 24 | }; |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 25 | |
Akron | fac1647 | 2018-07-26 16:47:21 +0200 | [diff] [blame] | 26 | var afterAllFunc = function () { |
| 27 | try { |
| 28 | var mirrors = document.querySelectorAll(".hint.mirror"); |
| 29 | for (var i in mirrors) { |
| 30 | mirrors[i].parentNode.removeChild(mirrors[i]) |
| 31 | }; |
| 32 | } |
| 33 | catch (e) {}; |
| 34 | |
| 35 | var body = document.body; |
| 36 | for (var i in body.children) { |
| 37 | if (body.children[i].nodeType && body.children[i].nodeType === 1) { |
| 38 | if (!body.children[i].classList.contains("jasmine_html-reporter")) { |
| 39 | body.removeChild(body.children[i]); |
| 40 | }; |
| 41 | }; |
| 42 | }; |
| 43 | KorAP.API.getMatchInfo = undefined; |
| 44 | KorAP.context = undefined; |
| 45 | // KorAP.annotationHelper = undefined; |
| 46 | }; |
| 47 | |
| 48 | var beforeAllFunc = function () { |
| 49 | KorAP.annotationHelper = KorAP.annotationHelper || {}; |
| 50 | KorAP.annotationHelper["-"] = [ |
| 51 | ["Base Annotation", "base/s=", "Structure"], |
| 52 | ["CoreNLP", "corenlp/", "Constituency, Named Entities, Part-of-Speech"] |
| 53 | ]; |
| 54 | KorAP.annotationHelper["corenlp/"] = [ |
| 55 | ["Named Entity", "ne=" , "Combined"], |
| 56 | ["Named Entity", "ne_dewac_175m_600=" , "ne_dewac_175m_600"], |
| 57 | ["Named Entity", "ne_hgc_175m_600=", "ne_hgc_175m_600"] |
| 58 | ]; |
| 59 | }; |
Nils Diewald | 5c5a747 | 2015-04-02 22:13:38 +0000 | [diff] [blame] | 60 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 61 | describe('KorAP.InputField', function () { |
Akron | fac1647 | 2018-07-26 16:47:21 +0200 | [diff] [blame] | 62 | beforeAll(beforeAllFunc); |
| 63 | afterAll(afterAllFunc); |
Akron | 5336fd4 | 2020-10-09 18:13:51 +0200 | [diff] [blame] | 64 | let input; |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame] | 65 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 66 | beforeEach(function () { |
| 67 | input = document.createElement("input"); |
| 68 | input.setAttribute('type', "text"); |
| 69 | input.setAttribute("value", "abcdefghijklmno"); |
| 70 | input.style.position = 'absolute'; |
| 71 | document.getElementsByTagName('body')[0].appendChild(input); |
| 72 | input.style.top = "20px"; |
| 73 | input.style.left = "30px"; |
| 74 | input.focus(); |
| 75 | input.selectionStart = 5; |
Nils Diewald | 5c5a747 | 2015-04-02 22:13:38 +0000 | [diff] [blame] | 76 | }); |
| 77 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 78 | afterEach(function () { |
| 79 | document.getElementsByTagName("body")[0].removeChild( |
Akron | 95abaf4 | 2018-04-26 15:33:22 +0200 | [diff] [blame] | 80 | input |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 81 | ); |
| 82 | }); |
Nils Diewald | 5c5a747 | 2015-04-02 22:13:38 +0000 | [diff] [blame] | 83 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 84 | it('should be initializable', function () { |
| 85 | // Supports: context, searchField |
| 86 | var inputField = inputClass.create(input); |
| 87 | expect(inputField._element).not.toBe(undefined); |
| 88 | }); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 89 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 90 | it('should have text', function () { |
| 91 | expect(input.value).toEqual('abcdefghijklmno'); |
| 92 | var inputField = inputClass.create(input); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 93 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 94 | expect(inputField.value()).toEqual("abcdefghijklmno"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 95 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 96 | expect(input.selectionStart).toEqual(5); |
| 97 | expect(inputField.element().selectionStart).toEqual(5); |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 98 | expect(inputField._split()[0]).toEqual("abcde"); |
| 99 | expect(inputField._split()[1]).toEqual("fghijklmno"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 100 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 101 | inputField.insert("xyz"); |
| 102 | expect(inputField.value()).toEqual('abcdexyzfghijklmno'); |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 103 | expect(inputField._split()[0]).toEqual("abcdexyz"); |
| 104 | expect(inputField._split()[1]).toEqual("fghijklmno"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 105 | }); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 106 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 107 | it('should be correctly positioned', function () { |
| 108 | expect(input.value).toEqual('abcdefghijklmno'); |
| 109 | var inputField = inputClass.create(input); |
| 110 | document.getElementsByTagName("body")[0].appendChild(input); |
| 111 | inputField.reposition(); |
| 112 | expect(input.style.left).toEqual("30px"); |
| 113 | expect(inputField.mirror().style.left.match(/^(\d+)px$/)[1]).toBeGreaterThan(29); |
| 114 | expect(inputField.mirror().style.top.match(/^(\d+)px$/)[1]).toBeGreaterThan(20); |
| 115 | }); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 116 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 117 | it('should have a correct context', function () { |
| 118 | expect(input.value).toEqual('abcdefghijklmno'); |
| 119 | var inputField = inputClass.create(input); |
| 120 | expect(inputField.value()).toEqual("abcdefghijklmno"); |
| 121 | expect(inputField.element().selectionStart).toEqual(5); |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 122 | expect(inputField._split()[0]).toEqual("abcde"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 123 | expect(inputField.context()).toEqual("abcde"); |
| 124 | }); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 125 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 126 | /* |
| 127 | it('should be correctly triggerable', function () { |
| 128 | // https://developer.mozilla.org/samples/domref/dispatchEvent.html |
| 129 | var hint = KorAP.Hint.create({ "inputField" : input }); |
| 130 | emitKeyboardEvent(hint.inputField.element, "keypress", 20); |
| 131 | }); |
| 132 | */ |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 133 | }); |
| 134 | |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame] | 135 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 136 | describe('KorAP.ContextAnalyzer', function () { |
Akron | fac1647 | 2018-07-26 16:47:21 +0200 | [diff] [blame] | 137 | beforeAll(beforeAllFunc); |
| 138 | afterAll(afterAllFunc); |
| 139 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 140 | it('should be initializable', function () { |
| 141 | var analyzer = contextClass.create(")"); |
| 142 | expect(analyzer).toBe(undefined); |
| 143 | analyzer = contextClass.create(".+?"); |
| 144 | expect(analyzer).not.toBe(undefined); |
| 145 | }); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 146 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 147 | it('should check correctly', function () { |
Akron | fac1647 | 2018-07-26 16:47:21 +0200 | [diff] [blame] | 148 | |
| 149 | // Intialize KorAP.context |
| 150 | hintClass.create(); |
| 151 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 152 | analyzer = contextClass.create(KorAP.context); |
| 153 | expect(analyzer.test("cnx/]cnx/c=")).toEqual("cnx/c="); |
| 154 | expect(analyzer.test("cnx/c=")).toEqual("cnx/c="); |
| 155 | expect(analyzer.test("cnx/c=np mate/m=mood:")).toEqual("mate/m=mood:"); |
| 156 | expect(analyzer.test("impcnx/")).toEqual("impcnx/"); |
| 157 | expect(analyzer.test("cnx/c=npcnx/")).toEqual("npcnx/"); |
| 158 | expect(analyzer.test("mate/m=degree:pos corenlp/ne_dewac_175m_600=")) |
Akron | fac1647 | 2018-07-26 16:47:21 +0200 | [diff] [blame] | 159 | .toEqual("corenlp/ne_dewac_175m_600="); |
Akron | 113cc1a | 2016-01-22 21:17:57 +0100 | [diff] [blame] | 160 | expect(analyzer.test("corenlp/")).toEqual("corenlp/"); |
| 161 | expect(analyzer.test("corenlp/c=")).toEqual("corenlp/c="); |
| 162 | expect(analyzer.test("corenlp/c=PP-")).toEqual("corenlp/c=PP-"); |
| 163 | expect(analyzer.test("corenlp/c=XY-")).toEqual("corenlp/c=XY-"); |
Akron | cff9bac | 2016-01-25 21:39:38 +0100 | [diff] [blame] | 164 | expect(analyzer.test("sgbr/l=")).toEqual("sgbr/l="); |
| 165 | expect(analyzer.test("sgbr/lv=")).toEqual("sgbr/lv="); |
| 166 | expect(analyzer.test("sgbr/p=")).toEqual("sgbr/p="); |
Akron | ee9ef4a | 2016-06-03 12:50:08 +0200 | [diff] [blame] | 167 | expect(analyzer.test("")).toEqual(undefined); |
| 168 | expect(analyzer.test("abcdecnx/")).toEqual("abcdecnx/"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 169 | }); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 170 | }); |
| 171 | |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 172 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 173 | describe('KorAP.Hint', function () { |
Akron | fac1647 | 2018-07-26 16:47:21 +0200 | [diff] [blame] | 174 | beforeAll(beforeAllFunc); |
| 175 | afterAll(afterAllFunc); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 176 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 177 | beforeEach(function () { |
| 178 | input = document.createElement("input"); |
| 179 | input.setAttribute("type", "text"); |
| 180 | input.setAttribute("value", "abcdefghijklmno"); |
| 181 | input.style.position = 'absolute'; |
| 182 | input.style.top = "20px"; |
| 183 | input.style.left = "30px"; |
| 184 | input.focus(); |
| 185 | input.selectionStart = 5; |
| 186 | }); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 187 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 188 | it('should be initializable', function () { |
Akron | fac1647 | 2018-07-26 16:47:21 +0200 | [diff] [blame] | 189 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 190 | // Supports: context, searchField |
| 191 | var hint = hintClass.create({ |
Akron | fac1647 | 2018-07-26 16:47:21 +0200 | [diff] [blame] | 192 | inputField : input |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 193 | }); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 194 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 195 | expect(hint).toBeTruthy(); |
| 196 | }); |
Akron | 00cd4d1 | 2016-05-31 21:01:11 +0200 | [diff] [blame] | 197 | |
Akron | 1a5a587 | 2016-09-05 20:17:14 +0200 | [diff] [blame] | 198 | |
Akron | 00cd4d1 | 2016-05-31 21:01:11 +0200 | [diff] [blame] | 199 | it('should alert at char pos', function () { |
| 200 | var hint = hintClass.create({ |
Akron | 1a5a587 | 2016-09-05 20:17:14 +0200 | [diff] [blame] | 201 | inputField : input |
Akron | 00cd4d1 | 2016-05-31 21:01:11 +0200 | [diff] [blame] | 202 | }); |
| 203 | |
| 204 | expect(hint.active()).toBeFalsy(); |
| 205 | |
| 206 | expect(hint.alert(4, 'That does not work!')).toBeTruthy(); |
| 207 | |
| 208 | expect(hint.active()).toBeTruthy(); |
| 209 | |
| 210 | var container = hint.inputField().container(); |
| 211 | expect(container.firstChild.classList.contains('hint')).toBe(true); |
| 212 | expect(container.firstChild.classList.contains('alert')).toBe(true); |
| 213 | expect(container.firstChild.textContent).toEqual('That does not work!'); |
| 214 | expect(hint.inputField().mirrorValue()).toEqual('abcd'); |
| 215 | |
| 216 | expect(hint.alert(4, 'That does not work!')).toBeFalsy(); |
| 217 | |
| 218 | // Update - meaning: hide alert |
| 219 | hint.update(); |
| 220 | |
| 221 | expect(hint.alert().active).toBeFalsy(); |
Akron | 00cd4d1 | 2016-05-31 21:01:11 +0200 | [diff] [blame] | 222 | expect(hint.active()).toBeFalsy(); |
Akron | 1a5a587 | 2016-09-05 20:17:14 +0200 | [diff] [blame] | 223 | |
| 224 | // Show again |
| 225 | expect(hint.alert(5, 'That does not work!')).toBeTruthy(); |
| 226 | expect(hint.inputField().mirrorValue()).toEqual('abcde'); |
| 227 | expect(hint.alert().active).toBeTruthy(); |
| 228 | expect(hint.active()).toBeTruthy(); |
| 229 | |
| 230 | // Show menu, hide alert! |
| 231 | hint.show(false); |
| 232 | expect(hint.active()).toBeTruthy(); |
| 233 | expect(hint.inputField().mirrorValue()).toEqual('abcde'); |
| 234 | expect(hint.alert().active).toBeFalsy(); |
| 235 | |
Akron | fac1647 | 2018-07-26 16:47:21 +0200 | [diff] [blame] | 236 | // Show again |
Akron | 1a5a587 | 2016-09-05 20:17:14 +0200 | [diff] [blame] | 237 | expect(hint.alert(5, 'That does not work!')).toBeTruthy(); |
| 238 | expect(hint.inputField().mirrorValue()).toEqual('abcde'); |
| 239 | expect(hint.alert().active).toBeTruthy(); |
| 240 | expect(hint.active()).toBeTruthy(); |
| 241 | |
| 242 | // Show menu, hide alert! |
| 243 | hint.show(false); |
Akron | ee9ef4a | 2016-06-03 12:50:08 +0200 | [diff] [blame] | 244 | }); |
Akron | 00cd4d1 | 2016-05-31 21:01:11 +0200 | [diff] [blame] | 245 | |
Akron | da5bd3a | 2020-10-16 17:37:49 +0200 | [diff] [blame^] | 246 | it('should work both in Chrome and Firefox', function () { |
| 247 | var hint = hintClass.create({ |
| 248 | inputField : input |
| 249 | }); |
| 250 | hint.show(false); |
| 251 | expect(hint.alert(5, 'That does not work!')).toBeTruthy(); |
| 252 | |
| 253 | // Show menu, hide alert! |
| 254 | hint.show(false); |
| 255 | |
| 256 | expect(hint.active()).toBeFalsy(); |
| 257 | }); |
| 258 | |
| 259 | |
Akron | ee9ef4a | 2016-06-03 12:50:08 +0200 | [diff] [blame] | 260 | it('should view main menu on default', function () { |
| 261 | var hint = hintClass.create({ |
Akron | 1a5a587 | 2016-09-05 20:17:14 +0200 | [diff] [blame] | 262 | inputField : input |
Akron | ee9ef4a | 2016-06-03 12:50:08 +0200 | [diff] [blame] | 263 | }); |
| 264 | |
| 265 | expect(hint.active()).toBeFalsy(); |
| 266 | |
| 267 | hint.inputField().insert('der Baum corenlp/'); |
Akron | ee9ef4a | 2016-06-03 12:50:08 +0200 | [diff] [blame] | 268 | |
Akron | 8eaeb2e | 2016-08-29 18:26:28 +0200 | [diff] [blame] | 269 | var cont = hint.inputField().container(); |
| 270 | |
| 271 | expect(cont.getElementsByTagName('div').length).toBe(1); |
| 272 | expect(cont.getElementsByTagName('ul').length).toBe(0); |
| 273 | expect(cont.firstChild).toEqual(cont.firstChild); |
| 274 | |
| 275 | // Show menu, if a relevant context exists |
| 276 | // There is a menu for corenlp/ |
Akron | 02360e4 | 2016-06-07 13:41:12 +0200 | [diff] [blame] | 277 | hint.show(false); |
| 278 | |
Akron | 8eaeb2e | 2016-08-29 18:26:28 +0200 | [diff] [blame] | 279 | expect(hint.inputField().container().getElementsByTagName('ul').length).toEqual(1); |
| 280 | expect(hint.inputField().container().getElementsByTagName('li').length).toEqual(3); |
Akron | 65c7435 | 2016-09-02 17:23:39 +0200 | [diff] [blame] | 281 | |
Akron | 8eaeb2e | 2016-08-29 18:26:28 +0200 | [diff] [blame] | 282 | // Hide the menu and focus on the input |
| 283 | hint.unshow(); |
Akron | 65c7435 | 2016-09-02 17:23:39 +0200 | [diff] [blame] | 284 | |
| 285 | expect(hint.inputField().container().getElementsByTagName('div').length).toEqual(1); |
| 286 | expect(hint.inputField().container().getElementsByTagName('li').length).toEqual(0); |
Akron | ee9ef4a | 2016-06-03 12:50:08 +0200 | [diff] [blame] | 287 | |
Akron | 02360e4 | 2016-06-07 13:41:12 +0200 | [diff] [blame] | 288 | hint.unshow(); |
Akron | 65c7435 | 2016-09-02 17:23:39 +0200 | [diff] [blame] | 289 | |
Akron | ee9ef4a | 2016-06-03 12:50:08 +0200 | [diff] [blame] | 290 | hint.inputField().insert(' hhhh'); |
Akron | 65c7435 | 2016-09-02 17:23:39 +0200 | [diff] [blame] | 291 | |
Akron | ee9ef4a | 2016-06-03 12:50:08 +0200 | [diff] [blame] | 292 | // show with context |
Akron | 02360e4 | 2016-06-07 13:41:12 +0200 | [diff] [blame] | 293 | hint.show(false); |
Akron | 65c7435 | 2016-09-02 17:23:39 +0200 | [diff] [blame] | 294 | |
Akron | ee9ef4a | 2016-06-03 12:50:08 +0200 | [diff] [blame] | 295 | expect(hint.inputField().container().getElementsByTagName('div').length).toEqual(4); |
| 296 | expect(hint.inputField().container().getElementsByTagName('ul').length).toEqual(1); |
Akron | 02360e4 | 2016-06-07 13:41:12 +0200 | [diff] [blame] | 297 | expect(hint.inputField().container().getElementsByTagName('li').length).toEqual(2); |
| 298 | |
Akron | ee9ef4a | 2016-06-03 12:50:08 +0200 | [diff] [blame] | 299 | hint.unshow(); |
| 300 | hint.inputField().insert(' aaaa/'); |
| 301 | |
| 302 | // show with context |
| 303 | hint.show(true); |
| 304 | |
Akron | 1a5a587 | 2016-09-05 20:17:14 +0200 | [diff] [blame] | 305 | expect(hint.inputField().container().getElementsByTagName('div').length).toEqual(1); |
| 306 | expect(hint.inputField().container().getElementsByTagName('ul').length).toEqual(0); |
| 307 | }); |
| 308 | |
Akron | 95abaf4 | 2018-04-26 15:33:22 +0200 | [diff] [blame] | 309 | |
| 310 | it('should open menus depending on the context', function () { |
| 311 | var hint = hintClass.create({ |
| 312 | inputField : input |
| 313 | }); |
| 314 | hint.inputField().reset(); |
| 315 | |
| 316 | expect(hint.active()).toBeFalsy(); |
| 317 | |
| 318 | // show with context |
| 319 | hint.show(false); |
| 320 | |
| 321 | expect(hint.active()).toBeTruthy(); |
| 322 | |
| 323 | expect(hint.inputField().container().getElementsByTagName('li')[0].firstChild.innerText).toEqual("Base Annotation"); |
| 324 | |
| 325 | // Type in prefix |
| 326 | hint.active().prefix("cor").show(); |
| 327 | expect(hint.active().prefix()).toEqual("cor"); |
| 328 | |
| 329 | // Click first step |
| 330 | expect(hint.inputField().container().getElementsByTagName('li')[0].firstChild.firstChild.innerText).toEqual("Cor"); |
| 331 | hint.inputField().container().getElementsByTagName('li')[0].click(); |
| 332 | |
| 333 | expect(hint.active()).toBeTruthy(); |
| 334 | |
| 335 | // Click second step |
| 336 | expect(hint.inputField().container().getElementsByTagName('li')[0].firstChild.innerText).toEqual("Named Entity"); |
| 337 | hint.inputField().container().getElementsByTagName('li')[0].click() |
| 338 | |
| 339 | // Invisible menu |
| 340 | expect(hint.inputField().container().getElementsByTagName('li')[0]).toBeUndefined(); |
| 341 | |
| 342 | // Inactive menu |
| 343 | expect(hint.active()).toBeFalsy(); |
| 344 | |
| 345 | // show with context |
| 346 | hint.show(false); |
| 347 | |
| 348 | // No prefix |
| 349 | expect(hint.active().prefix()).toEqual(""); |
| 350 | }); |
| 351 | |
| 352 | |
Akron | 1a5a587 | 2016-09-05 20:17:14 +0200 | [diff] [blame] | 353 | it('should not view main menu if context is mandatory', function () { |
| 354 | var hint = hintClass.create({ |
| 355 | inputField : input |
| 356 | }); |
| 357 | |
| 358 | expect(hint.active()).toBeFalsy(); |
| 359 | |
| 360 | // Fine |
| 361 | hint.inputField().insert('der Baum corenlp/'); |
| 362 | hint.show(true); |
| 363 | expect(hint.active()).toBeTruthy(); |
| 364 | |
| 365 | // Not analyzable |
| 366 | hint.inputField().insert('jhgjughjfhgnhfcvgnhj'); |
| 367 | hint.show(true); |
| 368 | expect(hint.active()).toBeFalsy(); |
| 369 | |
| 370 | // Not available |
| 371 | hint.inputField().insert('jhgjughjfhgnhfcvgnhj/'); |
| 372 | hint.show(true); |
| 373 | expect(hint.active()).toBeFalsy(); |
Akron | 00cd4d1 | 2016-05-31 21:01:11 +0200 | [diff] [blame] | 374 | }); |
Akron | 5746ecf | 2018-06-23 10:57:24 +0200 | [diff] [blame] | 375 | |
| 376 | |
| 377 | it('should show the assistant bar on blur', function () { |
| 378 | var hint = hintClass.create({ |
| 379 | inputField : input |
| 380 | }); |
| 381 | // Fine |
| 382 | hint.inputField().insert('der Baum corenlp/'); |
| 383 | hint.show(true); |
| 384 | expect(hint.active()).toBeTruthy(); |
| 385 | |
| 386 | // Blur |
Akron | e078911 | 2018-08-31 14:32:04 +0200 | [diff] [blame] | 387 | hint.active().hide(); |
Akron | 5746ecf | 2018-06-23 10:57:24 +0200 | [diff] [blame] | 388 | expect(hint.active()).toBeFalsy(); |
| 389 | }); |
Akron | 65c7435 | 2016-09-02 17:23:39 +0200 | [diff] [blame] | 390 | |
Akron | 02360e4 | 2016-06-07 13:41:12 +0200 | [diff] [blame] | 391 | xit('should remove all menus on escape'); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 392 | }); |
| 393 | |
Akron | 65c7435 | 2016-09-02 17:23:39 +0200 | [diff] [blame] | 394 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 395 | describe('KorAP.HintMenuItem', function () { |
Akron | fac1647 | 2018-07-26 16:47:21 +0200 | [diff] [blame] | 396 | beforeAll(beforeAllFunc); |
| 397 | afterAll(afterAllFunc); |
| 398 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 399 | it('should be initializable', function () { |
| 400 | expect( |
Akron | fac1647 | 2018-07-26 16:47:21 +0200 | [diff] [blame] | 401 | function() { menuItemClass.create([]) } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 402 | ).toThrow(new Error("Missing parameters")); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 403 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 404 | expect( |
Akron | fac1647 | 2018-07-26 16:47:21 +0200 | [diff] [blame] | 405 | function() { menuItemClass.create(['CoreNLP']) } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 406 | ).toThrow(new Error("Missing parameters")); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 407 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 408 | var menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']); |
| 409 | expect(menuItem.name()).toEqual('CoreNLP'); |
| 410 | expect(menuItem.action()).toEqual('corenlp/'); |
| 411 | expect(menuItem.desc()).toBeUndefined(); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 412 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 413 | menuItem = menuItemClass.create( |
Akron | fac1647 | 2018-07-26 16:47:21 +0200 | [diff] [blame] | 414 | ['CoreNLP', 'corenlp/', 'It\'s funny'] |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 415 | ); |
| 416 | expect(menuItem.name()).toEqual('CoreNLP'); |
| 417 | expect(menuItem.action()).toEqual('corenlp/'); |
| 418 | expect(menuItem.desc()).not.toBeUndefined(); |
| 419 | expect(menuItem.desc()).toEqual('It\'s funny'); |
| 420 | }); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 421 | |
Akron | fac1647 | 2018-07-26 16:47:21 +0200 | [diff] [blame] | 422 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 423 | it('should have an element', function () { |
| 424 | var menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']); |
| 425 | expect(menuItem.element()).not.toBe(undefined); |
| 426 | expect(menuItem.element().nodeName).toEqual("LI"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 427 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 428 | var title = menuItem.element().firstChild; |
| 429 | expect(title.nodeName).toEqual("SPAN"); |
| 430 | expect(title.firstChild.nodeType).toEqual(3); |
| 431 | expect(title.firstChild.nodeValue).toEqual("CoreNLP"); |
| 432 | expect(menuItem.element().childNodes[0]).not.toBe(undefined); |
| 433 | expect(menuItem.element().childNodes[1]).toBe(undefined); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 434 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 435 | menuItem = menuItemClass.create( |
Akron | fac1647 | 2018-07-26 16:47:21 +0200 | [diff] [blame] | 436 | ['CoreNLP', 'corenlp/', 'my DescRiption'] |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 437 | ); |
| 438 | expect(menuItem.element()).not.toBe(undefined); |
| 439 | expect(menuItem.element().nodeName).toEqual("LI"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 440 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 441 | title = menuItem.element().firstChild; |
| 442 | expect(title.nodeName).toEqual("SPAN"); |
| 443 | expect(title.firstChild.nodeType).toEqual(3); // TextNode |
| 444 | expect(title.firstChild.nodeValue).toEqual("CoreNLP"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 445 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 446 | expect(menuItem.element().childNodes[0]).not.toBe(undefined); |
| 447 | expect(menuItem.element().childNodes[1]).not.toBe(undefined); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 448 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 449 | var desc = menuItem.element().lastChild; |
| 450 | expect(desc.nodeName).toEqual("SPAN"); |
| 451 | expect(desc.firstChild.nodeType).toEqual(3); // TextNode |
| 452 | expect(desc.firstChild.nodeValue).toEqual("my DescRiption"); |
| 453 | }); |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame] | 454 | |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 455 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 456 | it('should be activatable and deactivateable by class', function () { |
| 457 | var menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']); |
| 458 | expect(menuItem.active()).toBe(false); |
| 459 | expect(menuItem.element().getAttribute("class")).toBe(null); |
| 460 | menuItem.active(true); |
| 461 | expect(menuItem.active()).toBe(true); |
| 462 | expect(menuItem.element().getAttribute("class")).toEqual("active"); |
| 463 | menuItem.active(false); // Is active |
| 464 | expect(menuItem.active()).toBe(false); |
| 465 | expect(menuItem.element().getAttribute("class")).toEqual(""); |
| 466 | menuItem.active(true); |
| 467 | expect(menuItem.active()).toBe(true); |
| 468 | expect(menuItem.element().getAttribute("class")).toEqual("active"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 469 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 470 | menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']); |
| 471 | expect(menuItem.active()).toBe(false); |
| 472 | expect(menuItem.element().getAttribute("class")).toBe(null); |
| 473 | menuItem.active(false); // Is not active |
| 474 | expect(menuItem.active()).toBe(false); |
| 475 | expect(menuItem.element().getAttribute("class")).toBe(null); |
| 476 | }); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 477 | |
Akron | fac1647 | 2018-07-26 16:47:21 +0200 | [diff] [blame] | 478 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 479 | it('should be set to boundary', function () { |
| 480 | var menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']); |
| 481 | expect(menuItem.active()).toBe(false); |
| 482 | expect(menuItem.element().getAttribute("class")).toBe(null); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 483 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 484 | // Set active |
| 485 | menuItem.active(true); |
| 486 | expect(menuItem.active()).toBe(true); |
| 487 | expect(menuItem.noMore()).toBe(false); |
| 488 | expect(menuItem.element().getAttribute("class")).toEqual("active"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 489 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 490 | // Set no more |
| 491 | menuItem.noMore(true); |
| 492 | expect(menuItem.active()).toBe(true); |
| 493 | expect(menuItem.noMore()).toBe(true); |
| 494 | expect(menuItem.element().getAttribute("class")).toEqual("active no-more"); |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame] | 495 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 496 | // No no more |
| 497 | menuItem.noMore(false); |
| 498 | expect(menuItem.active()).toBe(true); |
| 499 | expect(menuItem.noMore()).toBe(false); |
| 500 | expect(menuItem.element().getAttribute("class")).toEqual("active"); |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame] | 501 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 502 | // Set no more, deactivate |
| 503 | menuItem.noMore(true); |
| 504 | menuItem.active(false); |
| 505 | expect(menuItem.active()).toBe(false); |
| 506 | expect(menuItem.noMore()).toBe(true); |
| 507 | expect(menuItem.element().getAttribute("class")).toEqual("no-more"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 508 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 509 | // Set active |
| 510 | menuItem.active(true); |
| 511 | expect(menuItem.active()).toBe(true); |
| 512 | expect(menuItem.noMore()).toBe(true); |
| 513 | expect(menuItem.element().getAttribute("class")).toEqual("no-more active"); |
| 514 | }); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 515 | |
Akron | fac1647 | 2018-07-26 16:47:21 +0200 | [diff] [blame] | 516 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 517 | it('should be highlightable', function () { |
| 518 | // Highlight in the middle |
| 519 | var menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']); |
| 520 | menuItem.highlight("ren"); |
| 521 | expect(menuItem.element().innerHTML).toEqual("<span>Co<mark>reN</mark>LP</span>"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 522 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 523 | menuItem.lowlight(); |
| 524 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 525 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 526 | // Starting highlight |
| 527 | menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']); |
| 528 | menuItem.highlight("cor"); |
| 529 | expect(menuItem.element().innerHTML).toEqual("<span><mark>Cor</mark>eNLP</span>"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 530 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 531 | menuItem.lowlight(); |
| 532 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>"); |
| 533 | |
| 534 | // Starting highlight - short |
| 535 | menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']); |
| 536 | menuItem.highlight("c"); |
| 537 | expect(menuItem.element().innerHTML).toEqual("<span><mark>C</mark>oreNLP</span>"); |
| 538 | |
| 539 | menuItem.lowlight(); |
| 540 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>"); |
| 541 | |
| 542 | // Highlight at the end |
| 543 | menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']); |
| 544 | menuItem.highlight("nlp"); |
| 545 | expect(menuItem.element().innerHTML).toEqual("<span>Core<mark>NLP</mark></span>"); |
| 546 | |
| 547 | menuItem.lowlight(); |
| 548 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>"); |
| 549 | |
| 550 | // Highlight at the end - short |
| 551 | menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']); |
| 552 | menuItem.highlight("p"); |
| 553 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNL<mark>P</mark></span>"); |
| 554 | |
| 555 | menuItem.lowlight(); |
| 556 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>"); |
| 557 | |
| 558 | // No highlight |
| 559 | menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']); |
| 560 | menuItem.highlight("xp"); |
| 561 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>"); |
| 562 | |
| 563 | menuItem.lowlight(); |
| 564 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>"); |
| 565 | |
| 566 | // Highlight in the middle - first |
| 567 | menuItem = menuItemClass.create(['CoreNLP', 'corenlp/', 'This is my Example']); |
| 568 | |
| 569 | menuItem.highlight("ren"); |
| 570 | expect(menuItem.element().innerHTML).toEqual("<span>Co<mark>reN</mark>LP</span><span class=\"desc\">This is my Example</span>"); |
| 571 | |
| 572 | menuItem.lowlight(); |
| 573 | expect(menuItem.element().innerHTML).toEqual('<span>CoreNLP</span><span class="desc">This is my Example</span>'); |
| 574 | |
| 575 | // Highlight in the middle - second |
| 576 | menuItem = menuItemClass.create(['CoreNLP', 'corenlp/', 'This is my Example']); |
| 577 | menuItem.highlight("ampl"); |
| 578 | expect(menuItem.element().innerHTML).toEqual('<span>CoreNLP</span><span class="desc">This is my Ex<mark>ampl</mark>e</span>'); |
| 579 | |
| 580 | menuItem.lowlight(); |
| 581 | expect(menuItem.element().innerHTML).toEqual('<span>CoreNLP</span><span class="desc">This is my Example</span>'); |
| 582 | |
| 583 | // Highlight in the middle - both |
| 584 | menuItem = menuItemClass.create(['CoreNLP', 'corenlp/', 'This is my Example']); |
| 585 | |
| 586 | menuItem.highlight("e"); |
| 587 | expect(menuItem.element().innerHTML).toEqual('<span>Cor<mark>e</mark>NLP</span><span class="desc">This is my <mark>E</mark>xampl<mark>e</mark></span>'); |
| 588 | |
| 589 | menuItem.lowlight(); |
| 590 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span class=\"desc\">This is my Example</span>"); |
| 591 | |
| 592 | // Highlight in the end - second |
| 593 | menuItem = menuItemClass.create(['CoreNLP', 'corenlp/', 'This is my Example']); |
| 594 | menuItem.highlight("le"); |
| 595 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span class=\"desc\">This is my Examp<mark>le</mark></span>"); |
| 596 | |
| 597 | menuItem.lowlight(); |
| 598 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span class=\"desc\">This is my Example</span>"); |
| 599 | |
| 600 | // Highlight at the beginning - second |
| 601 | menuItem = menuItemClass.create(['CoreNLP', 'corenlp/', 'This is my Example']); |
| 602 | menuItem.highlight("this"); |
| 603 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span class=\"desc\"><mark>This</mark> is my Example</span>"); |
| 604 | |
| 605 | menuItem.lowlight(); |
| 606 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span class=\"desc\">This is my Example</span>"); |
| 607 | }); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 608 | }); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 609 | |
Akron | fac1647 | 2018-07-26 16:47:21 +0200 | [diff] [blame] | 610 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 611 | describe('KorAP.HintMenu', function () { |
Akron | fac1647 | 2018-07-26 16:47:21 +0200 | [diff] [blame] | 612 | beforeAll(beforeAllFunc); |
| 613 | afterAll(afterAllFunc); |
| 614 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 615 | var list = [ |
| 616 | ["Constituency", "c=", "Example 1"], |
| 617 | ["Lemma", "l="], |
| 618 | ["Morphology", "m=", "Example 2"], |
| 619 | ["Part-of-Speech", "p="], |
| 620 | ["Syntax", "syn="] |
| 621 | ]; |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 622 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 623 | it('should be initializable', function () { |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 624 | var menu = menuClass.create(null, "cnx/", list); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 625 | expect(menu.element().nodeName).toEqual('UL'); |
Akron | 65c7435 | 2016-09-02 17:23:39 +0200 | [diff] [blame] | 626 | // expect(menu.element().style.opacity).toEqual("0"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 627 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 628 | menu.limit(8); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 629 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 630 | // view |
| 631 | menu.show(); |
Akron | 6ed1399 | 2016-05-23 18:06:05 +0200 | [diff] [blame] | 632 | expect(menu.prefix()).toBe(''); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 633 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 634 | // First element in list |
| 635 | expect(menu.item(0).active()).toBe(true); |
| 636 | expect(menu.item(0).noMore()).toBe(true); |
| 637 | |
| 638 | // Middle element in list |
| 639 | expect(menu.item(2).active()).toBe(false); |
| 640 | expect(menu.item(2).noMore()).toBe(false); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 641 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 642 | // Last element in list |
| 643 | expect(menu.item(menu.length() - 1).active()).toBe(false); |
| 644 | expect(menu.item(menu.length() - 1).noMore()).toBe(true); |
Akron | 6ed1399 | 2016-05-23 18:06:05 +0200 | [diff] [blame] | 645 | |
| 646 | expect(menu.shownItem(0).active()).toBeTruthy(); |
| 647 | expect(menu.shownItem(0).lcField()).toEqual(' constituency example 1'); |
| 648 | expect(menu.shownItem(1).lcField()).toEqual(' lemma'); |
| 649 | expect(menu.shownItem(2).lcField()).toEqual(' morphology example 2'); |
| 650 | |
| 651 | menu.next(); |
| 652 | expect(menu.shownItem(1).active()).toBeTruthy(); |
| 653 | |
| 654 | menu.next(); |
| 655 | expect(menu.shownItem(2).active()).toBeTruthy(); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 656 | }); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 657 | }); |
| 658 | }); |