Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 1 | function emitKeyboardEvent (element, type, keyCode) { |
| 2 | // event type : keydown, keyup, keypress |
| 3 | // http://stackoverflow.com/questions/596481/simulate-javascript-key-events |
| 4 | // http://stackoverflow.com/questions/961532/firing-a-keyboard-event-in-javascript |
| 5 | var keyboardEvent = document.createEvent("KeyboardEvent"); |
| 6 | var initMethod = typeof keyboardEvent.initKeyboardEvent !== 'undefined' ? |
| 7 | "initKeyboardEvent" : "initKeyEvent"; |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 8 | keyboardEvent[initMethod]( |
| 9 | type, |
Akron | 308db38 | 2016-05-30 22:34:07 +0200 | [diff] [blame] | 10 | true, // bubbles |
| 11 | true, // cancelable |
| 12 | window, // viewArg: should be window |
| 13 | false, // ctrlKeyArg |
| 14 | false, // altKeyArg |
| 15 | false, // shiftKeyArg |
| 16 | false, // metaKeyArg |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 17 | keyCode, // keyCodeArg : unsigned long the virtual key code, else 0 |
Akron | 308db38 | 2016-05-30 22:34:07 +0200 | [diff] [blame] | 18 | 0 // charCodeArgs : unsigned long the Unicode character |
| 19 | // associated with the depressed key, else 0 |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 20 | ); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 21 | element.dispatchEvent(keyboardEvent); |
| 22 | }; |
| 23 | |
| 24 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 25 | define(['hint'], function () { |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 26 | var hintClass = require("hint"); |
| 27 | var inputClass = require("hint/input"); |
| 28 | var contextClass = require("hint/contextanalyzer"); |
| 29 | var menuClass = require("hint/menu"); |
| 30 | var menuItemClass = require("hint/item"); |
Nils Diewald | 5c5a747 | 2015-04-02 22:13:38 +0000 | [diff] [blame] | 31 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 32 | describe('KorAP.InputField', function () { |
| 33 | var input; |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame] | 34 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 35 | beforeEach(function () { |
| 36 | input = document.createElement("input"); |
| 37 | input.setAttribute('type', "text"); |
| 38 | input.setAttribute("value", "abcdefghijklmno"); |
| 39 | input.style.position = 'absolute'; |
| 40 | document.getElementsByTagName('body')[0].appendChild(input); |
| 41 | input.style.top = "20px"; |
| 42 | input.style.left = "30px"; |
| 43 | input.focus(); |
| 44 | input.selectionStart = 5; |
Nils Diewald | 5c5a747 | 2015-04-02 22:13:38 +0000 | [diff] [blame] | 45 | }); |
| 46 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 47 | afterEach(function () { |
| 48 | document.getElementsByTagName("body")[0].removeChild( |
| 49 | input |
| 50 | ); |
| 51 | }); |
Nils Diewald | 5c5a747 | 2015-04-02 22:13:38 +0000 | [diff] [blame] | 52 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 53 | afterAll(function () { |
| 54 | try { |
Akron | 00cd4d1 | 2016-05-31 21:01:11 +0200 | [diff] [blame] | 55 | var mirrors = document.querySelectorAll(".hint.mirror"); |
| 56 | for (var i in mirrors) { |
| 57 | mirrors[i].parentNode.removeChild(mirrors[i]) |
| 58 | }; |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 59 | } |
| 60 | catch (e) {}; |
| 61 | }); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 62 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 63 | it('should be initializable', function () { |
| 64 | // Supports: context, searchField |
| 65 | var inputField = inputClass.create(input); |
| 66 | expect(inputField._element).not.toBe(undefined); |
| 67 | }); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 68 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 69 | it('should have text', function () { |
| 70 | expect(input.value).toEqual('abcdefghijklmno'); |
| 71 | var inputField = inputClass.create(input); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 72 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 73 | expect(inputField.value()).toEqual("abcdefghijklmno"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 74 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 75 | expect(input.selectionStart).toEqual(5); |
| 76 | expect(inputField.element().selectionStart).toEqual(5); |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 77 | expect(inputField._split()[0]).toEqual("abcde"); |
| 78 | expect(inputField._split()[1]).toEqual("fghijklmno"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 79 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 80 | inputField.insert("xyz"); |
| 81 | expect(inputField.value()).toEqual('abcdexyzfghijklmno'); |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 82 | expect(inputField._split()[0]).toEqual("abcdexyz"); |
| 83 | expect(inputField._split()[1]).toEqual("fghijklmno"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 84 | }); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 85 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 86 | it('should be correctly positioned', function () { |
| 87 | expect(input.value).toEqual('abcdefghijklmno'); |
| 88 | var inputField = inputClass.create(input); |
| 89 | document.getElementsByTagName("body")[0].appendChild(input); |
| 90 | inputField.reposition(); |
| 91 | expect(input.style.left).toEqual("30px"); |
| 92 | expect(inputField.mirror().style.left.match(/^(\d+)px$/)[1]).toBeGreaterThan(29); |
| 93 | expect(inputField.mirror().style.top.match(/^(\d+)px$/)[1]).toBeGreaterThan(20); |
| 94 | }); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 95 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 96 | it('should have a correct context', function () { |
| 97 | expect(input.value).toEqual('abcdefghijklmno'); |
| 98 | var inputField = inputClass.create(input); |
| 99 | expect(inputField.value()).toEqual("abcdefghijklmno"); |
| 100 | expect(inputField.element().selectionStart).toEqual(5); |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 101 | expect(inputField._split()[0]).toEqual("abcde"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 102 | expect(inputField.context()).toEqual("abcde"); |
| 103 | }); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 104 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 105 | /* |
| 106 | it('should be correctly triggerable', function () { |
| 107 | // https://developer.mozilla.org/samples/domref/dispatchEvent.html |
| 108 | var hint = KorAP.Hint.create({ "inputField" : input }); |
| 109 | emitKeyboardEvent(hint.inputField.element, "keypress", 20); |
| 110 | }); |
| 111 | */ |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 112 | }); |
| 113 | |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame] | 114 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 115 | describe('KorAP.ContextAnalyzer', function () { |
| 116 | it('should be initializable', function () { |
| 117 | var analyzer = contextClass.create(")"); |
| 118 | expect(analyzer).toBe(undefined); |
| 119 | analyzer = contextClass.create(".+?"); |
| 120 | expect(analyzer).not.toBe(undefined); |
| 121 | }); |
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 | it('should check correctly', function () { |
| 124 | analyzer = contextClass.create(KorAP.context); |
| 125 | expect(analyzer.test("cnx/]cnx/c=")).toEqual("cnx/c="); |
| 126 | expect(analyzer.test("cnx/c=")).toEqual("cnx/c="); |
| 127 | expect(analyzer.test("cnx/c=np mate/m=mood:")).toEqual("mate/m=mood:"); |
| 128 | expect(analyzer.test("impcnx/")).toEqual("impcnx/"); |
| 129 | expect(analyzer.test("cnx/c=npcnx/")).toEqual("npcnx/"); |
| 130 | expect(analyzer.test("mate/m=degree:pos corenlp/ne_dewac_175m_600=")) |
| 131 | .toEqual("corenlp/ne_dewac_175m_600="); |
Akron | 113cc1a | 2016-01-22 21:17:57 +0100 | [diff] [blame] | 132 | expect(analyzer.test("corenlp/")).toEqual("corenlp/"); |
| 133 | expect(analyzer.test("corenlp/c=")).toEqual("corenlp/c="); |
| 134 | expect(analyzer.test("corenlp/c=PP-")).toEqual("corenlp/c=PP-"); |
| 135 | expect(analyzer.test("corenlp/c=XY-")).toEqual("corenlp/c=XY-"); |
Akron | cff9bac | 2016-01-25 21:39:38 +0100 | [diff] [blame] | 136 | expect(analyzer.test("sgbr/l=")).toEqual("sgbr/l="); |
| 137 | expect(analyzer.test("sgbr/lv=")).toEqual("sgbr/lv="); |
| 138 | expect(analyzer.test("sgbr/p=")).toEqual("sgbr/p="); |
Akron | ee9ef4a | 2016-06-03 12:50:08 +0200 | [diff] [blame] | 139 | expect(analyzer.test("")).toEqual(undefined); |
| 140 | expect(analyzer.test("abcdecnx/")).toEqual("abcdecnx/"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 141 | }); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 142 | }); |
| 143 | |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 144 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 145 | describe('KorAP.Hint', function () { |
| 146 | KorAP.hintArray = { |
Akron | 02360e4 | 2016-06-07 13:41:12 +0200 | [diff] [blame] | 147 | "-" : [ |
| 148 | ["Base Annotation", "base/s=", "Structure"], |
| 149 | ["CoreNLP", "corenlp/", "Constituency, Named Entities, Part-of-Speech"] |
| 150 | ], |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 151 | "corenlp/" : [ |
| 152 | ["Named Entity", "ne=" , "Combined"], |
| 153 | ["Named Entity", "ne_dewac_175m_600=" , "ne_dewac_175m_600"], |
| 154 | ["Named Entity", "ne_hgc_175m_600=", "ne_hgc_175m_600"] |
| 155 | ] |
| 156 | }; |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 157 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 158 | beforeEach(function () { |
| 159 | input = document.createElement("input"); |
| 160 | input.setAttribute("type", "text"); |
| 161 | input.setAttribute("value", "abcdefghijklmno"); |
| 162 | input.style.position = 'absolute'; |
| 163 | input.style.top = "20px"; |
| 164 | input.style.left = "30px"; |
| 165 | input.focus(); |
| 166 | input.selectionStart = 5; |
| 167 | }); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 168 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 169 | it('should be initializable', function () { |
| 170 | // Supports: context, searchField |
| 171 | var hint = hintClass.create({ |
| 172 | inputField : input |
| 173 | }); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 174 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 175 | expect(hint).toBeTruthy(); |
| 176 | }); |
Akron | 00cd4d1 | 2016-05-31 21:01:11 +0200 | [diff] [blame] | 177 | |
| 178 | it('should alert at char pos', function () { |
| 179 | var hint = hintClass.create({ |
| 180 | inputField : input |
| 181 | }); |
| 182 | |
| 183 | expect(hint.active()).toBeFalsy(); |
| 184 | |
| 185 | expect(hint.alert(4, 'That does not work!')).toBeTruthy(); |
| 186 | |
| 187 | expect(hint.active()).toBeTruthy(); |
| 188 | |
| 189 | var container = hint.inputField().container(); |
| 190 | expect(container.firstChild.classList.contains('hint')).toBe(true); |
| 191 | expect(container.firstChild.classList.contains('alert')).toBe(true); |
| 192 | expect(container.firstChild.textContent).toEqual('That does not work!'); |
| 193 | expect(hint.inputField().mirrorValue()).toEqual('abcd'); |
| 194 | |
| 195 | expect(hint.alert(4, 'That does not work!')).toBeFalsy(); |
| 196 | |
| 197 | // Update - meaning: hide alert |
| 198 | hint.update(); |
| 199 | |
| 200 | expect(hint.alert().active).toBeFalsy(); |
| 201 | |
| 202 | expect(hint.active()).toBeFalsy(); |
Akron | ee9ef4a | 2016-06-03 12:50:08 +0200 | [diff] [blame] | 203 | }); |
Akron | 00cd4d1 | 2016-05-31 21:01:11 +0200 | [diff] [blame] | 204 | |
Akron | ee9ef4a | 2016-06-03 12:50:08 +0200 | [diff] [blame] | 205 | it('should view main menu on default', function () { |
| 206 | var hint = hintClass.create({ |
Akron | 8eaeb2e | 2016-08-29 18:26:28 +0200 | [diff] [blame] | 207 | inputField : input |
Akron | ee9ef4a | 2016-06-03 12:50:08 +0200 | [diff] [blame] | 208 | }); |
| 209 | |
| 210 | expect(hint.active()).toBeFalsy(); |
| 211 | |
| 212 | hint.inputField().insert('der Baum corenlp/'); |
Akron | ee9ef4a | 2016-06-03 12:50:08 +0200 | [diff] [blame] | 213 | |
Akron | 8eaeb2e | 2016-08-29 18:26:28 +0200 | [diff] [blame] | 214 | var cont = hint.inputField().container(); |
| 215 | |
| 216 | expect(cont.getElementsByTagName('div').length).toBe(1); |
| 217 | expect(cont.getElementsByTagName('ul').length).toBe(0); |
| 218 | expect(cont.firstChild).toEqual(cont.firstChild); |
| 219 | |
| 220 | // Show menu, if a relevant context exists |
| 221 | // There is a menu for corenlp/ |
Akron | 02360e4 | 2016-06-07 13:41:12 +0200 | [diff] [blame] | 222 | hint.show(false); |
| 223 | |
Akron | 8eaeb2e | 2016-08-29 18:26:28 +0200 | [diff] [blame] | 224 | expect(hint.inputField().container().getElementsByTagName('ul').length).toEqual(1); |
| 225 | expect(hint.inputField().container().getElementsByTagName('li').length).toEqual(3); |
| 226 | |
| 227 | // Hide the menu and focus on the input |
| 228 | hint.unshow(); |
| 229 | |
Akron | 02360e4 | 2016-06-07 13:41:12 +0200 | [diff] [blame] | 230 | console.log('1: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>'); |
| 231 | console.log(hint.inputField().container().innerHTML); |
Akron | ee9ef4a | 2016-06-03 12:50:08 +0200 | [diff] [blame] | 232 | |
Akron | 8eaeb2e | 2016-08-29 18:26:28 +0200 | [diff] [blame] | 233 | /* |
| 234 | |
| 235 | |
| 236 | |
Akron | ee9ef4a | 2016-06-03 12:50:08 +0200 | [diff] [blame] | 237 | expect(hint.inputField().container().getElementsByTagName('div').length).toEqual(4); |
Akron | 02360e4 | 2016-06-07 13:41:12 +0200 | [diff] [blame] | 238 | expect(hint.inputField().container().getElementsByTagName('li').length).toEqual(3); |
Akron | ee9ef4a | 2016-06-03 12:50:08 +0200 | [diff] [blame] | 239 | |
Akron | 02360e4 | 2016-06-07 13:41:12 +0200 | [diff] [blame] | 240 | hint.unshow(); |
Akron | ee9ef4a | 2016-06-03 12:50:08 +0200 | [diff] [blame] | 241 | hint.inputField().insert(' hhhh'); |
| 242 | // show with context |
Akron | 02360e4 | 2016-06-07 13:41:12 +0200 | [diff] [blame] | 243 | hint.show(false); |
| 244 | |
| 245 | console.log('2: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>'); |
| 246 | console.log(hint.inputField().container().innerHTML); |
Akron | ee9ef4a | 2016-06-03 12:50:08 +0200 | [diff] [blame] | 247 | |
| 248 | expect(hint.inputField().container().getElementsByTagName('div').length).toEqual(4); |
| 249 | expect(hint.inputField().container().getElementsByTagName('ul').length).toEqual(1); |
Akron | 02360e4 | 2016-06-07 13:41:12 +0200 | [diff] [blame] | 250 | expect(hint.inputField().container().getElementsByTagName('li').length).toEqual(2); |
| 251 | |
Akron | 8eaeb2e | 2016-08-29 18:26:28 +0200 | [diff] [blame] | 252 | |
| 253 | |
| 254 | |
| 255 | |
| 256 | |
Akron | 02360e4 | 2016-06-07 13:41:12 +0200 | [diff] [blame] | 257 | |
| 258 | |
Akron | ee9ef4a | 2016-06-03 12:50:08 +0200 | [diff] [blame] | 259 | |
| 260 | hint.unshow(); |
| 261 | hint.inputField().insert(' aaaa/'); |
| 262 | |
| 263 | // show with context |
| 264 | hint.show(true); |
| 265 | |
| 266 | console.log(hint.inputField().container().outerHTML); |
| 267 | |
| 268 | expect(hint.inputField().container().getElementsByTagName('div').length).toEqual(4); |
| 269 | expect(hint.inputField().container().getElementsByTagName('ul').length).toEqual(1); |
Akron | 02360e4 | 2016-06-07 13:41:12 +0200 | [diff] [blame] | 270 | */ |
Akron | 00cd4d1 | 2016-05-31 21:01:11 +0200 | [diff] [blame] | 271 | }); |
Akron | 02360e4 | 2016-06-07 13:41:12 +0200 | [diff] [blame] | 272 | |
| 273 | xit('should remove all menus on escape'); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 274 | }); |
| 275 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 276 | describe('KorAP.HintMenuItem', function () { |
| 277 | it('should be initializable', function () { |
| 278 | expect( |
| 279 | function() { menuItemClass.create([]) } |
| 280 | ).toThrow(new Error("Missing parameters")); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 281 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 282 | expect( |
| 283 | function() { menuItemClass.create(['CoreNLP']) } |
| 284 | ).toThrow(new Error("Missing parameters")); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 285 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 286 | var menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']); |
| 287 | expect(menuItem.name()).toEqual('CoreNLP'); |
| 288 | expect(menuItem.action()).toEqual('corenlp/'); |
| 289 | expect(menuItem.desc()).toBeUndefined(); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 290 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 291 | menuItem = menuItemClass.create( |
| 292 | ['CoreNLP', 'corenlp/', 'It\'s funny'] |
| 293 | ); |
| 294 | expect(menuItem.name()).toEqual('CoreNLP'); |
| 295 | expect(menuItem.action()).toEqual('corenlp/'); |
| 296 | expect(menuItem.desc()).not.toBeUndefined(); |
| 297 | expect(menuItem.desc()).toEqual('It\'s funny'); |
| 298 | }); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 299 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 300 | it('should have an element', function () { |
| 301 | var menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']); |
| 302 | expect(menuItem.element()).not.toBe(undefined); |
| 303 | expect(menuItem.element().nodeName).toEqual("LI"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 304 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 305 | var title = menuItem.element().firstChild; |
| 306 | expect(title.nodeName).toEqual("SPAN"); |
| 307 | expect(title.firstChild.nodeType).toEqual(3); |
| 308 | expect(title.firstChild.nodeValue).toEqual("CoreNLP"); |
| 309 | expect(menuItem.element().childNodes[0]).not.toBe(undefined); |
| 310 | expect(menuItem.element().childNodes[1]).toBe(undefined); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 311 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 312 | menuItem = menuItemClass.create( |
| 313 | ['CoreNLP', 'corenlp/', 'my DescRiption'] |
| 314 | ); |
| 315 | expect(menuItem.element()).not.toBe(undefined); |
| 316 | expect(menuItem.element().nodeName).toEqual("LI"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 317 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 318 | title = menuItem.element().firstChild; |
| 319 | expect(title.nodeName).toEqual("SPAN"); |
| 320 | expect(title.firstChild.nodeType).toEqual(3); // TextNode |
| 321 | expect(title.firstChild.nodeValue).toEqual("CoreNLP"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 322 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 323 | expect(menuItem.element().childNodes[0]).not.toBe(undefined); |
| 324 | expect(menuItem.element().childNodes[1]).not.toBe(undefined); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 325 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 326 | var desc = menuItem.element().lastChild; |
| 327 | expect(desc.nodeName).toEqual("SPAN"); |
| 328 | expect(desc.firstChild.nodeType).toEqual(3); // TextNode |
| 329 | expect(desc.firstChild.nodeValue).toEqual("my DescRiption"); |
| 330 | }); |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame] | 331 | |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 332 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 333 | it('should be activatable and deactivateable by class', function () { |
| 334 | var menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']); |
| 335 | expect(menuItem.active()).toBe(false); |
| 336 | expect(menuItem.element().getAttribute("class")).toBe(null); |
| 337 | menuItem.active(true); |
| 338 | expect(menuItem.active()).toBe(true); |
| 339 | expect(menuItem.element().getAttribute("class")).toEqual("active"); |
| 340 | menuItem.active(false); // Is active |
| 341 | expect(menuItem.active()).toBe(false); |
| 342 | expect(menuItem.element().getAttribute("class")).toEqual(""); |
| 343 | menuItem.active(true); |
| 344 | expect(menuItem.active()).toBe(true); |
| 345 | expect(menuItem.element().getAttribute("class")).toEqual("active"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 346 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 347 | menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']); |
| 348 | expect(menuItem.active()).toBe(false); |
| 349 | expect(menuItem.element().getAttribute("class")).toBe(null); |
| 350 | menuItem.active(false); // Is not active |
| 351 | expect(menuItem.active()).toBe(false); |
| 352 | expect(menuItem.element().getAttribute("class")).toBe(null); |
| 353 | }); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 354 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 355 | it('should be set to boundary', function () { |
| 356 | var menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']); |
| 357 | expect(menuItem.active()).toBe(false); |
| 358 | expect(menuItem.element().getAttribute("class")).toBe(null); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 359 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 360 | // Set active |
| 361 | menuItem.active(true); |
| 362 | expect(menuItem.active()).toBe(true); |
| 363 | expect(menuItem.noMore()).toBe(false); |
| 364 | expect(menuItem.element().getAttribute("class")).toEqual("active"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 365 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 366 | // Set no more |
| 367 | menuItem.noMore(true); |
| 368 | expect(menuItem.active()).toBe(true); |
| 369 | expect(menuItem.noMore()).toBe(true); |
| 370 | expect(menuItem.element().getAttribute("class")).toEqual("active no-more"); |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame] | 371 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 372 | // No no more |
| 373 | menuItem.noMore(false); |
| 374 | expect(menuItem.active()).toBe(true); |
| 375 | expect(menuItem.noMore()).toBe(false); |
| 376 | expect(menuItem.element().getAttribute("class")).toEqual("active"); |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame] | 377 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 378 | // Set no more, deactivate |
| 379 | menuItem.noMore(true); |
| 380 | menuItem.active(false); |
| 381 | expect(menuItem.active()).toBe(false); |
| 382 | expect(menuItem.noMore()).toBe(true); |
| 383 | expect(menuItem.element().getAttribute("class")).toEqual("no-more"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 384 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 385 | // Set active |
| 386 | menuItem.active(true); |
| 387 | expect(menuItem.active()).toBe(true); |
| 388 | expect(menuItem.noMore()).toBe(true); |
| 389 | expect(menuItem.element().getAttribute("class")).toEqual("no-more active"); |
| 390 | }); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 391 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 392 | it('should be highlightable', function () { |
| 393 | // Highlight in the middle |
| 394 | var menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']); |
| 395 | menuItem.highlight("ren"); |
| 396 | expect(menuItem.element().innerHTML).toEqual("<span>Co<mark>reN</mark>LP</span>"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 397 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 398 | menuItem.lowlight(); |
| 399 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 400 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 401 | // Starting highlight |
| 402 | menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']); |
| 403 | menuItem.highlight("cor"); |
| 404 | expect(menuItem.element().innerHTML).toEqual("<span><mark>Cor</mark>eNLP</span>"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 405 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 406 | menuItem.lowlight(); |
| 407 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>"); |
| 408 | |
| 409 | // Starting highlight - short |
| 410 | menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']); |
| 411 | menuItem.highlight("c"); |
| 412 | expect(menuItem.element().innerHTML).toEqual("<span><mark>C</mark>oreNLP</span>"); |
| 413 | |
| 414 | menuItem.lowlight(); |
| 415 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>"); |
| 416 | |
| 417 | // Highlight at the end |
| 418 | menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']); |
| 419 | menuItem.highlight("nlp"); |
| 420 | expect(menuItem.element().innerHTML).toEqual("<span>Core<mark>NLP</mark></span>"); |
| 421 | |
| 422 | menuItem.lowlight(); |
| 423 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>"); |
| 424 | |
| 425 | // Highlight at the end - short |
| 426 | menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']); |
| 427 | menuItem.highlight("p"); |
| 428 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNL<mark>P</mark></span>"); |
| 429 | |
| 430 | menuItem.lowlight(); |
| 431 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>"); |
| 432 | |
| 433 | // No highlight |
| 434 | menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']); |
| 435 | menuItem.highlight("xp"); |
| 436 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>"); |
| 437 | |
| 438 | menuItem.lowlight(); |
| 439 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>"); |
| 440 | |
| 441 | // Highlight in the middle - first |
| 442 | menuItem = menuItemClass.create(['CoreNLP', 'corenlp/', 'This is my Example']); |
| 443 | |
| 444 | menuItem.highlight("ren"); |
| 445 | expect(menuItem.element().innerHTML).toEqual("<span>Co<mark>reN</mark>LP</span><span class=\"desc\">This is my Example</span>"); |
| 446 | |
| 447 | menuItem.lowlight(); |
| 448 | expect(menuItem.element().innerHTML).toEqual('<span>CoreNLP</span><span class="desc">This is my Example</span>'); |
| 449 | |
| 450 | // Highlight in the middle - second |
| 451 | menuItem = menuItemClass.create(['CoreNLP', 'corenlp/', 'This is my Example']); |
| 452 | menuItem.highlight("ampl"); |
| 453 | expect(menuItem.element().innerHTML).toEqual('<span>CoreNLP</span><span class="desc">This is my Ex<mark>ampl</mark>e</span>'); |
| 454 | |
| 455 | menuItem.lowlight(); |
| 456 | expect(menuItem.element().innerHTML).toEqual('<span>CoreNLP</span><span class="desc">This is my Example</span>'); |
| 457 | |
| 458 | // Highlight in the middle - both |
| 459 | menuItem = menuItemClass.create(['CoreNLP', 'corenlp/', 'This is my Example']); |
| 460 | |
| 461 | menuItem.highlight("e"); |
| 462 | 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>'); |
| 463 | |
| 464 | menuItem.lowlight(); |
| 465 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span class=\"desc\">This is my Example</span>"); |
| 466 | |
| 467 | // Highlight in the end - second |
| 468 | menuItem = menuItemClass.create(['CoreNLP', 'corenlp/', 'This is my Example']); |
| 469 | menuItem.highlight("le"); |
| 470 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span class=\"desc\">This is my Examp<mark>le</mark></span>"); |
| 471 | |
| 472 | menuItem.lowlight(); |
| 473 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span class=\"desc\">This is my Example</span>"); |
| 474 | |
| 475 | // Highlight at the beginning - second |
| 476 | menuItem = menuItemClass.create(['CoreNLP', 'corenlp/', 'This is my Example']); |
| 477 | menuItem.highlight("this"); |
| 478 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span class=\"desc\"><mark>This</mark> is my Example</span>"); |
| 479 | |
| 480 | menuItem.lowlight(); |
| 481 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span class=\"desc\">This is my Example</span>"); |
Akron | 6ed1399 | 2016-05-23 18:06:05 +0200 | [diff] [blame] | 482 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 483 | }); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 484 | }); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 485 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 486 | describe('KorAP.HintMenu', function () { |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 487 | var list = [ |
| 488 | ["Constituency", "c=", "Example 1"], |
| 489 | ["Lemma", "l="], |
| 490 | ["Morphology", "m=", "Example 2"], |
| 491 | ["Part-of-Speech", "p="], |
| 492 | ["Syntax", "syn="] |
| 493 | ]; |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 494 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 495 | it('should be initializable', function () { |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 496 | var menu = menuClass.create(null, "cnx/", list); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 497 | expect(menu.element().nodeName).toEqual('UL'); |
| 498 | expect(menu.element().style.opacity).toEqual("0"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 499 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 500 | menu.limit(8); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 501 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 502 | // view |
| 503 | menu.show(); |
Akron | 6ed1399 | 2016-05-23 18:06:05 +0200 | [diff] [blame] | 504 | expect(menu.prefix()).toBe(''); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 505 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 506 | // First element in list |
| 507 | expect(menu.item(0).active()).toBe(true); |
| 508 | expect(menu.item(0).noMore()).toBe(true); |
| 509 | |
| 510 | // Middle element in list |
| 511 | expect(menu.item(2).active()).toBe(false); |
| 512 | expect(menu.item(2).noMore()).toBe(false); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 513 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 514 | // Last element in list |
| 515 | expect(menu.item(menu.length() - 1).active()).toBe(false); |
| 516 | expect(menu.item(menu.length() - 1).noMore()).toBe(true); |
Akron | 6ed1399 | 2016-05-23 18:06:05 +0200 | [diff] [blame] | 517 | |
| 518 | expect(menu.shownItem(0).active()).toBeTruthy(); |
| 519 | expect(menu.shownItem(0).lcField()).toEqual(' constituency example 1'); |
| 520 | expect(menu.shownItem(1).lcField()).toEqual(' lemma'); |
| 521 | expect(menu.shownItem(2).lcField()).toEqual(' morphology example 2'); |
| 522 | |
| 523 | menu.next(); |
| 524 | expect(menu.shownItem(1).active()).toBeTruthy(); |
| 525 | |
| 526 | menu.next(); |
| 527 | expect(menu.shownItem(2).active()).toBeTruthy(); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 528 | }); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 529 | }); |
| 530 | }); |