-
-
Notifications
You must be signed in to change notification settings - Fork 241
Expand file tree
/
Copy pathui-spec.js
More file actions
61 lines (51 loc) · 1.57 KB
/
ui-spec.js
File metadata and controls
61 lines (51 loc) · 1.57 KB
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
describe("UI", function() {
var link;
beforeEach(function() {
link = document.createElement("a");
document.body.appendChild(link);
});
afterEach(function() {
document.body.removeChild(link);
});
it("triggers the download if the link points to 'download'", function() {
pointLinkTo("download");
spyOn(Zipper, "createZip");
UserInterface.setup(Zipper, undefined);
link.click();
expect(Zipper.createZip).toHaveBeenCalled();
});
it("prevents default of download link (does not follow link)", function() {
pointLinkTo("download");
UserInterface.setup(undefined, undefined);
var canceled = !link.dispatchEvent(createClickEvent());
expect(canceled).toBe(true);
});
it("does not trigger the download if the link doesn't point to 'download'", function() {
pointLinkTo("http://example.com/");
spyOn(Zipper, "createZip");
UserInterface.setup(Zipper, undefined);
dontFollowLink();
link.click();
expect(Zipper.createZip).not.toHaveBeenCalled();
});
it("calls the zipper with the right downloader", function() {
pointLinkTo("download");
spyOn(Zipper, "createZip");
UserInterface.setup(Zipper, Downloader);
link.click();
expect(Zipper.createZip).toHaveBeenCalledWith(Downloader);
});
function pointLinkTo(href) {
link.setAttribute("href", href);
}
function dontFollowLink() {
link.onclick = function() { return false; };
}
function createClickEvent() {
return new MouseEvent("click", {
"view": window,
"bubbles": true,
"cancelable": true
});
}
});