summaryrefslogtreecommitdiffstats
path: root/test/init/htmlSpec.js
blob: 25350c6428a6a6c890b4960c7c71640e4177a318 (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
describe("Html modifications", function () {

	$.fixture("plain");

	subject(function () { return new Awesomplete("#plain") });

	it("binds to correct input", function () {
		expect(this.subject.input instanceof HTMLElement).toBe(true);
		expect(this.subject.input.id).toBe("plain");
	});

	it("turns native autocompleter off", function () {
		expect(this.subject.input.getAttribute("autocomplete")).toBe("off");
	});

	describe("HTML tweaks", function () {
		it("creates container", function () {
			expect(this.subject.container instanceof HTMLElement).toBe(true);
			expect(this.subject.container.className).toBe("awesomplete");
		});

		it("places input inside container", function () {
			expect(this.subject.input.parentNode).toBe(this.subject.container);
		});

		it("creates list", function () {
			expect(this.subject.ul instanceof HTMLElement).toBe(true);
			expect(this.subject.ul.tagName).toBe("UL");
		});

		it("puts list inside container", function () {
			expect(this.subject.ul.parentNode).toBe(this.subject.container);
		});

		it("hides list", function () {
			expect(this.subject.ul.hasAttribute("hidden")).toBe(true);
		});
	});

	describe("ARIA support", function () {
		it("makes input accessible", function () {
			expect(this.subject.input.getAttribute("aria-autocomplete")).toBe("list");
		});

		it("creates status", function () {
			expect(this.subject.status instanceof HTMLElement).toBe(true);
			expect(this.subject.status.getAttribute("role")).toBe("status");
			expect(this.subject.status.getAttribute("aria-live")).toBe("assertive");
			expect(this.subject.status.getAttribute("aria-relevant")).toBe("additions");
		});

		it("puts status inside container", function () {
			expect(this.subject.status.parentNode).toBe(this.subject.container);
		});

		it("hides status", function () {
			expect(this.subject.status.className).toBe("visually-hidden");
		});
	});
});