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