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