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