forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuse-theme.js
More file actions
39 lines (34 loc) · 1.43 KB
/
use-theme.js
File metadata and controls
39 lines (34 loc) · 1.43 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
import { describe, expect, test } from '@jest/globals'
import {
getComponentTheme,
getCssTheme,
defaultCSSTheme,
defaultComponentTheme,
} from '../../components/hooks/useTheme.ts'
describe('getTheme basics', () => {
test('always return an object with certain keys', () => {
const cookieValue = JSON.stringify({})
expect(getCssTheme(cookieValue)).toEqual(defaultCSSTheme)
expect(getComponentTheme(cookieValue)).toEqual(defaultComponentTheme)
})
test('ignore "junk" cookie values', () => {
const cookieValue = '[This is not valid JSON}'
expect(getCssTheme(cookieValue)).toEqual(defaultCSSTheme)
expect(getComponentTheme(cookieValue)).toEqual(defaultComponentTheme)
})
test('respect the color_mode cookie value', () => {
const cookieValue = JSON.stringify({
color_mode: 'dark',
light_theme: { name: 'light_colorblind', color_mode: 'light' },
dark_theme: { name: 'dark_tritanopia', color_mode: 'dark' },
})
const cssTheme = getCssTheme(cookieValue)
expect(cssTheme.colorMode).toBe('dark')
expect(cssTheme.darkTheme).toBe(defaultCSSTheme.darkTheme)
expect(cssTheme.lightTheme).toBe(defaultCSSTheme.lightTheme)
const componentTheme = getComponentTheme(cookieValue)
expect(componentTheme.colorMode).toBe('night')
expect(componentTheme.nightScheme).toBe(defaultComponentTheme.nightScheme)
expect(componentTheme.dayScheme).toBe(defaultComponentTheme.dayScheme)
})
})