(inputSupported)
| 332 | describe('Custom EditableInput Listener', function () { |
| 333 | |
| 334 | function runEditableInputTests(inputSupported) { |
| 335 | var namePrefix = inputSupported ? 'when Input is supported' : 'when Input is NOT supported'; |
| 336 | |
| 337 | it(namePrefix + ' should trigger with the corresponding editor element passed as an argument', function () { |
| 338 | var originalInputSupport = MediumEditor.Events.prototype.InputEventOnContenteditableSupported; |
| 339 | MediumEditor.Events.prototype.InputEventOnContenteditableSupported = inputSupported; |
| 340 | |
| 341 | var editableTwo = this.createElement('div', 'editor', 'lore ipsum'), |
| 342 | firedTarget, |
| 343 | editor = this.newMediumEditor('.editor'), |
| 344 | handler = function (event, editable) { |
| 345 | firedTarget = editable; |
| 346 | }; |
| 347 | expect(editor.elements.length).toBe(2); |
| 348 | |
| 349 | editor.subscribe('editableInput', handler); |
| 350 | editor.selectElement(editableTwo.firstChild); |
| 351 | |
| 352 | editableTwo.textContent = 'lore ipsum!'; |
| 353 | |
| 354 | // trigger onInput |
| 355 | fireEvent(editableTwo, 'input'); |
| 356 | |
| 357 | // trigger faked 'selectionchange' event |
| 358 | fireEvent(document, 'selectionchange', { target: document, currentTarget: editableTwo }); |
| 359 | |
| 360 | jasmine.clock().tick(1); |
| 361 | expect(firedTarget).toBe(editableTwo); |
| 362 | |
| 363 | MediumEditor.Events.prototype.InputEventOnContenteditableSupported = originalInputSupport; |
| 364 | }); |
| 365 | |
| 366 | it(namePrefix + ' should only trigger when the content has actually changed', function () { |
| 367 | var originalInputSupport = MediumEditor.Events.prototype.InputEventOnContenteditableSupported; |
| 368 | MediumEditor.Events.prototype.InputEventOnContenteditableSupported = inputSupported; |
| 369 | |
| 370 | var editableTwo = this.createElement('div', 'editor', 'lore ipsum'), |
| 371 | firedTarget, |
| 372 | editor = this.newMediumEditor('.editor'), |
| 373 | handler = function (event, editable) { |
| 374 | firedTarget = editable; |
| 375 | }; |
| 376 | expect(editor.elements.length).toBe(2); |
| 377 | |
| 378 | editor.subscribe('editableInput', handler); |
| 379 | |
| 380 | // If content hasn't changed, custom event won't fire |
| 381 | fireEvent(editableTwo, 'input'); |
| 382 | fireEvent(editableTwo, 'keypress'); |
| 383 | expect(firedTarget).toBeUndefined(); |
| 384 | |
| 385 | // Change the content, custom event should fire |
| 386 | editableTwo.textContent = 'lore ipsum!'; |
| 387 | fireEvent(editableTwo, 'input'); |
| 388 | fireEvent(editableTwo, 'keypress'); |
| 389 | jasmine.clock().tick(1); |
| 390 | expect(firedTarget).toBe(editableTwo); |
| 391 |
no test coverage detected
searching dependent graphs…