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