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