UNPKG

awesomplete

Version:

http://leaverou.github.io/awesomplete/

97 lines (71 loc) 2.35 kB
describe("keydown event", function () { $.fixture("plain"); subject(function () { return new Awesomplete("#plain", { list: ["item1", "item2", "item3"] }); }); beforeEach(function () { $.type(this.subject.input, "ite"); }); it("supports enter", function () { this.subject.next(); spyOn(this.subject, "select"); $.keydown(this.subject.input, $.k.ENTER); expect(this.subject.select).toHaveBeenCalled(); }); it("supports escape", function () { spyOn(this.subject, "close"); $.keydown(this.subject.input, $.k.ESC); expect(this.subject.close).toHaveBeenCalledWith({ reason: "esc" }); }); it("supports down arrow", function () { spyOn(this.subject, "next"); $.keydown(this.subject.input, $.k.DOWN); expect(this.subject.next).toHaveBeenCalled(); }); it("supports up arrow", function () { spyOn(this.subject, "previous"); $.keydown(this.subject.input, $.k.UP); expect(this.subject.previous).toHaveBeenCalled(); }); it("ignores other keys", function() { spyOn(this.subject, "select"); spyOn(this.subject, "close"); spyOn(this.subject, "next"); spyOn(this.subject, "previous"); $.keydown(this.subject.input, 111); expect(this.subject.select).not.toHaveBeenCalled(); expect(this.subject.close).not.toHaveBeenCalled(); expect(this.subject.next).not.toHaveBeenCalled(); expect(this.subject.previous).not.toHaveBeenCalled(); }); it("does nothing if not opened", function () { this.subject.close(); spyOn(this.subject, "next"); $.keydown(this.subject.input, $.k.DOWN); expect(this.subject.next).not.toHaveBeenCalled(); }); it("does not select on tab", function () { this.subject.next(); spyOn(this.subject, "select"); $.keydown(this.subject.input, $.k.TAB); expect(this.subject.select).not.toHaveBeenCalled(); }); }); describe("tabSelect option true ", function () { $.fixture("plain"); subject(function () { return new Awesomplete("#plain", { list: ["item1", "item2", "item3"], tabSelect: true }); }); beforeEach(function () { $.type(this.subject.input, "ite"); }); it("selects on tab", function () { this.subject.next(); spyOn(this.subject, "select"); $.keydown(this.subject.input, $.k.TAB); expect(this.subject.select).toHaveBeenCalled(); expect(this.subject.select.calls.mostRecent().args[2].defaultPrevented).toBe(true); }); })