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