generated from cis3296f22/project-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.test.js
90 lines (85 loc) · 2.34 KB
/
content.test.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
const content = require("./js/content.js");
var mockDocument;
var mockStorage;
var mockWindow;
beforeEach(() => {
mockDocument = {
body: {
style: {},
},
querySelector: jest.fn(),
};
mockStorage = {
get: jest.fn(),
set: jest.fn(),
};
mockWindow = {
location: { origin: "https://templeu.instructure.com" },
};
});
test("Test Loading With Darkmode ", () => {
var mockHTML = { style: { filter: undefined } };
mockDocument.querySelector.mockReturnValueOnce(mockHTML);
var c = content(mockStorage, mockDocument, mockWindow);
c.init();
expect(mockStorage.get).toHaveBeenCalledWith(
[
"darkMode",
"backgroundImg",
"rmHistory",
"rmHelp",
"rmCommons",
"rmInbox",
"rmCalendar",
"rmGroups",
"rmCourses",
"rmAccount",
"colorChoice",
],
expect.any(Function)
);
mockStorage.get.mock.calls[0][1]({
darkMode: true,
backgroundImg: "https://example.com/pic.jpg",
});
expect(mockDocument.body.style.backgroundImage).toEqual(
"url('https://example.com/pic.jpg')"
);
expect(mockDocument.body.style.backgroundRepeat).toEqual("no-repeat");
expect(mockDocument.body.style.backgroundSize).toEqual("contain");
expect(mockDocument.querySelector).toHaveBeenCalledWith("html");
expect(mockHTML.style.filter).toEqual("invert(1) hue-rotate(180deg)");
});
test("Test Loading Without Darkmode", () => {
var mockHTML = { style: { filter: undefined } };
mockDocument.querySelector.mockReturnValueOnce(mockHTML);
var c = content(mockStorage, mockDocument, mockWindow);
c.init();
expect(mockStorage.get).toHaveBeenCalledWith(
[
"darkMode",
"backgroundImg",
"rmHistory",
"rmHelp",
"rmCommons",
"rmInbox",
"rmCalendar",
"rmGroups",
"rmCourses",
"rmAccount",
"colorChoice",
],
expect.any(Function)
);
mockStorage.get.mock.calls[0][1]({
darkMode: false,
backgroundImg: "https://example2.com/pic.jpg",
});
expect(mockDocument.body.style.backgroundImage).toEqual(
"url('https://example2.com/pic.jpg')"
);
expect(mockDocument.body.style.backgroundRepeat).toEqual("no-repeat");
expect(mockDocument.body.style.backgroundSize).toEqual("contain");
expect(mockDocument.querySelector).toHaveBeenCalledWith("html");
expect(mockHTML.style.filter).toEqual("");
});