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