summaryrefslogtreecommitdiffstats
path: root/test/events/mousedownSpec.js
blob: c0f7cf62332089b0de0b790ae3373acb805403d8 (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
describe("mousedown event", function () {

	$.fixture("plain");

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

	def("li", function () { return this.subject.ul.children[1] });

	beforeEach(function () {
		$.type(this.subject.input, "ite");
		spyOn(this.subject, "select");
	});

	describe("with ul target", function () {
		def("target", function () { return this.subject.ul });

		it("does not select item", function () {
			$.fire(this.target, "mousedown", { button: 0 });
			expect(this.subject.select).not.toHaveBeenCalled();
		});
	});

	describe("with li target", function () {
		def("target", function () { return this.li });

		describe("on left click", function () {
			it("selects item", function () {
				var event = $.fire(this.target, "mousedown", { button: 0 });
				expect(this.subject.select).toHaveBeenCalledWith(this.li, this.target);
				expect(event.defaultPrevented).toBe(true);
			});
		});

		describe("on right click", function () {
			it("does not select item", function () {
				$.fire(this.target, "mousedown", { button: 2 });
				expect(this.subject.select).not.toHaveBeenCalled();
			});
		});
	});

	describe("with child of li target", function () {
		def("target", function () { return $("mark", this.li) });

		describe("on left click", function () {
			it("selects item", function () {
				var event = $.fire(this.target, "mousedown", { button: 0 });
				expect(this.subject.select).toHaveBeenCalledWith(this.li, this.target);
				expect(event.defaultPrevented).toBe(true);
			});
		});

		describe("on right click", function () {
			it("does not select item", function () {
				$.fire(this.target, "mousedown", { button: 2 });
				expect(this.subject.select).not.toHaveBeenCalled();
			});
		});
	});
});