-
Notifications
You must be signed in to change notification settings - Fork 611
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve test coverage #16785
Merged
LeaVerou
merged 40 commits into
LeaVerou:gh-pages
from
vlazar:features/improve-test-coverage
Dec 27, 2015
Merged
Improve test coverage #16785
Changes from all commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
317efcb
Update devDependencies
vlazar bb8f148
Add karma-jasmine-def for def() and subject() test helpers
vlazar 1aa72f7
Add karma-fixture for loading fixtures from files
vlazar b6e5716
Set correct fixtures path
vlazar eff8334
Constructor options tests
vlazar ba73e77
List initialization tests
vlazar 267d2b8
Fix bug exposed by tests: Can't init list from list html attribute.
vlazar 6bee532
Html modifications tests
vlazar 336c21e
Fix bug exposed by tests: List isn't hidden by default.
vlazar 9c4e25e
Awesomplete.all tests
vlazar fff2793
Awesomplete.FILTER_CONTAINS tests
vlazar c97c34f
Awesomplete.FILTER_STARTSWITH tests
vlazar 2b2e3ed
Awesomplete.SORT_BYLENGTH tests
vlazar e3d15e3
Awesomplete.$.bind tests
vlazar 375a452
Awesomplete.$.create tests
vlazar 2017243
Awesomplete.$ tests
vlazar e85128e
Awesomplete.$$ tests
vlazar 643ccfb
Awesomplete.$.fire tests
vlazar 4a0e723
Awesomplete.$.regExpEscape tests
vlazar dcd4620
awesomplete.close tests
vlazar 4b7a449
awesomplete.open tests
vlazar 4fc68f6
awesomplete.next tests
vlazar 93a56a3
awesomplete.previous tests
vlazar 8781595
awesomplete.goto tests
vlazar ca9c91a
awesomplete.select tests
vlazar 132906c
awesomplete.evaluate tests
vlazar 03bb15a
awesomplete.opened tests
vlazar 6cd69b2
awesomplete.selected tests
vlazar 625cd57
blur event tests
vlazar c1c5e13
input event tests
vlazar 94bb12f
mousedown event tests
vlazar 1323113
form submit event tests
vlazar b08fd22
keydown event tests
vlazar df992f7
Fix tests run in Firefox
vlazar f4cef99
Simplify tests by inlining and using $.spyOnEvent helper
vlazar 00f0630
Covered some missed branches
vlazar db50ff8
Progress reporter is too noisy on TravisCI. Use dots reporter instead.
vlazar f793f05
Remove unused dependency
vlazar 17934ef
Merge remote-tracking branch 'upstream/gh-pages' into features/improv…
vlazar f9d6cca
Tests for merged #16791 Don't select items on mouse right-click
vlazar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
describe("awesomplete.close", function () { | ||
|
||
$.fixture("plain"); | ||
|
||
subject(function () { return new Awesomplete("#plain") }); | ||
|
||
beforeEach(function () { | ||
this.subject.open(); | ||
this.subject.next(); | ||
}); | ||
|
||
it("closes completer", function () { | ||
this.subject.close(); | ||
expect(this.subject.ul.hasAttribute("hidden")).toBe(true); | ||
}); | ||
|
||
it("makes no item selected", function () { | ||
this.subject.close(); | ||
|
||
expect(this.subject.selected).toBe(false); | ||
expect(this.subject.index).toBe(-1); | ||
}); | ||
|
||
it("fires awesomplete-close event", function () { | ||
var handler = $.spyOnEvent(this.subject.input, "awesomplete-close"); | ||
this.subject.close(); | ||
|
||
expect(handler).toHaveBeenCalled(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
describe("awesomplete.evaluate", function () { | ||
|
||
$.fixture("plain"); | ||
|
||
subject(function () { | ||
return new Awesomplete("#plain", { list: ["item1", "item2", "item3"] }); | ||
}); | ||
|
||
describe("with too short input value", function () { | ||
beforeEach(function () { | ||
$.type(this.subject.input, "i"); | ||
}); | ||
|
||
it("closes completer", function () { | ||
spyOn(this.subject, "close"); | ||
this.subject.evaluate(); | ||
|
||
expect(this.subject.close).toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
describe("with no items found", function () { | ||
beforeEach(function () { | ||
$.type(this.subject.input, "nosuchitem"); | ||
}); | ||
|
||
it("closes completer", function () { | ||
spyOn(this.subject, "close"); | ||
this.subject.evaluate(); | ||
|
||
expect(this.subject.close).toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
describe("with some items found", function () { | ||
beforeEach(function () { | ||
$.type(this.subject.input, "ite"); | ||
}); | ||
|
||
it("opens completer", function () { | ||
spyOn(this.subject, "open"); | ||
this.subject.evaluate(); | ||
|
||
expect(this.subject.open).toHaveBeenCalled(); | ||
}); | ||
|
||
it("fills completer with found items", function () { | ||
this.subject.evaluate(); | ||
expect(this.subject.ul.children.length).toBe(3); | ||
}); | ||
|
||
it("makes no item selected", function () { | ||
this.subject.evaluate(); | ||
expect(this.subject.selected).toBe(false); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
describe("awesomplete.goto", function () { | ||
|
||
$.fixture("plain"); | ||
|
||
subject(function () { | ||
return new Awesomplete("#plain", { list: ["item1", "item2", "item3"] }); | ||
}); | ||
|
||
def("firstIndex", function () { return 0 }); | ||
def("lastIndex", function () { return this.subject.ul.children.length - 1 }); | ||
|
||
beforeEach(function () { | ||
$.type(this.subject.input, "ite"); | ||
}); | ||
|
||
it("clears previous aria-selected", function () { | ||
this.subject.goto(this.firstIndex); | ||
this.subject.goto(this.lastIndex); | ||
|
||
expect(this.subject.ul.children[this.firstIndex].getAttribute("aria-selected")).toBe("false"); | ||
}); | ||
|
||
it("goes to first item", function () { | ||
this.subject.goto(this.firstIndex); | ||
expect(this.subject.index).toBe(this.firstIndex); | ||
}); | ||
|
||
it("goes to last item", function () { | ||
this.subject.goto(this.lastIndex); | ||
expect(this.subject.index).toBe(this.lastIndex); | ||
}); | ||
|
||
it("fires awesomplete-highlight event", function () { | ||
var handler = $.spyOnEvent(this.subject.input, "awesomplete-highlight"); | ||
this.subject.goto(1); | ||
|
||
expect(handler).toHaveBeenCalled(); | ||
}); | ||
|
||
describe("with item index > -1", function () { | ||
beforeEach(function () { | ||
this.subject.goto(this.firstIndex); | ||
}); | ||
|
||
it("sets aria-selected", function () { | ||
expect(this.subject.ul.children[this.firstIndex].getAttribute("aria-selected")).toBe("true"); | ||
}); | ||
|
||
it("updates status", function () { | ||
expect(this.subject.status.textContent).toBe("item1"); | ||
}); | ||
}); | ||
|
||
describe("with item index = -1", function () { | ||
beforeEach(function () { | ||
this.subject.goto(this.firstIndex); | ||
this.subject.goto(-1); | ||
}); | ||
|
||
it("does not update status", function () { | ||
expect(this.subject.status.textContent).toBe("item1"); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
describe("awesomplete.next", function () { | ||
|
||
$.fixture("plain"); | ||
|
||
subject(function () { | ||
return new Awesomplete("#plain", { list: ["item1", "item2", "item3"] }); | ||
}); | ||
|
||
def("firstIndex", function () { return 0 }); | ||
def("lastIndex", function () { return this.subject.ul.children.length - 1 }); | ||
|
||
describe("without any items found", function () { | ||
beforeEach(function () { | ||
$.type(this.subject.input, "nosuchitem"); | ||
this.subject.open(); | ||
}); | ||
|
||
it("does not select any item", function () { | ||
this.subject.next(); | ||
expect(this.subject.selected).toBe(false); | ||
}); | ||
}); | ||
|
||
describe("with some items found", function () { | ||
beforeEach(function () { | ||
$.type(this.subject.input, "ite"); | ||
this.subject.open(); | ||
}); | ||
|
||
describe("and no item was already selected", function () { | ||
it("selects the first item ", function () { | ||
this.subject.next(); | ||
expect(this.subject.index).toBe(this.firstIndex); | ||
}); | ||
}); | ||
|
||
describe("and some item was already selected", function () { | ||
it("selects the second item", function () { | ||
this.subject.goto(this.firstIndex); | ||
this.subject.next(); | ||
expect(this.subject.index).toBe(this.firstIndex + 1); | ||
}); | ||
|
||
it("selects the last item", function () { | ||
this.subject.goto(this.lastIndex - 1); | ||
this.subject.next(); | ||
expect(this.subject.index).toBe(this.lastIndex); | ||
}); | ||
|
||
it("selects no item after reaching the end", function () { | ||
this.subject.goto(this.lastIndex); | ||
this.subject.next(); | ||
expect(this.subject.selected).toBe(false); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
describe("awesomplete.open", function () { | ||
|
||
$.fixture("plain"); | ||
|
||
subject(function () { return new Awesomplete("#plain", this.options) }); | ||
|
||
it("opens completer", function () { | ||
this.subject.open(); | ||
expect(this.subject.ul.hasAttribute("hidden")).toBe(false); | ||
}); | ||
|
||
// Exposes this bug https://github.com/LeaVerou/awesomplete/pull/16740 | ||
// FIXME better fix is probably required as discussed in PR above | ||
xit("fills in the list on creation", function () { | ||
$("#plain").value = "ite"; | ||
this.options = { list: "item1, item2" }; | ||
this.subject.open(); | ||
|
||
expect(this.subject.ul.children.length).toBe(2); | ||
}); | ||
|
||
it("fires awesomplete-open event", function () { | ||
var handler = $.spyOnEvent(this.subject.input, "awesomplete-open"); | ||
this.subject.open(); | ||
|
||
expect(handler).toHaveBeenCalled(); | ||
}); | ||
|
||
describe("with autoFirst: true", function () { | ||
def("options", function () { return { autoFirst: true } }); | ||
|
||
it("automatically selects first item", function () { | ||
spyOn(this.subject, "goto"); | ||
this.subject.open(); | ||
|
||
expect(this.subject.goto).toHaveBeenCalledWith(0); | ||
}); | ||
}); | ||
|
||
describe("with autoFirst: false", function () { | ||
def("options", function () { return { autoFirst: false } }); | ||
|
||
it("does not select any item", function () { | ||
this.subject.open(); | ||
|
||
expect(this.subject.selected).toBe(false); | ||
expect(this.subject.index).toBe(-1); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
describe("awesomplete.opened", function () { | ||
|
||
$.fixture("plain"); | ||
|
||
subject(function () { return new Awesomplete("#plain") }); | ||
|
||
describe("with newly created completer", function () { | ||
it("is false", function () { | ||
expect(this.subject.opened).toBe(false); | ||
}); | ||
}); | ||
|
||
describe("with opened completer", function () { | ||
it("is true", function () { | ||
this.subject.open(); | ||
expect(this.subject.opened).toBe(true); | ||
}); | ||
}); | ||
|
||
describe("with closed completer", function () { | ||
it("is false", function () { | ||
this.subject.close(); | ||
expect(this.subject.opened).toBe(false); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$.create when working with attributes would do:
Which is for boolean attribute would be the same as:
So completer would not be hidden by default.
I don't remember why I didn't used
hidden: false
here. Maybe there was some bug with it. I'll check this later.