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