summaryrefslogtreecommitdiffstats
path: root/test/api
diff options
context:
space:
mode:
authorVladislav Zarakovsky <vlad.zar@gmail.com>2015-11-24 13:49:15 +0300
committerVladislav Zarakovsky <vlad.zar@gmail.com>2015-11-24 15:42:16 +0300
commit8781595f6fbcb4723f9ce4b912dbb45f499d729c (patch)
tree47c4cc78d895af5188de97c96ddc140b0e669904 /test/api
parent93a56a3f77baa893d954e6f13fce8fccd5cc5adc (diff)
downloadawesomplete-8781595f6fbcb4723f9ce4b912dbb45f499d729c.zip
awesomplete-8781595f6fbcb4723f9ce4b912dbb45f499d729c.tar.gz
awesomplete-8781595f6fbcb4723f9ce4b912dbb45f499d729c.tar.bz2
awesomplete.goto tests
Diffstat (limited to 'test/api')
-rw-r--r--test/api/gotoSpec.js66
1 files changed, 66 insertions, 0 deletions
diff --git a/test/api/gotoSpec.js b/test/api/gotoSpec.js
new file mode 100644
index 0000000..9e382c0
--- /dev/null
+++ b/test/api/gotoSpec.js
@@ -0,0 +1,66 @@
+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 events = { highlight: $.noop};
+ spyOn(events, "highlight");
+ $.on(this.subject.input, "awesomplete-highlight", events.highlight);
+ this.subject.goto(1);
+
+ expect(events.highlight).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");
+ });
+ });
+});