Skip to content

Commit

Permalink
Fix tests to add an event to select()
Browse files Browse the repository at this point in the history
  • Loading branch information
TxHawks committed Jan 2, 2016
1 parent 52dac84 commit dc966c9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
15 changes: 8 additions & 7 deletions test/api/selectSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ describe("awesomplete.select", function () {
def("firstIndex", function () { return 0 });
def("lastIndex", function () { return this.subject.ul.children.length - 1 });
def("lastLi", function () { return this.subject.ul.children[this.lastIndex] });
def("mockEvt", function () { return { 'originalTarget': this.lastLi } });

beforeEach(function () {
$.type(this.subject.input, "ite");
Expand Down Expand Up @@ -43,7 +44,7 @@ describe("awesomplete.select", function () {
function itSelects(expectedTxt) {
it("fires awesomplete-select event", function () {
var handler = $.spyOnEvent(this.subject.input, "awesomplete-select");
this.subject.select(this.selectArgument);
this.subject.select(this.selectArgument, this.mockEvt);

expect(handler).toHaveBeenCalledWith(jasmine.objectContaining({ text: expectedTxt }));
});
Expand All @@ -54,20 +55,20 @@ describe("awesomplete.select", function () {
});

it("changes the input value", function () {
this.subject.select(this.selectArgument);
this.subject.select(this.selectArgument, this.mockEvt);
expect(this.subject.input.value).toBe(expectedTxt);
});

it("closes completer", function () {
spyOn(this.subject, "close");
this.subject.select(this.selectArgument);
this.subject.select(this.selectArgument, this.mockEvt);

expect(this.subject.close).toHaveBeenCalled();
});

it("fires awesomplete-selectcomplete event", function () {
var handler = $.spyOnEvent(this.subject.input, "awesomplete-selectcomplete");
this.subject.select(this.selectArgument);
this.subject.select(this.selectArgument, this.mockEvt);

expect(handler).toHaveBeenCalled();
});
Expand All @@ -79,20 +80,20 @@ describe("awesomplete.select", function () {
});

it("does not change the input value", function () {
this.subject.select(this.selectArgument);
this.subject.select(this.selectArgument, this.mockEvt);
expect(this.subject.input.value).toBe("ite");
});

it("does not close completer", function () {
spyOn(this.subject, "close");
this.subject.select(this.selectArgument);
this.subject.select(this.selectArgument, this.mockEvt);

expect(this.subject.close).not.toHaveBeenCalled();
});

it("does not fire awesomplete-selectcomplete event", function () {
var handler = $.spyOnEvent(this.subject.input, "awesomplete-selectcomplete");
this.subject.select(this.selectArgument);
this.subject.select(this.selectArgument, this.mockEvt);

expect(handler).not.toHaveBeenCalled();
});
Expand Down
4 changes: 3 additions & 1 deletion test/awesompleteShared.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ var shared = {
expectSelectingFirstSuggestionToWorkWith: function(val){
return function(){
var li;
var evt;
shared.awesompleter.input.value = val;
shared.awesompleter.evaluate();
li = shared.awesompleter.ul.children[0];
shared.awesompleter.select(li);
evt = {originalTarget: li};
shared.awesompleter.select(li, evt);
expect(shared.awesompleter.input.value).toBe(li.textContent);
}
},
Expand Down

0 comments on commit dc966c9

Please sign in to comment.