Skip to content

Commit

Permalink
Add tests for covering checkContentChanged
Browse files Browse the repository at this point in the history
  • Loading branch information
nmielnik committed May 5, 2016
1 parent 0007885 commit a27fa81
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
48 changes: 47 additions & 1 deletion spec/core-api.spec.js
@@ -1,4 +1,5 @@
/*global fireEvent, selectElementContents */
/*global fireEvent, selectElementContents,
selectElementContentsAndFire */

describe('Core-API', function () {
'use strict';
Expand Down Expand Up @@ -101,4 +102,49 @@ describe('Core-API', function () {
expect(exportedSelection.editableElementIndex).toEqual(1);
});
});

describe('checkContentChanged', function () {
it('should trigger editableInput when called after the html has changed', function () {
var editor = this.newMediumEditor('.editor', {
toolbar: {
buttons: ['italic', 'underline', 'strikethrough']
}
}),
spy = jasmine.createSpy('handler');

editor.subscribe('editableInput', spy);
expect(spy).not.toHaveBeenCalled();

selectElementContentsAndFire(this.el.firstChild);
jasmine.clock().tick(1);

this.el.innerHTML = 'lorem ipsum';
expect(spy).not.toHaveBeenCalled();

var obj = { target: this.el, currentTarget: this.el };
editor.checkContentChanged();
expect(spy).toHaveBeenCalledWith(obj, this.el);
});

it('should not trigger editableInput when called after the html has not changed', function () {
var editor = this.newMediumEditor('.editor', {
toolbar: {
buttons: ['italic', 'underline', 'strikethrough']
}
}),
spy = jasmine.createSpy('handler');

editor.subscribe('editableInput', spy);
expect(spy).not.toHaveBeenCalled();

selectElementContentsAndFire(this.el.firstChild);
jasmine.clock().tick(1);

this.el.innerHTML = 'lore ipsum';
expect(spy).not.toHaveBeenCalled();

editor.checkContentChanged();
expect(spy).not.toHaveBeenCalled();
});
});
});
2 changes: 1 addition & 1 deletion src/js/core.js
Expand Up @@ -1103,7 +1103,7 @@
},

checkContentChanged: function (editable) {
editable = editable || MediumEditor.selection.getSelectionElement(this.window);
editable = editable || MediumEditor.selection.getSelectionElement(this.options.contentWindow);
this.events.updateInput(editable, { target: editable, currentTarget: editable });
}
};
Expand Down

0 comments on commit a27fa81

Please sign in to comment.