Skip to content

Commit a19ff67

Browse files
committed
Unit tests added
1 parent 7034e7b commit a19ff67

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

tests/lib/themeManager-test.js

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/**
2+
* @fileoverview Unit test for browser/main/lib/ThemeManager.js
3+
*/
4+
const test = require('ava')
5+
const { chooseTheme, applyTheme } = require('browser/main/lib/ThemeManager')
6+
7+
const originalDate = Date
8+
9+
test.beforeEach(t => {
10+
t.context = {
11+
theme: 'white',
12+
scheduledTheme: 'dark',
13+
enableScheduleTheme: true,
14+
defaultTheme: 'monokai'
15+
}
16+
const constantDate = new Date('2017-11-27T14:33:42Z')
17+
global.Date = class extends Date {
18+
constructor () {
19+
super()
20+
return constantDate
21+
}
22+
}
23+
})
24+
25+
test.afterEach(t => {
26+
global.Date = originalDate
27+
})
28+
29+
test('enableScheduleTheme is false, theme shouldn\'t change', t => {
30+
t.context.enableScheduleTheme = false
31+
32+
const beforeTheme = t.context.theme
33+
chooseTheme(t.context)
34+
const afterTheme = t.context.theme
35+
36+
t.is(afterTheme, beforeTheme)
37+
})
38+
39+
// NOT IN SCHEDULE
40+
test('scheduleEnd is bigger than scheduleStart and not in schedule, theme shouldn\'t change', t => {
41+
const beforeTheme = t.context.defaultTheme
42+
t.context.scheduleStart = 720 // 12:00
43+
t.context.scheduleEnd = 870 // 14:30
44+
chooseTheme(t.context)
45+
const afterTheme = t.context.theme
46+
47+
t.is(afterTheme, beforeTheme)
48+
})
49+
50+
test('scheduleStart is bigger than scheduleEnd and not in schedule, theme shouldn\'t change', t => {
51+
const beforeTheme = t.context.defaultTheme
52+
t.context.scheduleStart = 960 // 16:00
53+
t.context.scheduleEnd = 600 // 10:00
54+
chooseTheme(t.context)
55+
const afterTheme = t.context.theme
56+
57+
t.is(afterTheme, beforeTheme)
58+
})
59+
60+
// IN SCHEDULE
61+
test('scheduleEnd is bigger than scheduleStart and in schedule, theme should change', t => {
62+
const beforeTheme = t.context.scheduledTheme
63+
t.context.scheduleStart = 720 // 12:00
64+
t.context.scheduleEnd = 900 // 15:00
65+
chooseTheme(t.context)
66+
const afterTheme = t.context.theme
67+
68+
t.is(afterTheme, beforeTheme)
69+
})
70+
71+
test('scheduleStart is bigger than scheduleEnd and in schedule, theme should change', t => {
72+
const beforeTheme = t.context.scheduledTheme
73+
t.context.scheduleStart = 1200 // 20:00
74+
t.context.scheduleEnd = 900 // 15:00
75+
chooseTheme(t.context)
76+
const afterTheme = t.context.theme
77+
78+
t.is(afterTheme, beforeTheme)
79+
})
80+
81+
test('theme to apply is not a supported theme, theme shouldn\'t change', t => {
82+
applyTheme('notATheme')
83+
const afterTheme = document.body.dataset.theme
84+
85+
t.is(afterTheme, 'default')
86+
})
87+
88+
test('theme to apply is a supported theme, theme should change', t => {
89+
applyTheme(t.context.defaultTheme)
90+
const afterTheme = document.body.dataset.theme
91+
92+
t.is(afterTheme, t.context.defaultTheme)
93+
})

0 commit comments

Comments
 (0)