summaryrefslogtreecommitdiffstats
path: root/test/init/optionsSpec.js
blob: fc60997c52c757f145c467ccc1a035a59b5fb5ea (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
describe("Constructor options", function () {

	$.fixture("options");

	subject(function () { return new Awesomplete(this.element, this.options) });

	describe("with default options", function () {
		def("element", "#with-data-list");

		it("requires minimum 2 chars to open completer", function () {
			expect(this.subject.minChars).toBe(2);
		});

		it("shows 10 items in completer", function () {
			expect(this.subject.maxItems).toBe(10);
		});

		it("does not select the first ocurrence automatically" , function () {
			expect(this.subject.autoFirst).toBe(false);
		});

		it("modifies list item with DATA", function () {
			expect(this.subject.data).toBe(Awesomplete.DATA);
		});

		it("filters with FILTER_CONTAINS", function () {
			expect(this.subject.filter).toBe(Awesomplete.FILTER_CONTAINS);
		});

		it("orders with SORT_BYLENGTH", function () {
			expect(this.subject.sort).toBe(Awesomplete.SORT_BYLENGTH);
		});

		it("creates item with ITEM", function () {
			expect(this.subject.item).toEqual(Awesomplete.ITEM);
		});

		it("replaces input value with REPLACE", function () {
			expect(this.subject.replace).toEqual(Awesomplete.REPLACE);
		});
	});

	describe("with custom options in constructor", function () {
		def("element", "#with-data-list");
		def("options", function () {
			return {
				minChars: 3,
				maxItems: 9,
				autoFirst: true,
				filter: $.noop,
				sort: $.noop,
				item: $.noop,
				replace: $.noop
			};
		});

		it("overrides simple default options", function () {
			expect(this.subject.minChars).toBe(3);
			expect(this.subject.maxItems).toBe(9);
			expect(this.subject.autoFirst).toBe(true);
		});

		it("overrides default functions", function () {
			expect(this.subject.filter).toBe(this.options.filter);
			expect(this.subject.sort).toBe(this.options.sort);
			expect(this.subject.item).toBe(this.options.item);
			expect(this.subject.replace).toBe(this.options.replace);
		});
	});

	describe("with custom options in data-* attributes", function () {
		def("element", "#with-custom-options");

		it("overrides simple default options", function () {
			expect(this.subject.minChars).toBe(4);
			expect(this.subject.maxItems).toBe(8);
			expect(this.subject.autoFirst).toBe(true);
		});
	});
});