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 = { |
| 148 | "corenlp/" : [ |
| 149 | ["Named Entity", "ne=" , "Combined"], |
| 150 | ["Named Entity", "ne_dewac_175m_600=" , "ne_dewac_175m_600"], |
| 151 | ["Named Entity", "ne_hgc_175m_600=", "ne_hgc_175m_600"] |
| 152 | ] |
| 153 | }; |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 154 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 155 | beforeEach(function () { |
| 156 | input = document.createElement("input"); |
| 157 | input.setAttribute("type", "text"); |
| 158 | input.setAttribute("value", "abcdefghijklmno"); |
| 159 | input.style.position = 'absolute'; |
| 160 | input.style.top = "20px"; |
| 161 | input.style.left = "30px"; |
| 162 | input.focus(); |
| 163 | input.selectionStart = 5; |
| 164 | }); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 165 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 166 | it('should be initializable', function () { |
| 167 | // Supports: context, searchField |
| 168 | var hint = hintClass.create({ |
| 169 | inputField : input |
| 170 | }); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 171 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 172 | expect(hint).toBeTruthy(); |
| 173 | }); |
Akron | 00cd4d1 | 2016-05-31 21:01:11 +0200 | [diff] [blame] | 174 | |
| 175 | it('should alert at char pos', function () { |
| 176 | var hint = hintClass.create({ |
| 177 | inputField : input |
| 178 | }); |
| 179 | |
| 180 | expect(hint.active()).toBeFalsy(); |
| 181 | |
| 182 | expect(hint.alert(4, 'That does not work!')).toBeTruthy(); |
| 183 | |
| 184 | expect(hint.active()).toBeTruthy(); |
| 185 | |
| 186 | var container = hint.inputField().container(); |
| 187 | expect(container.firstChild.classList.contains('hint')).toBe(true); |
| 188 | expect(container.firstChild.classList.contains('alert')).toBe(true); |
| 189 | expect(container.firstChild.textContent).toEqual('That does not work!'); |
| 190 | expect(hint.inputField().mirrorValue()).toEqual('abcd'); |
| 191 | |
| 192 | expect(hint.alert(4, 'That does not work!')).toBeFalsy(); |
| 193 | |
| 194 | // Update - meaning: hide alert |
| 195 | hint.update(); |
| 196 | |
| 197 | expect(hint.alert().active).toBeFalsy(); |
| 198 | |
| 199 | expect(hint.active()).toBeFalsy(); |
Akron | ee9ef4a | 2016-06-03 12:50:08 +0200 | [diff] [blame] | 200 | }); |
Akron | 00cd4d1 | 2016-05-31 21:01:11 +0200 | [diff] [blame] | 201 | |
Akron | ee9ef4a | 2016-06-03 12:50:08 +0200 | [diff] [blame] | 202 | it('should view main menu on default', function () { |
| 203 | var hint = hintClass.create({ |
| 204 | inputField : input |
| 205 | }); |
| 206 | |
| 207 | expect(hint.active()).toBeFalsy(); |
| 208 | |
| 209 | hint.inputField().insert('der Baum corenlp/'); |
| 210 | expect(hint.inputField().container().getElementsByTagName('div').length).toBe(1); |
| 211 | expect(hint.inputField().container().getElementsByTagName('ul').length).toBe(0); |
| 212 | |
| 213 | // show with context |
| 214 | hint.unshow(); |
| 215 | hint.show(true); |
| 216 | |
| 217 | expect(hint.inputField().container().getElementsByTagName('div').length).toEqual(4); |
| 218 | expect(hint.inputField().container().getElementsByTagName('ul').length).toEqual(1); |
| 219 | |
| 220 | hint.inputField().insert(' hhhh'); |
| 221 | // show with context |
| 222 | hint.unshow(); |
| 223 | hint.show(true); |
| 224 | |
| 225 | expect(hint.inputField().container().getElementsByTagName('div').length).toEqual(4); |
| 226 | expect(hint.inputField().container().getElementsByTagName('ul').length).toEqual(1); |
| 227 | |
| 228 | hint.unshow(); |
| 229 | hint.inputField().insert(' aaaa/'); |
| 230 | |
| 231 | // show with context |
| 232 | hint.show(true); |
| 233 | |
| 234 | console.log(hint.inputField().container().outerHTML); |
| 235 | |
| 236 | expect(hint.inputField().container().getElementsByTagName('div').length).toEqual(4); |
| 237 | expect(hint.inputField().container().getElementsByTagName('ul').length).toEqual(1); |
Akron | 00cd4d1 | 2016-05-31 21:01:11 +0200 | [diff] [blame] | 238 | }); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 239 | }); |
| 240 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 241 | describe('KorAP.HintMenuItem', function () { |
| 242 | it('should be initializable', function () { |
| 243 | expect( |
| 244 | function() { menuItemClass.create([]) } |
| 245 | ).toThrow(new Error("Missing parameters")); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 246 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 247 | expect( |
| 248 | function() { menuItemClass.create(['CoreNLP']) } |
| 249 | ).toThrow(new Error("Missing parameters")); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 250 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 251 | var menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']); |
| 252 | expect(menuItem.name()).toEqual('CoreNLP'); |
| 253 | expect(menuItem.action()).toEqual('corenlp/'); |
| 254 | expect(menuItem.desc()).toBeUndefined(); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 255 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 256 | menuItem = menuItemClass.create( |
| 257 | ['CoreNLP', 'corenlp/', 'It\'s funny'] |
| 258 | ); |
| 259 | expect(menuItem.name()).toEqual('CoreNLP'); |
| 260 | expect(menuItem.action()).toEqual('corenlp/'); |
| 261 | expect(menuItem.desc()).not.toBeUndefined(); |
| 262 | expect(menuItem.desc()).toEqual('It\'s funny'); |
| 263 | }); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 264 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 265 | it('should have an element', function () { |
| 266 | var menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']); |
| 267 | expect(menuItem.element()).not.toBe(undefined); |
| 268 | expect(menuItem.element().nodeName).toEqual("LI"); |
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 title = menuItem.element().firstChild; |
| 271 | expect(title.nodeName).toEqual("SPAN"); |
| 272 | expect(title.firstChild.nodeType).toEqual(3); |
| 273 | expect(title.firstChild.nodeValue).toEqual("CoreNLP"); |
| 274 | expect(menuItem.element().childNodes[0]).not.toBe(undefined); |
| 275 | expect(menuItem.element().childNodes[1]).toBe(undefined); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 276 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 277 | menuItem = menuItemClass.create( |
| 278 | ['CoreNLP', 'corenlp/', 'my DescRiption'] |
| 279 | ); |
| 280 | expect(menuItem.element()).not.toBe(undefined); |
| 281 | expect(menuItem.element().nodeName).toEqual("LI"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 282 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 283 | title = menuItem.element().firstChild; |
| 284 | expect(title.nodeName).toEqual("SPAN"); |
| 285 | expect(title.firstChild.nodeType).toEqual(3); // TextNode |
| 286 | expect(title.firstChild.nodeValue).toEqual("CoreNLP"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 287 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 288 | expect(menuItem.element().childNodes[0]).not.toBe(undefined); |
| 289 | expect(menuItem.element().childNodes[1]).not.toBe(undefined); |
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 | var desc = menuItem.element().lastChild; |
| 292 | expect(desc.nodeName).toEqual("SPAN"); |
| 293 | expect(desc.firstChild.nodeType).toEqual(3); // TextNode |
| 294 | expect(desc.firstChild.nodeValue).toEqual("my DescRiption"); |
| 295 | }); |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame] | 296 | |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 297 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 298 | it('should be activatable and deactivateable by class', function () { |
| 299 | var menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']); |
| 300 | expect(menuItem.active()).toBe(false); |
| 301 | expect(menuItem.element().getAttribute("class")).toBe(null); |
| 302 | menuItem.active(true); |
| 303 | expect(menuItem.active()).toBe(true); |
| 304 | expect(menuItem.element().getAttribute("class")).toEqual("active"); |
| 305 | menuItem.active(false); // Is active |
| 306 | expect(menuItem.active()).toBe(false); |
| 307 | expect(menuItem.element().getAttribute("class")).toEqual(""); |
| 308 | menuItem.active(true); |
| 309 | expect(menuItem.active()).toBe(true); |
| 310 | expect(menuItem.element().getAttribute("class")).toEqual("active"); |
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(['CoreNLP', 'corenlp/']); |
| 313 | expect(menuItem.active()).toBe(false); |
| 314 | expect(menuItem.element().getAttribute("class")).toBe(null); |
| 315 | menuItem.active(false); // Is not active |
| 316 | expect(menuItem.active()).toBe(false); |
| 317 | expect(menuItem.element().getAttribute("class")).toBe(null); |
| 318 | }); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 319 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 320 | it('should be set to boundary', function () { |
| 321 | var menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']); |
| 322 | expect(menuItem.active()).toBe(false); |
| 323 | expect(menuItem.element().getAttribute("class")).toBe(null); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 324 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 325 | // Set active |
| 326 | menuItem.active(true); |
| 327 | expect(menuItem.active()).toBe(true); |
| 328 | expect(menuItem.noMore()).toBe(false); |
| 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 | // Set no more |
| 332 | menuItem.noMore(true); |
| 333 | expect(menuItem.active()).toBe(true); |
| 334 | expect(menuItem.noMore()).toBe(true); |
| 335 | expect(menuItem.element().getAttribute("class")).toEqual("active no-more"); |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame] | 336 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 337 | // No no more |
| 338 | menuItem.noMore(false); |
| 339 | expect(menuItem.active()).toBe(true); |
| 340 | expect(menuItem.noMore()).toBe(false); |
| 341 | expect(menuItem.element().getAttribute("class")).toEqual("active"); |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame] | 342 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 343 | // Set no more, deactivate |
| 344 | menuItem.noMore(true); |
| 345 | menuItem.active(false); |
| 346 | expect(menuItem.active()).toBe(false); |
| 347 | expect(menuItem.noMore()).toBe(true); |
| 348 | expect(menuItem.element().getAttribute("class")).toEqual("no-more"); |
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 active |
| 351 | menuItem.active(true); |
| 352 | expect(menuItem.active()).toBe(true); |
| 353 | expect(menuItem.noMore()).toBe(true); |
| 354 | expect(menuItem.element().getAttribute("class")).toEqual("no-more active"); |
| 355 | }); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 356 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 357 | it('should be highlightable', function () { |
| 358 | // Highlight in the middle |
| 359 | var menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']); |
| 360 | menuItem.highlight("ren"); |
| 361 | expect(menuItem.element().innerHTML).toEqual("<span>Co<mark>reN</mark>LP</span>"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 362 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 363 | menuItem.lowlight(); |
| 364 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>"); |
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 | // Starting highlight |
| 367 | menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']); |
| 368 | menuItem.highlight("cor"); |
| 369 | expect(menuItem.element().innerHTML).toEqual("<span><mark>Cor</mark>eNLP</span>"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 370 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 371 | menuItem.lowlight(); |
| 372 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>"); |
| 373 | |
| 374 | // Starting highlight - short |
| 375 | menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']); |
| 376 | menuItem.highlight("c"); |
| 377 | expect(menuItem.element().innerHTML).toEqual("<span><mark>C</mark>oreNLP</span>"); |
| 378 | |
| 379 | menuItem.lowlight(); |
| 380 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>"); |
| 381 | |
| 382 | // Highlight at the end |
| 383 | menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']); |
| 384 | menuItem.highlight("nlp"); |
| 385 | expect(menuItem.element().innerHTML).toEqual("<span>Core<mark>NLP</mark></span>"); |
| 386 | |
| 387 | menuItem.lowlight(); |
| 388 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>"); |
| 389 | |
| 390 | // Highlight at the end - short |
| 391 | menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']); |
| 392 | menuItem.highlight("p"); |
| 393 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNL<mark>P</mark></span>"); |
| 394 | |
| 395 | menuItem.lowlight(); |
| 396 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>"); |
| 397 | |
| 398 | // No highlight |
| 399 | menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']); |
| 400 | menuItem.highlight("xp"); |
| 401 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>"); |
| 402 | |
| 403 | menuItem.lowlight(); |
| 404 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>"); |
| 405 | |
| 406 | // Highlight in the middle - first |
| 407 | menuItem = menuItemClass.create(['CoreNLP', 'corenlp/', 'This is my Example']); |
| 408 | |
| 409 | menuItem.highlight("ren"); |
| 410 | expect(menuItem.element().innerHTML).toEqual("<span>Co<mark>reN</mark>LP</span><span class=\"desc\">This is my Example</span>"); |
| 411 | |
| 412 | menuItem.lowlight(); |
| 413 | expect(menuItem.element().innerHTML).toEqual('<span>CoreNLP</span><span class="desc">This is my Example</span>'); |
| 414 | |
| 415 | // Highlight in the middle - second |
| 416 | menuItem = menuItemClass.create(['CoreNLP', 'corenlp/', 'This is my Example']); |
| 417 | menuItem.highlight("ampl"); |
| 418 | expect(menuItem.element().innerHTML).toEqual('<span>CoreNLP</span><span class="desc">This is my Ex<mark>ampl</mark>e</span>'); |
| 419 | |
| 420 | menuItem.lowlight(); |
| 421 | expect(menuItem.element().innerHTML).toEqual('<span>CoreNLP</span><span class="desc">This is my Example</span>'); |
| 422 | |
| 423 | // Highlight in the middle - both |
| 424 | menuItem = menuItemClass.create(['CoreNLP', 'corenlp/', 'This is my Example']); |
| 425 | |
| 426 | menuItem.highlight("e"); |
| 427 | 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>'); |
| 428 | |
| 429 | menuItem.lowlight(); |
| 430 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span class=\"desc\">This is my Example</span>"); |
| 431 | |
| 432 | // Highlight in the end - second |
| 433 | menuItem = menuItemClass.create(['CoreNLP', 'corenlp/', 'This is my Example']); |
| 434 | menuItem.highlight("le"); |
| 435 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span class=\"desc\">This is my Examp<mark>le</mark></span>"); |
| 436 | |
| 437 | menuItem.lowlight(); |
| 438 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span class=\"desc\">This is my Example</span>"); |
| 439 | |
| 440 | // Highlight at the beginning - second |
| 441 | menuItem = menuItemClass.create(['CoreNLP', 'corenlp/', 'This is my Example']); |
| 442 | menuItem.highlight("this"); |
| 443 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span class=\"desc\"><mark>This</mark> is my Example</span>"); |
| 444 | |
| 445 | menuItem.lowlight(); |
| 446 | 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] | 447 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 448 | }); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 449 | }); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 450 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 451 | describe('KorAP.HintMenu', function () { |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 452 | var list = [ |
| 453 | ["Constituency", "c=", "Example 1"], |
| 454 | ["Lemma", "l="], |
| 455 | ["Morphology", "m=", "Example 2"], |
| 456 | ["Part-of-Speech", "p="], |
| 457 | ["Syntax", "syn="] |
| 458 | ]; |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 459 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 460 | it('should be initializable', function () { |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 461 | var menu = menuClass.create(null, "cnx/", list); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 462 | expect(menu.element().nodeName).toEqual('UL'); |
| 463 | expect(menu.element().style.opacity).toEqual("0"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 464 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 465 | menu.limit(8); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 466 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 467 | // view |
| 468 | menu.show(); |
Akron | 6ed1399 | 2016-05-23 18:06:05 +0200 | [diff] [blame] | 469 | expect(menu.prefix()).toBe(''); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 470 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 471 | // First element in list |
| 472 | expect(menu.item(0).active()).toBe(true); |
| 473 | expect(menu.item(0).noMore()).toBe(true); |
| 474 | |
| 475 | // Middle element in list |
| 476 | expect(menu.item(2).active()).toBe(false); |
| 477 | expect(menu.item(2).noMore()).toBe(false); |
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 | // Last element in list |
| 480 | expect(menu.item(menu.length() - 1).active()).toBe(false); |
| 481 | expect(menu.item(menu.length() - 1).noMore()).toBe(true); |
Akron | 6ed1399 | 2016-05-23 18:06:05 +0200 | [diff] [blame] | 482 | |
| 483 | expect(menu.shownItem(0).active()).toBeTruthy(); |
| 484 | expect(menu.shownItem(0).lcField()).toEqual(' constituency example 1'); |
| 485 | expect(menu.shownItem(1).lcField()).toEqual(' lemma'); |
| 486 | expect(menu.shownItem(2).lcField()).toEqual(' morphology example 2'); |
| 487 | |
| 488 | menu.next(); |
| 489 | expect(menu.shownItem(1).active()).toBeTruthy(); |
| 490 | |
| 491 | menu.next(); |
| 492 | expect(menu.shownItem(2).active()).toBeTruthy(); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 493 | }); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 494 | }); |
| 495 | }); |