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"; |
| 8 | |
| 9 | keyboardEvent[initMethod]( |
| 10 | type, |
| 11 | true, // bubbles |
| 12 | true, // cancelable |
| 13 | window, // viewArg: should be window |
| 14 | false, // ctrlKeyArg |
| 15 | false, // altKeyArg |
| 16 | false, // shiftKeyArg |
| 17 | false, // metaKeyArg |
| 18 | keyCode, // keyCodeArg : unsigned long the virtual key code, else 0 |
| 19 | 0 // charCodeArgs : unsigned long the Unicode character |
| 20 | // associated with the depressed key, else 0 |
| 21 | ); |
| 22 | |
| 23 | element.dispatchEvent(keyboardEvent); |
| 24 | }; |
| 25 | |
| 26 | |
Nils Diewald | 5c5a747 | 2015-04-02 22:13:38 +0000 | [diff] [blame] | 27 | describe('KorAP.InputField', function () { |
| 28 | var input; |
| 29 | |
| 30 | beforeEach(function () { |
| 31 | input = document.createElement("input"); |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 32 | input.setAttribute('type', "text"); |
Nils Diewald | 5c5a747 | 2015-04-02 22:13:38 +0000 | [diff] [blame] | 33 | input.setAttribute("value", "abcdefghijklmno"); |
| 34 | input.style.position = 'absolute'; |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 35 | document.getElementsByTagName('body')[0].appendChild(input); |
Nils Diewald | 5c5a747 | 2015-04-02 22:13:38 +0000 | [diff] [blame] | 36 | input.style.top = "20px"; |
| 37 | input.style.left = "30px"; |
| 38 | input.focus(); |
| 39 | input.selectionStart = 5; |
| 40 | }); |
| 41 | |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 42 | afterEach(function () { |
| 43 | document.getElementsByTagName("body")[0].removeChild( |
| 44 | input |
| 45 | ); |
| 46 | }); |
| 47 | |
Nils Diewald | 5c5a747 | 2015-04-02 22:13:38 +0000 | [diff] [blame] | 48 | afterAll(function () { |
| 49 | try { |
Nils Diewald | 5c5a747 | 2015-04-02 22:13:38 +0000 | [diff] [blame] | 50 | document.getElementsByTagName("body")[0].removeChild( |
| 51 | document.getElementById("searchMirror") |
| 52 | ); |
| 53 | } |
| 54 | catch (e) {}; |
| 55 | }); |
| 56 | |
| 57 | it('should be initializable', function () { |
| 58 | // Supports: context, searchField |
| 59 | var inputField = KorAP.InputField.create(input); |
| 60 | expect(inputField._element).not.toBe(undefined); |
| 61 | }); |
| 62 | |
| 63 | it('should have text', function () { |
| 64 | expect(input.value).toEqual('abcdefghijklmno'); |
| 65 | var inputField = KorAP.InputField.create(input); |
| 66 | |
| 67 | expect(inputField.value()).toEqual("abcdefghijklmno"); |
| 68 | |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 69 | expect(input.selectionStart).toEqual(5); |
Nils Diewald | 5c5a747 | 2015-04-02 22:13:38 +0000 | [diff] [blame] | 70 | expect(inputField.element().selectionStart).toEqual(5); |
| 71 | expect(inputField.split()[0]).toEqual("abcde"); |
| 72 | expect(inputField.split()[1]).toEqual("fghijklmno"); |
| 73 | |
| 74 | inputField.insert("xyz"); |
| 75 | expect(inputField.value()).toEqual('abcdexyzfghijklmno'); |
| 76 | expect(inputField.split()[0]).toEqual("abcdexyz"); |
| 77 | expect(inputField.split()[1]).toEqual("fghijklmno"); |
| 78 | }); |
| 79 | |
| 80 | it('should be correctly positioned', function () { |
| 81 | expect(input.value).toEqual('abcdefghijklmno'); |
| 82 | var inputField = KorAP.InputField.create(input); |
| 83 | document.getElementsByTagName("body")[0].appendChild(input); |
| 84 | inputField.reposition(); |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 85 | expect(input.style.left).toEqual("30px"); |
| 86 | expect(inputField.mirror().style.left.match(/^(\d+)px$/)[1]).toBeGreaterThan(29); |
Nils Diewald | 5c5a747 | 2015-04-02 22:13:38 +0000 | [diff] [blame] | 87 | expect(inputField.mirror().style.top.match(/^(\d+)px$/)[1]).toBeGreaterThan(20); |
| 88 | }); |
| 89 | |
| 90 | it('should have a correct context', function () { |
| 91 | expect(input.value).toEqual('abcdefghijklmno'); |
| 92 | var inputField = KorAP.InputField.create(input); |
| 93 | |
| 94 | expect(inputField.value()).toEqual("abcdefghijklmno"); |
| 95 | |
| 96 | expect(inputField.element().selectionStart).toEqual(5); |
| 97 | expect(inputField.split()[0]).toEqual("abcde"); |
| 98 | expect(inputField.context()).toEqual("abcde"); |
| 99 | }); |
| 100 | |
| 101 | /* |
| 102 | it('should be correctly triggerable', function () { |
| 103 | // https://developer.mozilla.org/samples/domref/dispatchEvent.html |
| 104 | var hint = KorAP.Hint.create({ "inputField" : input }); |
| 105 | emitKeyboardEvent(hint.inputField.element, "keypress", 20); |
| 106 | }); |
| 107 | */ |
| 108 | }); |
| 109 | |
| 110 | |
| 111 | describe('KorAP.ContextAnalyzer', function () { |
| 112 | it('should be initializable', function () { |
| 113 | var analyzer = KorAP.ContextAnalyzer.create(")"); |
| 114 | expect(analyzer).toBe(undefined); |
| 115 | |
| 116 | analyzer = KorAP.ContextAnalyzer.create(".+?"); |
| 117 | expect(analyzer).not.toBe(undefined); |
| 118 | |
| 119 | }); |
| 120 | |
| 121 | it('should check correctly', function () { |
| 122 | analyzer = KorAP.ContextAnalyzer.create(KorAP.context); |
| 123 | expect(analyzer.test("cnx/]cnx/c=")).toEqual("cnx/c="); |
| 124 | expect(analyzer.test("cnx/c=")).toEqual("cnx/c="); |
| 125 | expect(analyzer.test("cnx/c=np mate/m=mood:")).toEqual("mate/m=mood:"); |
| 126 | expect(analyzer.test("impcnx/")).toEqual("impcnx/"); |
| 127 | expect(analyzer.test("cnx/c=npcnx/")).toEqual("npcnx/"); |
| 128 | expect(analyzer.test("mate/m=degree:pos corenlp/ne_dewac_175m_600=")) |
| 129 | .toEqual("corenlp/ne_dewac_175m_600="); |
| 130 | }); |
| 131 | }); |
| 132 | |
| 133 | |
| 134 | describe('KorAP.Hint', function () { |
| 135 | KorAP.hintArray = { |
| 136 | "corenlp/" : [ |
| 137 | ["Named Entity", "ne=" , "Combined"], |
| 138 | ["Named Entity", "ne_dewac_175m_600=" , "ne_dewac_175m_600"], |
| 139 | ["Named Entity", "ne_hgc_175m_600=", "ne_hgc_175m_600"] |
| 140 | ] |
| 141 | }; |
| 142 | |
| 143 | beforeEach(function () { |
| 144 | input = document.createElement("input"); |
| 145 | input.setAttribute("type", "text"); |
| 146 | input.setAttribute("value", "abcdefghijklmno"); |
| 147 | input.style.position = 'absolute'; |
| 148 | input.style.top = "20px"; |
| 149 | input.style.left = "30px"; |
| 150 | input.focus(); |
| 151 | input.selectionStart = 5; |
| 152 | }); |
| 153 | |
| 154 | it('should be initializable', function () { |
| 155 | // Supports: context, searchField |
| 156 | var hint = KorAP.Hint.create({ |
| 157 | inputField : input |
| 158 | }); |
| 159 | |
| 160 | expect(hint).toBeTruthy(); |
| 161 | }); |
| 162 | }); |
| 163 | |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 164 | describe('KorAP.HintMenuItem', function () { |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 165 | it('should be initializable', function () { |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 166 | expect( |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 167 | function() { KorAP.HintMenuItem.create([]) } |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 168 | ).toThrow(new Error("Missing parameters")); |
| 169 | |
| 170 | expect( |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 171 | function() { KorAP.HintMenuItem.create(['CoreNLP']) } |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 172 | ).toThrow(new Error("Missing parameters")); |
| 173 | |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 174 | var menuItem = KorAP.HintMenuItem.create(['CoreNLP', 'corenlp/']); |
| 175 | expect(menuItem.name()).toEqual('CoreNLP'); |
| 176 | expect(menuItem.action()).toEqual('corenlp/'); |
| 177 | expect(menuItem.desc()).toBeUndefined(); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 178 | |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 179 | menuItem = KorAP.HintMenuItem.create( |
| 180 | ['CoreNLP', 'corenlp/', 'It\'s funny'] |
| 181 | ); |
| 182 | expect(menuItem.name()).toEqual('CoreNLP'); |
| 183 | expect(menuItem.action()).toEqual('corenlp/'); |
| 184 | expect(menuItem.desc()).not.toBeUndefined(); |
| 185 | expect(menuItem.desc()).toEqual('It\'s funny'); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 186 | }); |
| 187 | |
| 188 | it('should have an element', function () { |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 189 | var menuItem = KorAP.HintMenuItem.create(['CoreNLP', 'corenlp/']); |
| 190 | expect(menuItem.element()).not.toBe(undefined); |
| 191 | expect(menuItem.element().nodeName).toEqual("LI"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 192 | |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 193 | var title = menuItem.element().firstChild; |
| 194 | expect(title.nodeName).toEqual("SPAN"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 195 | expect(title.firstChild.nodeType).toEqual(3); |
| 196 | expect(title.firstChild.nodeValue).toEqual("CoreNLP"); |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 197 | expect(menuItem.element().childNodes[0]).not.toBe(undefined); |
| 198 | expect(menuItem.element().childNodes[1]).toBe(undefined); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 199 | |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 200 | menuItem = KorAP.HintMenuItem.create( |
| 201 | ['CoreNLP', 'corenlp/', 'my DescRiption'] |
| 202 | ); |
| 203 | expect(menuItem.element()).not.toBe(undefined); |
| 204 | expect(menuItem.element().nodeName).toEqual("LI"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 205 | |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 206 | title = menuItem.element().firstChild; |
| 207 | expect(title.nodeName).toEqual("SPAN"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 208 | expect(title.firstChild.nodeType).toEqual(3); // TextNode |
| 209 | expect(title.firstChild.nodeValue).toEqual("CoreNLP"); |
| 210 | |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 211 | expect(menuItem.element().childNodes[0]).not.toBe(undefined); |
| 212 | expect(menuItem.element().childNodes[1]).not.toBe(undefined); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 213 | |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 214 | var desc = menuItem.element().lastChild; |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 215 | expect(desc.nodeName).toEqual("SPAN"); |
| 216 | expect(desc.firstChild.nodeType).toEqual(3); // TextNode |
| 217 | expect(desc.firstChild.nodeValue).toEqual("my DescRiption"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 218 | }); |
| 219 | |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 220 | |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 221 | it('should be activatable and deactivateable by class', function () { |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 222 | var menuItem = KorAP.HintMenuItem.create(['CoreNLP', 'corenlp/']); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 223 | expect(menuItem.active()).toBe(false); |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 224 | expect(menuItem.element().getAttribute("class")).toBe(null); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 225 | menuItem.active(true); |
| 226 | expect(menuItem.active()).toBe(true); |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 227 | expect(menuItem.element().getAttribute("class")).toEqual("active"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 228 | menuItem.active(false); // Is active |
| 229 | expect(menuItem.active()).toBe(false); |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 230 | expect(menuItem.element().getAttribute("class")).toEqual(""); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 231 | menuItem.active(true); |
| 232 | expect(menuItem.active()).toBe(true); |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 233 | expect(menuItem.element().getAttribute("class")).toEqual("active"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 234 | |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 235 | menuItem = KorAP.HintMenuItem.create(['CoreNLP', 'corenlp/']); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 236 | expect(menuItem.active()).toBe(false); |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 237 | expect(menuItem.element().getAttribute("class")).toBe(null); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 238 | menuItem.active(false); // Is not active |
| 239 | expect(menuItem.active()).toBe(false); |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 240 | expect(menuItem.element().getAttribute("class")).toBe(null); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 241 | }); |
| 242 | |
| 243 | it('should be set to boundary', function () { |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 244 | var menuItem = KorAP.HintMenuItem.create(['CoreNLP', 'corenlp/']); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 245 | expect(menuItem.active()).toBe(false); |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 246 | expect(menuItem.element().getAttribute("class")).toBe(null); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 247 | |
| 248 | // Set active |
| 249 | menuItem.active(true); |
| 250 | expect(menuItem.active()).toBe(true); |
| 251 | expect(menuItem.noMore()).toBe(false); |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 252 | expect(menuItem.element().getAttribute("class")).toEqual("active"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 253 | |
| 254 | // Set no more |
| 255 | menuItem.noMore(true); |
| 256 | expect(menuItem.active()).toBe(true); |
| 257 | expect(menuItem.noMore()).toBe(true); |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 258 | expect(menuItem.element().getAttribute("class")).toEqual("active no-more"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 259 | |
| 260 | // No no more |
| 261 | menuItem.noMore(false); |
| 262 | expect(menuItem.active()).toBe(true); |
| 263 | expect(menuItem.noMore()).toBe(false); |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 264 | expect(menuItem.element().getAttribute("class")).toEqual("active"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 265 | |
| 266 | // Set no more, deactivate |
| 267 | menuItem.noMore(true); |
| 268 | menuItem.active(false); |
| 269 | expect(menuItem.active()).toBe(false); |
| 270 | expect(menuItem.noMore()).toBe(true); |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 271 | expect(menuItem.element().getAttribute("class")).toEqual("no-more"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 272 | |
| 273 | // Set active |
| 274 | menuItem.active(true); |
| 275 | expect(menuItem.active()).toBe(true); |
| 276 | expect(menuItem.noMore()).toBe(true); |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 277 | expect(menuItem.element().getAttribute("class")).toEqual("no-more active"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 278 | }); |
| 279 | |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 280 | xit('should be highlightable', function () { |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 281 | // Highlight in the middle |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 282 | var menuItem = KorAP.HintMenuItem.create(['CoreNLP', 'corenlp/']); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 283 | menuItem.highlight("ren"); |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 284 | expect(menuItem.element().innerHTML).toEqual("<span>Co<mark>reN</mark>LP</span>"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 285 | |
| 286 | menuItem.lowlight(); |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 287 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 288 | |
| 289 | // Starting highlight |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 290 | menuItem = KorAP.HintMenuItem.create(['CoreNLP', 'corenlp/']); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 291 | menuItem.highlight("cor"); |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 292 | expect(menuItem.element().innerHTML).toEqual("<span><mark>Cor</mark>eNLP</span>"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 293 | |
| 294 | menuItem.lowlight(); |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 295 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>"); |
| 296 | /* |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 297 | |
| 298 | // Starting highlight - short |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 299 | menuItem = KorAP.HintMenuItem.create(['CoreNLP', 'corenlp/']); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 300 | menuItem.highlight("c"); |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 301 | expect(menuItem.element().innerHTML).toEqual("<span><mark>C</mark>oreNLP</span>"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 302 | |
| 303 | menuItem.lowlight(); |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 304 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 305 | |
| 306 | // Highlight at the end |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 307 | menuItem = KorAP.HintMenuItem.create(['CoreNLP', 'corenlp/']); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 308 | menuItem.highlight("nlp"); |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 309 | expect(menuItem.element().innerHTML).toEqual("<span>Core<mark>NLP</mark></span>"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 310 | |
| 311 | menuItem.lowlight(); |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 312 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 313 | |
| 314 | // Highlight at the end - short |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 315 | menuItem = KorAP.HintMenuItem.create(['CoreNLP', 'corenlp/']); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 316 | menuItem.highlight("p"); |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 317 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNL<mark>P</mark></span>"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 318 | |
| 319 | menuItem.lowlight(); |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 320 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 321 | |
| 322 | // No highlight |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 323 | menuItem = KorAP.HintMenuItem.create(['CoreNLP', 'corenlp/']); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 324 | menuItem.highlight("xp"); |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 325 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 326 | |
| 327 | menuItem.lowlight(); |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 328 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>"); |
| 329 | |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 330 | |
| 331 | // Highlight in the middle - first |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 332 | menuItem = KorAP.HintMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 333 | menuItem.highlight("ren"); |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 334 | expect(menuItem.element().innerHTML).toEqual("<span>Co<mark>reN</mark>LP</span><span class=\"desc\">This is my Example</span>"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 335 | |
| 336 | menuItem.lowlight(); |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 337 | expect(menuItem.element().innerHTML).toEqual('<span>CoreNLP</span><span class="desc">This is my Example</span>'); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 338 | |
| 339 | // Highlight in the middle - second |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 340 | menuItem = KorAP.HintMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 341 | menuItem.highlight("ampl"); |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 342 | expect(menuItem.element().innerHTML).toEqual('<span>CoreNLP</span><span class="desc">This is my Ex<mark>ampl</mark>e</span>'); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 343 | |
| 344 | menuItem.lowlight(); |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 345 | expect(menuItem.element().innerHTML).toEqual('<span>CoreNLP</span><span class="desc">This is my Example</span>'); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 346 | |
| 347 | // Highlight in the middle - both |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 348 | menuItem = KorAP.HintMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']); |
| 349 | |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 350 | menuItem.highlight("e"); |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 351 | 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>'); |
| 352 | |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 353 | |
| 354 | menuItem.lowlight(); |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 355 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span>This is my Example</span>"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 356 | |
| 357 | // Highlight in the end - second |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 358 | menuItem = KorAP.HintMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 359 | menuItem.highlight("le"); |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 360 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span>This is my Examp<mark>le</mark></span>"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 361 | |
| 362 | menuItem.lowlight(); |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 363 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span>This is my Example</span>"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 364 | |
| 365 | // Highlight at the beginning - second |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 366 | menuItem = KorAP.HintMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 367 | menuItem.highlight("this"); |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 368 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span><mark>This</mark> is my Example</span>"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 369 | |
| 370 | menuItem.lowlight(); |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame^] | 371 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span>This is my Example</span>"); |
| 372 | */ |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 373 | }); |
| 374 | }); |
| 375 | |
| 376 | |
Nils Diewald | 5c5a747 | 2015-04-02 22:13:38 +0000 | [diff] [blame] | 377 | describe('KorAP.HintMenu', function () { |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 378 | |
| 379 | var list = [ |
| 380 | ["Constituency", "c=", "Example 1"], |
| 381 | ["Lemma", "l="], |
| 382 | ["Morphology", "m=", "Example 2"], |
| 383 | ["Part-of-Speech", "p="], |
| 384 | ["Syntax", "syn="] |
| 385 | ]; |
| 386 | |
| 387 | |
| 388 | it('should be initializable', function () { |
| 389 | |
Nils Diewald | 5814133 | 2015-04-07 16:18:45 +0000 | [diff] [blame] | 390 | var menu = KorAP.HintMenu.create(null, "cnx/", list); |
Nils Diewald | 5c5a747 | 2015-04-02 22:13:38 +0000 | [diff] [blame] | 391 | expect(menu.context()).toEqual('cnx/'); |
| 392 | expect(menu.element().nodeName).toEqual('UL'); |
| 393 | expect(menu.element().style.opacity).toEqual("0"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 394 | |
Nils Diewald | 5c5a747 | 2015-04-02 22:13:38 +0000 | [diff] [blame] | 395 | menu.limit(8); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 396 | |
| 397 | // view |
| 398 | menu.show(); |
| 399 | |
| 400 | // First element in list |
| 401 | expect(menu.item(0).active()).toBe(true); |
| 402 | expect(menu.item(0).noMore()).toBe(true); |
| 403 | |
| 404 | // Middle element in list |
| 405 | expect(menu.item(2).active()).toBe(false); |
| 406 | expect(menu.item(2).noMore()).toBe(false); |
| 407 | |
| 408 | // Last element in list |
Nils Diewald | 5c5a747 | 2015-04-02 22:13:38 +0000 | [diff] [blame] | 409 | expect(menu.item(menu.length() - 1).active()).toBe(false); |
| 410 | expect(menu.item(menu.length() - 1).noMore()).toBe(true); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 411 | }); |
| 412 | }); |