summaryrefslogtreecommitdiffstats
path: root/test/api/openSpec.js
blob: 1bfc467f461ab9cfa21c4088a062fcf00c50820b (plain)
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
describe("awesomplete.open", function () {

	$.fixture("plain");

	subject(function () { return new Awesomplete("#plain", { list: ["item1", "item2", "item3"] }) });

	// 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.subject.open();

		expect(this.subject.ul.children.length).toBe(3);
	});

	it("opens completer", function () {
		this.subject.open();
		expect(this.subject.ul.hasAttribute("hidden")).toBe(false);
	});

	describe("with autoFirst: true", function () {
		beforeEach(function () {
			this.subject.autoFirst = true;
			spyOn(this.subject, "goto");
		});

		it("selects first item if wasn't seleted before", function () {
			this.subject.open();

			expect(this.subject.goto).toHaveBeenCalledWith(0);
		});

		it("does not select any item if was seleted before", function () {
			this.subject.index = 0;
			this.subject.open();

			expect(this.subject.goto).not.toHaveBeenCalled();
		});
	});

	describe("with autoFirst: false", function () {
		it("does not select any item", function () {
			this.subject.autoFirst = false;
			spyOn(this.subject, "goto");

			this.subject.open();

			expect(this.subject.goto).not.toHaveBeenCalled();
		});
	});

	it("fires awesomplete-open event", function () {
		var handler = $.spyOnEvent(this.subject.input, "awesomplete-open");

		this.subject.open();

		expect(handler).toHaveBeenCalled();
	});
});