forked from swiftlang/swift-docc-render
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththemes.spec.js
99 lines (91 loc) · 2.78 KB
/
themes.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/**
* This source file is part of the Swift.org open source project
*
* Copyright (c) 2021 Apple Inc. and the Swift project authors
* Licensed under Apache License v2.0 with Runtime Library Exception
*
* See https://swift.org/LICENSE.txt for license information
* See https://swift.org/CONTRIBUTORS.txt for Swift project authors
*/
import { objectToCustomProperties } from 'docc-render/utils/themes';
describe('themes', () => {
it('works if passed `undefined`', () => {
expect(objectToCustomProperties(undefined)).toEqual({});
});
it('works if passed `null`', () => {
expect(objectToCustomProperties(null)).toEqual({});
});
it('converts a deeply nested object into an object with custom css properties', () => {
const treeToWalk = {
level1: {
prop1: 'value1',
level2: {
prop2: 'value2',
},
},
level1_1: 'value1_1',
'level_1-2': 'value1_2',
levelOneItemFour: 1,
};
expect(objectToCustomProperties(treeToWalk))
.toEqual({
'--level1-prop1': 'value1',
'--level1-level2-prop2': 'value2',
'--level1_1': 'value1_1',
'--level_1-2': 'value1_2',
'--levelOneItemFour': 1,
});
});
it('supports light/dark mode variants', () => {
const treeToWalk = {
button: {
background: {
light: '#ffffff',
dark: '#000000',
},
},
};
expect(objectToCustomProperties(treeToWalk, 'light')).toEqual({
'--button-background': treeToWalk.button.background.light,
});
expect(objectToCustomProperties(treeToWalk, 'dark')).toEqual({
'--button-background': treeToWalk.button.background.dark,
});
});
it('supports having a `light` and `dark` key', () => {
const treeToWalk = {
nav: {
light: {
text: '#fff',
background: '#000',
},
dark: {
text: '#000',
background: '#fff',
},
},
};
const result = {
'--nav-light-text': treeToWalk.nav.light.text,
'--nav-light-background': treeToWalk.nav.light.background,
'--nav-dark-text': treeToWalk.nav.dark.text,
'--nav-dark-background': treeToWalk.nav.dark.background,
};
// both are the same, because the end values are not `light/dark`
expect(objectToCustomProperties(treeToWalk, 'light')).toEqual(result);
expect(objectToCustomProperties(treeToWalk, 'dark')).toEqual(result);
});
it('does not retrieve a value, not specified for current color scheme', () => {
const treeToWalk = {
nav: {
text: {
dark: '#fff',
},
},
};
expect(objectToCustomProperties(treeToWalk, 'light')).toEqual({});
expect(objectToCustomProperties(treeToWalk, 'dark')).toEqual({
'--nav-text': '#fff',
});
});
});