-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.test.js
91 lines (81 loc) · 2.89 KB
/
main.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
91
const { JSDOM } = require('jsdom');
const {
toBeInTheDocument,
toBeEmptyDOMElement,
toHaveStyle,
toHaveAttribute,
toHaveClass,
} = require('@testing-library/jest-dom/matchers');
const {default: userEvent} = require('@testing-library/user-event');
expect.extend({
toBeInTheDocument,
toBeEmptyDOMElement,
toHaveStyle,
toHaveAttribute,
toHaveClass,
});
const LEVELS = {
one: 'level_one',
two: 'level_two',
three: 'level_three',
};
let document = null;
let window = null;
beforeEach(async () => {
const jsDOM = await JSDOM.fromFile('index.html', {
runScripts: 'dangerously',
resources: 'usable',
url: `file://${__dirname}/`,
features: {
FetchExternalResources: ['script'],
ProcessExternalResources: ['script'],
},
});
await new Promise((res) => {
jsDOM.window.onload = res;
});
document = jsDOM.window.document;
window = jsDOM.window;
});
afterEach(() => {
document = null;
window = null;
});
describe(LEVELS.one, () => {
it(
'should use the CSS variables in the correct places in the CSS',
() => {
expect(document.querySelector('.plant-listing')).toHaveStyle('background-color: var(--primary-colour)');
expect(document.querySelector('body')).toHaveStyle('background-color: var(--secondary-colour)');
expect(document.querySelector('.body')).toHaveStyle('color: var(--text-colour)');
expect(document.querySelector('.plant-header')).toHaveStyle('font-size: var(--header-size)');
expect(document.querySelector('main')).toHaveStyle('font-size: var(--text-size)');
expect(document.querySelector('button')).toHaveStyle('font-size: var(--text-size)');
expect(document.querySelector('.plant-listing')).toHaveStyle('border-radius: var(--border-radius)');
expect(document.querySelector('.plant-pic')).toHaveStyle('border-radius: var(--border-radius)');
expect(document.querySelector('button')).toHaveStyle('border-radius: var(--border-radius)');
}
);
});
describe(LEVELS.two, () => {
it(
'should have the value of main-text-size be 18px (without changing any of the places in the rest of the CSS)',
() => {
expect(document.querySelector('main')).toHaveStyle('font-size: 18px');
}
);
});
describe(LEVELS.three, () => {
it(
'should have function hooked up to #dark-mode-button button that toggles the .dark-mode-theme class on and off',
() => {
const button = document.getElementById('dark-mode-button');
expect(document.querySelector('body')).not.toHaveClass('dark-mode-theme');
userEvent.click(button);
expect(document.querySelector('body')).toHaveClass('dark-mode-theme');
expect(document.querySelector('.plant-listing')).toHaveStyle('background-color: rgb(0, 87, 0)');
expect(document.querySelector('body')).toHaveStyle('background-color: black');
expect(document.querySelector('.body')).toHaveStyle('color: white');
}
);
});