summaryrefslogtreecommitdiffstats
path: root/test/api/evaluateSpec.js
blob: 011835edd78a966c0dc3fa2b974bdfdd564aa4fb (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
describe("awesomplete.evaluate", function () {

	$.fixture("plain");

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

	describe("with too short input value", function () {
		beforeEach(function () {
			$.type(this.subject.input, "i");
		});

		it("closes completer", function () {
			spyOn(this.subject, "close");
			this.subject.evaluate();

			expect(this.subject.close).toHaveBeenCalled();
		});
	});

	describe("with no items found", function () {
		beforeEach(function () {
			$.type(this.subject.input, "nosuchitem");
		});

		it("closes completer", function () {
			spyOn(this.subject, "close");
			this.subject.evaluate();

			expect(this.subject.close).toHaveBeenCalled();
		});
	});

	describe("with some items found", function () {
		beforeEach(function () {
			$.type(this.subject.input, "ite");
		});

		it("opens completer", function () {
			spyOn(this.subject, "open");
			this.subject.evaluate();

			expect(this.subject.open).toHaveBeenCalled();
		});

		it("fills completer with found items", function () {
			this.subject.evaluate();
			expect(this.subject.ul.children.length).toBe(3);
		});

		it("shows no more than maxItems", function () {
			this.subject.maxItems = 2;
			this.subject.evaluate();
			expect(this.subject.ul.children.length).toBe(2);
		});

		it("makes no item selected", function () {
			this.subject.evaluate();
			expect(this.subject.index).toBe(-1);
		});
	});

	describe("with minChars: 0", function () {
		beforeEach(function () {
			this.subject.minChars = 0;
		});

		it("opens completer", function () {
			spyOn(this.subject, "open");
			this.subject.evaluate();

			expect(this.subject.open).toHaveBeenCalled();
		});

		it("fills completer with all items", function () {
			this.subject.evaluate();
			expect(this.subject.ul.children.length).toBe(3);
		});

		it("shows no more than maxItems", function () {
			this.subject.maxItems = 2;
			this.subject.evaluate();
			expect(this.subject.ul.children.length).toBe(2);
		});

		it("makes no item selected", function () {
			this.subject.evaluate();
			expect(this.subject.index).toBe(-1);
		});
	});
});