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, |
| 10 | true, // bubbles |
| 11 | true, // cancelable |
| 12 | window, // viewArg: should be window |
| 13 | false, // ctrlKeyArg |
| 14 | false, // altKeyArg |
| 15 | false, // shiftKeyArg |
| 16 | false, // metaKeyArg |
| 17 | keyCode, // keyCodeArg : unsigned long the virtual key code, else 0 |
| 18 | 0 // charCodeArgs : unsigned long the Unicode character |
| 19 | // associated with the depressed key, else 0 |
| 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 { |
| 56 | document.getElementsByTagName("body")[0].removeChild( |
| 57 | document.getElementById("searchMirror") |
| 58 | ); |
| 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); |
| 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'); |
| 82 | expect(inputField.split()[0]).toEqual("abcdexyz"); |
| 83 | expect(inputField.split()[1]).toEqual("fghijklmno"); |
| 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); |
| 101 | expect(inputField.split()[0]).toEqual("abcde"); |
| 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="); |
| 132 | }); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 133 | }); |
| 134 | |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 135 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 136 | describe('KorAP.Hint', function () { |
| 137 | KorAP.hintArray = { |
| 138 | "corenlp/" : [ |
| 139 | ["Named Entity", "ne=" , "Combined"], |
| 140 | ["Named Entity", "ne_dewac_175m_600=" , "ne_dewac_175m_600"], |
| 141 | ["Named Entity", "ne_hgc_175m_600=", "ne_hgc_175m_600"] |
| 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 | beforeEach(function () { |
| 146 | input = document.createElement("input"); |
| 147 | input.setAttribute("type", "text"); |
| 148 | input.setAttribute("value", "abcdefghijklmno"); |
| 149 | input.style.position = 'absolute'; |
| 150 | input.style.top = "20px"; |
| 151 | input.style.left = "30px"; |
| 152 | input.focus(); |
| 153 | input.selectionStart = 5; |
| 154 | }); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 155 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 156 | it('should be initializable', function () { |
| 157 | // Supports: context, searchField |
| 158 | var hint = hintClass.create({ |
| 159 | inputField : input |
| 160 | }); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 161 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 162 | expect(hint).toBeTruthy(); |
| 163 | }); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 164 | }); |
| 165 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 166 | describe('KorAP.HintMenuItem', function () { |
| 167 | it('should be initializable', function () { |
| 168 | expect( |
| 169 | function() { menuItemClass.create([]) } |
| 170 | ).toThrow(new Error("Missing parameters")); |
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( |
| 173 | function() { menuItemClass.create(['CoreNLP']) } |
| 174 | ).toThrow(new Error("Missing parameters")); |
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 | var menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']); |
| 177 | expect(menuItem.name()).toEqual('CoreNLP'); |
| 178 | expect(menuItem.action()).toEqual('corenlp/'); |
| 179 | expect(menuItem.desc()).toBeUndefined(); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 180 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 181 | menuItem = menuItemClass.create( |
| 182 | ['CoreNLP', 'corenlp/', 'It\'s funny'] |
| 183 | ); |
| 184 | expect(menuItem.name()).toEqual('CoreNLP'); |
| 185 | expect(menuItem.action()).toEqual('corenlp/'); |
| 186 | expect(menuItem.desc()).not.toBeUndefined(); |
| 187 | expect(menuItem.desc()).toEqual('It\'s funny'); |
| 188 | }); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 189 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 190 | it('should have an element', function () { |
| 191 | var menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']); |
| 192 | expect(menuItem.element()).not.toBe(undefined); |
| 193 | expect(menuItem.element().nodeName).toEqual("LI"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 194 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 195 | var title = menuItem.element().firstChild; |
| 196 | expect(title.nodeName).toEqual("SPAN"); |
| 197 | expect(title.firstChild.nodeType).toEqual(3); |
| 198 | expect(title.firstChild.nodeValue).toEqual("CoreNLP"); |
| 199 | expect(menuItem.element().childNodes[0]).not.toBe(undefined); |
| 200 | expect(menuItem.element().childNodes[1]).toBe(undefined); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 201 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 202 | menuItem = menuItemClass.create( |
| 203 | ['CoreNLP', 'corenlp/', 'my DescRiption'] |
| 204 | ); |
| 205 | expect(menuItem.element()).not.toBe(undefined); |
| 206 | expect(menuItem.element().nodeName).toEqual("LI"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 207 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 208 | title = menuItem.element().firstChild; |
| 209 | expect(title.nodeName).toEqual("SPAN"); |
| 210 | expect(title.firstChild.nodeType).toEqual(3); // TextNode |
| 211 | expect(title.firstChild.nodeValue).toEqual("CoreNLP"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 212 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 213 | expect(menuItem.element().childNodes[0]).not.toBe(undefined); |
| 214 | expect(menuItem.element().childNodes[1]).not.toBe(undefined); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 215 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 216 | var desc = menuItem.element().lastChild; |
| 217 | expect(desc.nodeName).toEqual("SPAN"); |
| 218 | expect(desc.firstChild.nodeType).toEqual(3); // TextNode |
| 219 | expect(desc.firstChild.nodeValue).toEqual("my DescRiption"); |
| 220 | }); |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame] | 221 | |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 222 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 223 | it('should be activatable and deactivateable by class', function () { |
| 224 | var menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']); |
| 225 | expect(menuItem.active()).toBe(false); |
| 226 | expect(menuItem.element().getAttribute("class")).toBe(null); |
| 227 | menuItem.active(true); |
| 228 | expect(menuItem.active()).toBe(true); |
| 229 | expect(menuItem.element().getAttribute("class")).toEqual("active"); |
| 230 | menuItem.active(false); // Is active |
| 231 | expect(menuItem.active()).toBe(false); |
| 232 | expect(menuItem.element().getAttribute("class")).toEqual(""); |
| 233 | menuItem.active(true); |
| 234 | expect(menuItem.active()).toBe(true); |
| 235 | expect(menuItem.element().getAttribute("class")).toEqual("active"); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 236 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 237 | menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']); |
| 238 | expect(menuItem.active()).toBe(false); |
| 239 | expect(menuItem.element().getAttribute("class")).toBe(null); |
| 240 | menuItem.active(false); // Is not active |
| 241 | expect(menuItem.active()).toBe(false); |
| 242 | expect(menuItem.element().getAttribute("class")).toBe(null); |
| 243 | }); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 244 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 245 | it('should be set to boundary', function () { |
| 246 | var menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']); |
| 247 | expect(menuItem.active()).toBe(false); |
| 248 | expect(menuItem.element().getAttribute("class")).toBe(null); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 249 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 250 | // Set active |
| 251 | menuItem.active(true); |
| 252 | expect(menuItem.active()).toBe(true); |
| 253 | expect(menuItem.noMore()).toBe(false); |
| 254 | expect(menuItem.element().getAttribute("class")).toEqual("active"); |
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 | // Set no more |
| 257 | menuItem.noMore(true); |
| 258 | expect(menuItem.active()).toBe(true); |
| 259 | expect(menuItem.noMore()).toBe(true); |
| 260 | expect(menuItem.element().getAttribute("class")).toEqual("active no-more"); |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame] | 261 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 262 | // No no more |
| 263 | menuItem.noMore(false); |
| 264 | expect(menuItem.active()).toBe(true); |
| 265 | expect(menuItem.noMore()).toBe(false); |
| 266 | expect(menuItem.element().getAttribute("class")).toEqual("active"); |
Nils Diewald | 1c54692 | 2015-04-13 01:56:19 +0000 | [diff] [blame] | 267 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 268 | // Set no more, deactivate |
| 269 | menuItem.noMore(true); |
| 270 | menuItem.active(false); |
| 271 | expect(menuItem.active()).toBe(false); |
| 272 | expect(menuItem.noMore()).toBe(true); |
| 273 | expect(menuItem.element().getAttribute("class")).toEqual("no-more"); |
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 | // Set active |
| 276 | menuItem.active(true); |
| 277 | expect(menuItem.active()).toBe(true); |
| 278 | expect(menuItem.noMore()).toBe(true); |
| 279 | expect(menuItem.element().getAttribute("class")).toEqual("no-more active"); |
| 280 | }); |
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 | it('should be highlightable', function () { |
| 283 | // Highlight in the middle |
| 284 | var menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']); |
| 285 | menuItem.highlight("ren"); |
| 286 | expect(menuItem.element().innerHTML).toEqual("<span>Co<mark>reN</mark>LP</span>"); |
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 | menuItem.lowlight(); |
| 289 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>"); |
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 | // Starting highlight |
| 292 | menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']); |
| 293 | menuItem.highlight("cor"); |
| 294 | expect(menuItem.element().innerHTML).toEqual("<span><mark>Cor</mark>eNLP</span>"); |
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.lowlight(); |
| 297 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>"); |
| 298 | |
| 299 | // Starting highlight - short |
| 300 | menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']); |
| 301 | menuItem.highlight("c"); |
| 302 | expect(menuItem.element().innerHTML).toEqual("<span><mark>C</mark>oreNLP</span>"); |
| 303 | |
| 304 | menuItem.lowlight(); |
| 305 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>"); |
| 306 | |
| 307 | // Highlight at the end |
| 308 | menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']); |
| 309 | menuItem.highlight("nlp"); |
| 310 | expect(menuItem.element().innerHTML).toEqual("<span>Core<mark>NLP</mark></span>"); |
| 311 | |
| 312 | menuItem.lowlight(); |
| 313 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>"); |
| 314 | |
| 315 | // Highlight at the end - short |
| 316 | menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']); |
| 317 | menuItem.highlight("p"); |
| 318 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNL<mark>P</mark></span>"); |
| 319 | |
| 320 | menuItem.lowlight(); |
| 321 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>"); |
| 322 | |
| 323 | // No highlight |
| 324 | menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']); |
| 325 | menuItem.highlight("xp"); |
| 326 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>"); |
| 327 | |
| 328 | menuItem.lowlight(); |
| 329 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>"); |
| 330 | |
| 331 | // Highlight in the middle - first |
| 332 | menuItem = menuItemClass.create(['CoreNLP', 'corenlp/', 'This is my Example']); |
| 333 | |
| 334 | menuItem.highlight("ren"); |
| 335 | expect(menuItem.element().innerHTML).toEqual("<span>Co<mark>reN</mark>LP</span><span class=\"desc\">This is my Example</span>"); |
| 336 | |
| 337 | menuItem.lowlight(); |
| 338 | expect(menuItem.element().innerHTML).toEqual('<span>CoreNLP</span><span class="desc">This is my Example</span>'); |
| 339 | |
| 340 | // Highlight in the middle - second |
| 341 | menuItem = menuItemClass.create(['CoreNLP', 'corenlp/', 'This is my Example']); |
| 342 | menuItem.highlight("ampl"); |
| 343 | expect(menuItem.element().innerHTML).toEqual('<span>CoreNLP</span><span class="desc">This is my Ex<mark>ampl</mark>e</span>'); |
| 344 | |
| 345 | menuItem.lowlight(); |
| 346 | expect(menuItem.element().innerHTML).toEqual('<span>CoreNLP</span><span class="desc">This is my Example</span>'); |
| 347 | |
| 348 | // Highlight in the middle - both |
| 349 | menuItem = menuItemClass.create(['CoreNLP', 'corenlp/', 'This is my Example']); |
| 350 | |
| 351 | menuItem.highlight("e"); |
| 352 | 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>'); |
| 353 | |
| 354 | menuItem.lowlight(); |
| 355 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span class=\"desc\">This is my Example</span>"); |
| 356 | |
| 357 | // Highlight in the end - second |
| 358 | menuItem = menuItemClass.create(['CoreNLP', 'corenlp/', 'This is my Example']); |
| 359 | menuItem.highlight("le"); |
| 360 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span class=\"desc\">This is my Examp<mark>le</mark></span>"); |
| 361 | |
| 362 | menuItem.lowlight(); |
| 363 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span class=\"desc\">This is my Example</span>"); |
| 364 | |
| 365 | // Highlight at the beginning - second |
| 366 | menuItem = menuItemClass.create(['CoreNLP', 'corenlp/', 'This is my Example']); |
| 367 | menuItem.highlight("this"); |
| 368 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span class=\"desc\"><mark>This</mark> is my Example</span>"); |
| 369 | |
| 370 | menuItem.lowlight(); |
| 371 | expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span class=\"desc\">This is my Example</span>"); |
| 372 | }); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 373 | }); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 374 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 375 | describe('KorAP.HintMenu', function () { |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 376 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 377 | var list = [ |
| 378 | ["Constituency", "c=", "Example 1"], |
| 379 | ["Lemma", "l="], |
| 380 | ["Morphology", "m=", "Example 2"], |
| 381 | ["Part-of-Speech", "p="], |
| 382 | ["Syntax", "syn="] |
| 383 | ]; |
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 | it('should be initializable', function () { |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 386 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 387 | var menu = menuClass.create(null, "cnx/", list); |
| 388 | expect(menu.context()).toEqual('cnx/'); |
| 389 | expect(menu.element().nodeName).toEqual('UL'); |
| 390 | expect(menu.element().style.opacity).toEqual("0"); |
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 | menu.limit(8); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 393 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 394 | // view |
| 395 | menu.show(); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 396 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 397 | // First element in list |
| 398 | expect(menu.item(0).active()).toBe(true); |
| 399 | expect(menu.item(0).noMore()).toBe(true); |
| 400 | |
| 401 | // Middle element in list |
| 402 | expect(menu.item(2).active()).toBe(false); |
| 403 | expect(menu.item(2).noMore()).toBe(false); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 404 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 405 | // Last element in list |
| 406 | expect(menu.item(menu.length() - 1).active()).toBe(false); |
| 407 | expect(menu.item(menu.length() - 1).noMore()).toBe(true); |
| 408 | }); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 409 | }); |
| 410 | }); |