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