1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
describe("awesomplete.goto", function () {
$.fixture("plain");
subject(function () {
return new Awesomplete("#plain", { list: ["item1", "item2", "item3"] });
});
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(0);
this.subject.goto(this.lastIndex);
expect(this.subject.ul.children[0].getAttribute("aria-selected")).toBe("false");
});
it("goes to first item", function () {
this.subject.goto(0);
expect(this.subject.index).toBe(0);
});
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).toHaveBeenCalledWith(
jasmine.objectContaining({
text: jasmine.objectContaining({ label: "item2", value: "item2" })
})
);
});
describe("with item index > -1", function () {
beforeEach(function () {
this.subject.goto(0);
});
it("sets aria-selected", function () {
expect(this.subject.ul.children[0].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(0);
this.subject.goto(-1);
});
it("does not update status", function () {
expect(this.subject.status.textContent).toBe("item1");
});
});
});
|