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