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 | cae907d | 2018-08-20 17:22:15 +0200 | [diff] [blame] | 244 | |
| 245 | // PROBLEM! |
Akron | 1a5a587 | 2016-09-05 20:17:14 +0200 | [diff] [blame] | 246 | expect(hint.active()).toBeTruthy(); |
| 247 | expect(hint.inputField().mirrorValue()).toEqual('abcde'); |
| 248 | expect(hint.alert().active).toBeFalsy(); |
Akron | ee9ef4a | 2016-06-03 12:50:08 +0200 | [diff] [blame] | 249 | }); |
Akron | 00cd4d1 | 2016-05-31 21:01:11 +0200 | [diff] [blame] | 250 | |
Akron | ee9ef4a | 2016-06-03 12:50:08 +0200 | [diff] [blame] | 251 | it('should view main menu on default', function () { |
| 252 | var hint = hintClass.create({ |
Akron | 1a5a587 | 2016-09-05 20:17:14 +0200 | [diff] [blame] | 253 | inputField : input |
Akron | ee9ef4a | 2016-06-03 12:50:08 +0200 | [diff] [blame] | 254 | }); |
| 255 | |
| 256 | expect(hint.active()).toBeFalsy(); |
| 257 | |
| 258 | hint.inputField().insert('der Baum corenlp/'); |
Akron | ee9ef4a | 2016-06-03 12:50:08 +0200 | [diff] [blame] | 259 | |
Akron | 8eaeb2e | 2016-08-29 18:26:28 +0200 | [diff] [blame] | 260 | var cont = hint.inputField().container(); |
| 261 | |
| 262 | expect(cont.getElementsByTagName('div').length).toBe(1); |
| 263 | expect(cont.getElementsByTagName('ul').length).toBe(0); |
| 264 | expect(cont.firstChild).toEqual(cont.firstChild); |
| 265 | |
| 266 | // Show menu, if a relevant context exists |
| 267 | // There is a menu for corenlp/ |
Akron | 02360e4 | 2016-06-07 13:41:12 +0200 | [diff] [blame] | 268 | hint.show(false); |
| 269 | |
Akron | 8eaeb2e | 2016-08-29 18:26:28 +0200 | [diff] [blame] | 270 | expect(hint.inputField().container().getElementsByTagName('ul').length).toEqual(1); |
| 271 | expect(hint.inputField().container().getElementsByTagName('li').length).toEqual(3); |
Akron | 65c7435 | 2016-09-02 17:23:39 +0200 | [diff] [blame] | 272 | |
Akron | 8eaeb2e | 2016-08-29 18:26:28 +0200 | [diff] [blame] | 273 | // Hide the menu and focus on the input |
| 274 | hint.unshow(); |
Akron | 65c7435 | 2016-09-02 17:23:39 +0200 | [diff] [blame] | 275 | |
| 276 | expect(hint.inputField().container().getElementsByTagName('div').length).toEqual(1); |
| 277 | expect(hint.inputField().container().getElementsByTagName('li').length).toEqual(0); |
Akron | ee9ef4a | 2016-06-03 12:50:08 +0200 | [diff] [blame] | 278 | |
Akron | 02360e4 | 2016-06-07 13:41:12 +0200 | [diff] [blame] | 279 | hint.unshow(); |
Akron | 65c7435 | 2016-09-02 17:23:39 +0200 | [diff] [blame] | 280 | |
Akron | ee9ef4a | 2016-06-03 12:50:08 +0200 | [diff] [blame] | 281 | hint.inputField().insert(' hhhh'); |
Akron | 65c7435 | 2016-09-02 17:23:39 +0200 | [diff] [blame] | 282 | |
Akron | ee9ef4a | 2016-06-03 12:50:08 +0200 | [diff] [blame] | 283 | // show with context |
Akron | 02360e4 | 2016-06-07 13:41:12 +0200 | [diff] [blame] | 284 | hint.show(false); |
Akron | 65c7435 | 2016-09-02 17:23:39 +0200 | [diff] [blame] | 285 | |
Akron | ee9ef4a | 2016-06-03 12:50:08 +0200 | [diff] [blame] | 286 | expect(hint.inputField().container().getElementsByTagName('div').length).toEqual(4); |
| 287 | expect(hint.inputField().container().getElementsByTagName('ul').length).toEqual(1); |
Akron | 02360e4 | 2016-06-07 13:41:12 +0200 | [diff] [blame] | 288 | expect(hint.inputField().container().getElementsByTagName('li').length).toEqual(2); |
| 289 | |
Akron | ee9ef4a | 2016-06-03 12:50:08 +0200 | [diff] [blame] | 290 | hint.unshow(); |
| 291 | hint.inputField().insert(' aaaa/'); |
| 292 | |
| 293 | // show with context |
| 294 | hint.show(true); |
| 295 | |
Akron | 1a5a587 | 2016-09-05 20:17:14 +0200 | [diff] [blame] | 296 | expect(hint.inputField().container().getElementsByTagName('div').length).toEqual(1); |
| 297 | expect(hint.inputField().container().getElementsByTagName('ul').length).toEqual(0); |
| 298 | }); |
| 299 | |
Akron | 95abaf4 | 2018-04-26 15:33:22 +0200 | [diff] [blame] | 300 | |
| 301 | it('should open menus depending on the context', function () { |
| 302 | var hint = hintClass.create({ |
| 303 | inputField : input |
| 304 | }); |
| 305 | hint.inputField().reset(); |
| 306 | |
| 307 | expect(hint.active()).toBeFalsy(); |
| 308 | |
| 309 | // show with context |
| 310 | hint.show(false); |
| 311 | |
| 312 | expect(hint.active()).toBeTruthy(); |
| 313 | |
| 314 | expect(hint.inputField().container().getElementsByTagName('li')[0].firstChild.innerText).toEqual("Base Annotation"); |
| 315 | |
| 316 | // Type in prefix |
| 317 | hint.active().prefix("cor").show(); |
| 318 | expect(hint.active().prefix()).toEqual("cor"); |
| 319 | |
| 320 | // Click first step |
| 321 | expect(hint.inputField().container().getElementsByTagName('li')[0].firstChild.firstChild.innerText).toEqual("Cor"); |
| 322 | hint.inputField().container().getElementsByTagName('li')[0].click(); |
| 323 | |
| 324 | expect(hint.active()).toBeTruthy(); |
| 325 | |
| 326 | // Click second step |
| 327 | expect(hint.inputField().container().getElementsByTagName('li')[0].firstChild.innerText).toEqual("Named Entity"); |
| 328 | hint.inputField().container().getElementsByTagName('li')[0].click() |
| 329 | |
| 330 | // Invisible menu |
| 331 | expect(hint.inputField().container().getElementsByTagName('li')[0]).toBeUndefined(); |
| 332 | |
| 333 | // Inactive menu |
| 334 | expect(hint.active()).toBeFalsy(); |
| 335 | |
| 336 | // show with context |
| 337 | hint.show(false); |
| 338 | |
| 339 | // No prefix |
| 340 | expect(hint.active().prefix()).toEqual(""); |
| 341 | }); |
| 342 | |
| 343 | |
Akron | 1a5a587 | 2016-09-05 20:17:14 +0200 | [diff] [blame] | 344 | it('should not view main menu if context is mandatory', function () { |
| 345 | var hint = hintClass.create({ |
| 346 | inputField : input |
| 347 | }); |
| 348 | |
| 349 | expect(hint.active()).toBeFalsy(); |
| 350 | |
| 351 | // Fine |
| 352 | hint.inputField().insert('der Baum corenlp/'); |
| 353 | hint.show(true); |
| 354 | expect(hint.active()).toBeTruthy(); |
| 355 | |
| 356 | // Not analyzable |
| 357 | hint.inputField().insert('jhgjughjfhgnhfcvgnhj'); |
| 358 | hint.show(true); |
| 359 | expect(hint.active()).toBeFalsy(); |
| 360 | |
| 361 | // Not available |
| 362 | hint.inputField().insert('jhgjughjfhgnhfcvgnhj/'); |
| 363 | hint.show(true); |
| 364 | expect(hint.active()).toBeFalsy(); |
Akron | 00cd4d1 | 2016-05-31 21:01:11 +0200 | [diff] [blame] | 365 | }); |
Akron | 5746ecf | 2018-06-23 10:57:24 +0200 | [diff] [blame] | 366 | |
| 367 | |
| 368 | it('should show the assistant bar on blur', function () { |
| 369 | var hint = hintClass.create({ |
| 370 | inputField : input |
| 371 | }); |
| 372 | // Fine |
| 373 | hint.inputField().insert('der Baum corenlp/'); |
| 374 | hint.show(true); |
| 375 | expect(hint.active()).toBeTruthy(); |
| 376 | |
| 377 | // Blur |
Akron | e078911 | 2018-08-31 14:32:04 +0200 | [diff] [blame] | 378 | hint.active().hide(); |
Akron | 5746ecf | 2018-06-23 10:57:24 +0200 | [diff] [blame] | 379 | expect(hint.active()).toBeFalsy(); |
| 380 | }); |
Akron | 65c7435 | 2016-09-02 17:23:39 +0200 | [diff] [blame] | 381 | |
Akron | 02360e4 | 2016-06-07 13:41:12 +0200 | [diff] [blame] | 382 | xit('should remove all menus on escape'); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 383 | }); |
| 384 | |
Akron | 65c7435 | 2016-09-02 17:23:39 +0200 | [diff] [blame] | 385 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 386 | describe('KorAP.HintMenuItem', function () { |
Akron | fac1647 | 2018-07-26 16:47:21 +0200 | [diff] [blame] | 387 | beforeAll(beforeAllFunc); |
| 388 | afterAll(afterAllFunc); |
| 389 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 390 | it('should be initializable', function () { |
| 391 | expect( |
Akron | fac1647 | 2018-07-26 16:47:21 +0200 | [diff] [blame] | 392 | function() { menuItemClass.create([]) } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 393 | ).toThrow(new Error("Missing parameters")); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 394 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 395 | expect( |
Akron | fac1647 | 2018-07-26 16:47:21 +0200 | [diff] [blame] | 396 | function() { menuItemClass.create(['CoreNLP']) } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 397 | ).toThrow(new Error("Missing parameters")); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 398 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 399 | var menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']); |
| 400 | expect(menuItem.name()).toEqual('CoreNLP'); |
| 401 | expect(menuItem.action()).toEqual('corenlp/'); |
| 402 | expect(menuItem.desc()).toBeUndefined(); |
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 | menuItem = menuItemClass.create( |
Akron | fac1647 | 2018-07-26 16:47:21 +0200 | [diff] [blame] | 405 | ['CoreNLP', 'corenlp/', 'It\'s funny'] |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 406 | ); |
| 407 | expect(menuItem.name()).toEqual('CoreNLP'); |
| 408 | expect(menuItem.action()).toEqual('corenlp/'); |
| 409 | expect(menuItem.desc()).not.toBeUndefined(); |
| 410 | expect(menuItem.desc()).toEqual('It\'s funny'); |
| 411 | }); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 412 | |
Akron | fac1647 | 2018-07-26 16:47:21 +0200 | [diff] [blame] | 413 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 414 | it('should have an element', function () { |
| 415 | var menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']); |
| 416 | expect(menuItem.element()).not.toBe(undefined); |
| 417 | expect(menuItem.element().nodeName).toEqual("LI"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 418 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 419 | var title = menuItem.element().firstChild; |
| 420 | expect(title.nodeName).toEqual("SPAN"); |
| 421 | expect(title.firstChild.nodeType).toEqual(3); |
| 422 | expect(title.firstChild.nodeValue).toEqual("CoreNLP"); |
| 423 | expect(menuItem.element().childNodes[0]).not.toBe(undefined); |
| 424 | expect(menuItem.element().childNodes[1]).toBe(undefined); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 425 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 426 | menuItem = menuItemClass.create( |
Akron | fac1647 | 2018-07-26 16:47:21 +0200 | [diff] [blame] | 427 | ['CoreNLP', 'corenlp/', 'my DescRiption'] |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 428 | ); |
| 429 | expect(menuItem.element()).not.toBe(undefined); |
| 430 | expect(menuItem.element().nodeName).toEqual("LI"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 431 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 432 | title = menuItem.element().firstChild; |
| 433 | expect(title.nodeName).toEqual("SPAN"); |
| 434 | expect(title.firstChild.nodeType).toEqual(3); // TextNode |
| 435 | expect(title.firstChild.nodeValue).toEqual("CoreNLP"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 436 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 437 | expect(menuItem.element().childNodes[0]).not.toBe(undefined); |
| 438 | expect(menuItem.element().childNodes[1]).not.toBe(undefined); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 439 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 440 | var desc = menuItem.element().lastChild; |
| 441 | expect(desc.nodeName).toEqual("SPAN"); |
| 442 | expect(desc.firstChild.nodeType).toEqual(3); // TextNode |
| 443 | expect(desc.firstChild.nodeValue).toEqual("my DescRiption"); |
| 444 | }); |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame] | 445 | |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 446 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 447 | it('should be activatable and deactivateable by class', function () { |
| 448 | var menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']); |
| 449 | expect(menuItem.active()).toBe(false); |
| 450 | expect(menuItem.element().getAttribute("class")).toBe(null); |
| 451 | menuItem.active(true); |
| 452 | expect(menuItem.active()).toBe(true); |
| 453 | expect(menuItem.element().getAttribute("class")).toEqual("active"); |
| 454 | menuItem.active(false); // Is active |
| 455 | expect(menuItem.active()).toBe(false); |
| 456 | expect(menuItem.element().getAttribute("class")).toEqual(""); |
| 457 | menuItem.active(true); |
| 458 | expect(menuItem.active()).toBe(true); |
| 459 | expect(menuItem.element().getAttribute("class")).toEqual("active"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 460 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 461 | menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']); |
| 462 | expect(menuItem.active()).toBe(false); |
| 463 | expect(menuItem.element().getAttribute("class")).toBe(null); |
| 464 | menuItem.active(false); // Is not active |
| 465 | expect(menuItem.active()).toBe(false); |
| 466 | expect(menuItem.element().getAttribute("class")).toBe(null); |
| 467 | }); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 468 | |
Akron | fac1647 | 2018-07-26 16:47:21 +0200 | [diff] [blame] | 469 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 470 | it('should be set to boundary', function () { |
| 471 | var menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']); |
| 472 | expect(menuItem.active()).toBe(false); |
| 473 | expect(menuItem.element().getAttribute("class")).toBe(null); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 474 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 475 | // Set active |
| 476 | menuItem.active(true); |
| 477 | expect(menuItem.active()).toBe(true); |
| 478 | expect(menuItem.noMore()).toBe(false); |
| 479 | expect(menuItem.element().getAttribute("class")).toEqual("active"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 480 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 481 | // Set no more |
| 482 | menuItem.noMore(true); |
| 483 | expect(menuItem.active()).toBe(true); |
| 484 | expect(menuItem.noMore()).toBe(true); |
| 485 | expect(menuItem.element().getAttribute("class")).toEqual("active no-more"); |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame] | 486 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 487 | // No no more |
| 488 | menuItem.noMore(false); |
| 489 | expect(menuItem.active()).toBe(true); |
| 490 | expect(menuItem.noMore()).toBe(false); |
| 491 | expect(menuItem.element().getAttribute("class")).toEqual("active"); |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame] | 492 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 493 | // Set no more, deactivate |
| 494 | menuItem.noMore(true); |
| 495 | menuItem.active(false); |
| 496 | expect(menuItem.active()).toBe(false); |
| 497 | expect(menuItem.noMore()).toBe(true); |
| 498 | expect(menuItem.element().getAttribute("class")).toEqual("no-more"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 499 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 500 | // Set active |
| 501 | menuItem.active(true); |
| 502 | expect(menuItem.active()).toBe(true); |
| 503 | expect(menuItem.noMore()).toBe(true); |
| 504 | expect(menuItem.element().getAttribute("class")).toEqual("no-more active"); |
| 505 | }); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 506 | |
Akron | fac1647 | 2018-07-26 16:47:21 +0200 | [diff] [blame] | 507 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 508 | it('should be highlightable', function () { |
| 509 | // Highlight in the middle |
| 510 | var menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']); |
| 511 | menuItem.highlight("ren"); |
| 512 | expect(menuItem.element().innerHTML).toEqual("<span>Co<mark>reN</mark>LP</span>"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 513 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 514 | menuItem.lowlight(); |
| 515 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 516 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 517 | // Starting highlight |
| 518 | menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']); |
| 519 | menuItem.highlight("cor"); |
| 520 | expect(menuItem.element().innerHTML).toEqual("<span><mark>Cor</mark>eNLP</span>"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 521 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 522 | menuItem.lowlight(); |
| 523 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>"); |
| 524 | |
| 525 | // Starting highlight - short |
| 526 | menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']); |
| 527 | menuItem.highlight("c"); |
| 528 | expect(menuItem.element().innerHTML).toEqual("<span><mark>C</mark>oreNLP</span>"); |
| 529 | |
| 530 | menuItem.lowlight(); |
| 531 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>"); |
| 532 | |
| 533 | // Highlight at the end |
| 534 | menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']); |
| 535 | menuItem.highlight("nlp"); |
| 536 | expect(menuItem.element().innerHTML).toEqual("<span>Core<mark>NLP</mark></span>"); |
| 537 | |
| 538 | menuItem.lowlight(); |
| 539 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>"); |
| 540 | |
| 541 | // Highlight at the end - short |
| 542 | menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']); |
| 543 | menuItem.highlight("p"); |
| 544 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNL<mark>P</mark></span>"); |
| 545 | |
| 546 | menuItem.lowlight(); |
| 547 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>"); |
| 548 | |
| 549 | // No highlight |
| 550 | menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']); |
| 551 | menuItem.highlight("xp"); |
| 552 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>"); |
| 553 | |
| 554 | menuItem.lowlight(); |
| 555 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>"); |
| 556 | |
| 557 | // Highlight in the middle - first |
| 558 | menuItem = menuItemClass.create(['CoreNLP', 'corenlp/', 'This is my Example']); |
| 559 | |
| 560 | menuItem.highlight("ren"); |
| 561 | expect(menuItem.element().innerHTML).toEqual("<span>Co<mark>reN</mark>LP</span><span class=\"desc\">This is my Example</span>"); |
| 562 | |
| 563 | menuItem.lowlight(); |
| 564 | expect(menuItem.element().innerHTML).toEqual('<span>CoreNLP</span><span class="desc">This is my Example</span>'); |
| 565 | |
| 566 | // Highlight in the middle - second |
| 567 | menuItem = menuItemClass.create(['CoreNLP', 'corenlp/', 'This is my Example']); |
| 568 | menuItem.highlight("ampl"); |
| 569 | expect(menuItem.element().innerHTML).toEqual('<span>CoreNLP</span><span class="desc">This is my Ex<mark>ampl</mark>e</span>'); |
| 570 | |
| 571 | menuItem.lowlight(); |
| 572 | expect(menuItem.element().innerHTML).toEqual('<span>CoreNLP</span><span class="desc">This is my Example</span>'); |
| 573 | |
| 574 | // Highlight in the middle - both |
| 575 | menuItem = menuItemClass.create(['CoreNLP', 'corenlp/', 'This is my Example']); |
| 576 | |
| 577 | menuItem.highlight("e"); |
| 578 | 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>'); |
| 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 end - second |
| 584 | menuItem = menuItemClass.create(['CoreNLP', 'corenlp/', 'This is my Example']); |
| 585 | menuItem.highlight("le"); |
| 586 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span class=\"desc\">This is my Examp<mark>le</mark></span>"); |
| 587 | |
| 588 | menuItem.lowlight(); |
| 589 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span class=\"desc\">This is my Example</span>"); |
| 590 | |
| 591 | // Highlight at the beginning - second |
| 592 | menuItem = menuItemClass.create(['CoreNLP', 'corenlp/', 'This is my Example']); |
| 593 | menuItem.highlight("this"); |
| 594 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span class=\"desc\"><mark>This</mark> is my Example</span>"); |
| 595 | |
| 596 | menuItem.lowlight(); |
| 597 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span class=\"desc\">This is my Example</span>"); |
| 598 | }); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 599 | }); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 600 | |
Akron | fac1647 | 2018-07-26 16:47:21 +0200 | [diff] [blame] | 601 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 602 | describe('KorAP.HintMenu', function () { |
Akron | fac1647 | 2018-07-26 16:47:21 +0200 | [diff] [blame] | 603 | beforeAll(beforeAllFunc); |
| 604 | afterAll(afterAllFunc); |
| 605 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 606 | var list = [ |
| 607 | ["Constituency", "c=", "Example 1"], |
| 608 | ["Lemma", "l="], |
| 609 | ["Morphology", "m=", "Example 2"], |
| 610 | ["Part-of-Speech", "p="], |
| 611 | ["Syntax", "syn="] |
| 612 | ]; |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 613 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 614 | it('should be initializable', function () { |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 615 | var menu = menuClass.create(null, "cnx/", list); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 616 | expect(menu.element().nodeName).toEqual('UL'); |
Akron | 65c7435 | 2016-09-02 17:23:39 +0200 | [diff] [blame] | 617 | // expect(menu.element().style.opacity).toEqual("0"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 618 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 619 | menu.limit(8); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 620 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 621 | // view |
| 622 | menu.show(); |
Akron | 6ed1399 | 2016-05-23 18:06:05 +0200 | [diff] [blame] | 623 | expect(menu.prefix()).toBe(''); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 624 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 625 | // First element in list |
| 626 | expect(menu.item(0).active()).toBe(true); |
| 627 | expect(menu.item(0).noMore()).toBe(true); |
| 628 | |
| 629 | // Middle element in list |
| 630 | expect(menu.item(2).active()).toBe(false); |
| 631 | expect(menu.item(2).noMore()).toBe(false); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 632 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 633 | // Last element in list |
| 634 | expect(menu.item(menu.length() - 1).active()).toBe(false); |
| 635 | expect(menu.item(menu.length() - 1).noMore()).toBe(true); |
Akron | 6ed1399 | 2016-05-23 18:06:05 +0200 | [diff] [blame] | 636 | |
| 637 | expect(menu.shownItem(0).active()).toBeTruthy(); |
| 638 | expect(menu.shownItem(0).lcField()).toEqual(' constituency example 1'); |
| 639 | expect(menu.shownItem(1).lcField()).toEqual(' lemma'); |
| 640 | expect(menu.shownItem(2).lcField()).toEqual(' morphology example 2'); |
| 641 | |
| 642 | menu.next(); |
| 643 | expect(menu.shownItem(1).active()).toBeTruthy(); |
| 644 | |
| 645 | menu.next(); |
| 646 | expect(menu.shownItem(2).active()).toBeTruthy(); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 647 | }); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 648 | }); |
| 649 | }); |