-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathauto-events.test.js
More file actions
67 lines (57 loc) · 1.96 KB
/
auto-events.test.js
File metadata and controls
67 lines (57 loc) · 1.96 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
62
63
64
65
66
67
const { expect } = require("chai");
const { createDOM } = require("./helpers/dom-auto-events");
function setupDOM() {
const events = [];
const dom = createDOM({
beforeRun(vm) {
vm.sa_event = function (name, metadata, cb) {
events.push({ name, metadata });
if (typeof cb === "function") cb();
};
vm.sa_event_loaded = true;
},
});
dom.events = events;
return dom;
}
describe("auto-events", function () {
it("tracks outbound link clicks", function (done) {
const dom = setupDOM();
const link = dom.window.document.createElement("a");
link.href = "https://example.org/path";
link.target = "_blank";
dom.window.document.body.appendChild(link);
dom.window.saAutomatedLink(link, "outbound");
setTimeout(() => {
expect(dom.events[0]).to.deep.include({ name: "outbound_example_org" });
expect(dom.events[0].metadata).to.include({ url: link.href });
done();
}, 0);
});
it("tracks download link clicks", function (done) {
const dom = setupDOM();
const link = dom.window.document.createElement("a");
link.href = "https://example.com/file.pdf";
link.target = "_blank";
dom.window.document.body.appendChild(link);
dom.window.saAutomatedLink(link, "download");
setTimeout(() => {
expect(dom.events[0]).to.deep.include({ name: "download_file_pdf" });
expect(dom.events[0].metadata).to.include({ url: link.href });
done();
}, 0);
});
it("tracks email link clicks", function (done) {
const dom = setupDOM();
const link = dom.window.document.createElement("a");
link.href = "mailto:test@example.com";
link.target = "_blank";
dom.window.document.body.appendChild(link);
dom.window.saAutomatedLink(link, "email");
setTimeout(() => {
expect(dom.events[0]).to.deep.include({ name: "email_test_example_com" });
expect(dom.events[0].metadata).to.include({ email: "test@example.com" });
done();
}, 0);
});
});