-
-
Notifications
You must be signed in to change notification settings - Fork 153
/
Copy pathmain.spec.js
73 lines (65 loc) · 2.52 KB
/
main.spec.js
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
describe("Nothing Private unit tests", function () {
let fixture = null;
beforeAll(function () {
// To prevent call to API and fixing errors
window.calculateFingerprint = () => {
};
window.saveFingerPrintAPICall = (...data) => {};
});
beforeEach(function () {
fixture = document.createElement("div");
fixture.id = "fixture";
document.body.appendChild(fixture);
});
afterEach(function () {
if (document.getElementById("fixture")) {
document.body.removeChild(document.getElementById("fixture"));
}
});
it("renderNewTabPage function should render the text properly", function () {
const maindiv = document.createElement("div");
maindiv.id = "maindiv";
const user = document.createElement("div");
user.id = "user";
fixture.appendChild(maindiv);
fixture.appendChild(user);
const name = "Test";
renderNewTabPage(name);
expect(maindiv.innerHTML).toContain(name);
expect(user.innerHTML).toContain(name);
});
it("htmlEncode function should encode values correctly", function () {
const encoded = htmlEncode('<div>test<div>');
expect(encoded).toBe('<div>test<div>');
});
it("renderSubmit function should render the text properly", function () {
const maindiv = document.createElement("div");
maindiv.id = "maindiv";
fixture.appendChild(maindiv);
const name = "Test";
renderSubmit(name);
expect(maindiv.innerHTML).toContain(name);
expect(maindiv.innerHTML).toContain("Thank you");
});
it("renderMain function should render the text properly", function () {
const maindiv = document.createElement("div");
maindiv.id = "maindiv";
fixture.appendChild(maindiv);
renderMain();
expect(maindiv.innerHTML).toContain("Do you think that switching");
});
it("reload function should render the text properly", function () {
const maindiv = document.createElement("div");
maindiv.id = "maindiv";
fixture.appendChild(maindiv);
reload();
expect(maindiv.innerHTML).toContain("Loading");
});
it("errorHandler function should render the text properly", function () {
const maindiv = document.createElement("div");
maindiv.id = "maindiv";
fixture.appendChild(maindiv);
errorHandler();
expect(maindiv.innerHTML).toContain("An API error occurred");
});
});