diff options
author | Vladislav Zarakovsky <vlad.zar@gmail.com> | 2015-11-24 13:44:55 +0300 |
---|---|---|
committer | Vladislav Zarakovsky <vlad.zar@gmail.com> | 2015-11-24 15:41:59 +0300 |
commit | 93a56a3f77baa893d954e6f13fce8fccd5cc5adc (patch) | |
tree | a5d1ea92d9b16fceb93b59e23dc4427ffc6c8793 | |
parent | 4fc68f6302d9606406d88e28ab9181f01779bbb4 (diff) | |
download | awesomplete-93a56a3f77baa893d954e6f13fce8fccd5cc5adc.zip awesomplete-93a56a3f77baa893d954e6f13fce8fccd5cc5adc.tar.gz awesomplete-93a56a3f77baa893d954e6f13fce8fccd5cc5adc.tar.bz2 |
awesomplete.previous tests
-rw-r--r-- | test/api/previousSpec.js | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/test/api/previousSpec.js b/test/api/previousSpec.js new file mode 100644 index 0000000..c1d7daf --- /dev/null +++ b/test/api/previousSpec.js @@ -0,0 +1,57 @@ +describe("awesomplete.previous", 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.previous(); + 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 last item ", function () { + this.subject.previous(); + expect(this.subject.index).toBe(this.lastIndex); + }); + }); + + describe("and some item was already selected", function () { + it("selects the second item from the end", function () { + this.subject.goto(this.lastIndex); + this.subject.previous(); + expect(this.subject.index).toBe(this.lastIndex - 1); + }); + + it("selects the first item", function () { + this.subject.goto(this.firstIndex + 1); + this.subject.previous(); + expect(this.subject.index).toBe(this.firstIndex); + }); + + it("selects no item after reaching the start", function () { + this.subject.goto(this.firstIndex); + this.subject.previous(); + expect(this.subject.selected).toBe(false); + }); + }); + }); +}); |