Skip to content

Commit 7e04cff

Browse files
committed
test(theme): add tests for getCustomTheme
1 parent bbbb627 commit 7e04cff

File tree

1 file changed

+130
-1
lines changed

1 file changed

+130
-1
lines changed

core/src/utils/theme.spec.ts

Lines changed: 130 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,136 @@ import { newSpecPage } from '@stencil/core/testing';
33
import { CardContent } from '../components/card-content/card-content';
44
import { Chip } from '../components/chip/chip';
55

6-
import { generateComponentThemeCSS, generateCSSVars, generateGlobalThemeCSS, injectCSS } from './theme';
6+
import { generateComponentThemeCSS, generateCSSVars, generateGlobalThemeCSS, getCustomTheme, injectCSS } from './theme';
7+
8+
describe('getCustomTheme', () => {
9+
it('should return the custom theme if no mode overrides exist', () => {
10+
const customTheme = {
11+
components: {
12+
IonChip: {
13+
hue: {
14+
subtle: {
15+
bg: 'red',
16+
color: 'white',
17+
},
18+
},
19+
},
20+
},
21+
};
22+
23+
const result = getCustomTheme(customTheme, 'ios');
24+
25+
expect(result).toEqual(customTheme);
26+
});
27+
28+
it('should combine only with ios overrides if mode is ios', () => {
29+
const customTheme = {
30+
components: {
31+
IonChip: {
32+
hue: {
33+
subtle: {
34+
bg: 'red',
35+
color: 'white',
36+
},
37+
},
38+
},
39+
},
40+
ios: {
41+
components: {
42+
IonChip: {
43+
hue: {
44+
subtle: {
45+
bg: 'blue',
46+
},
47+
},
48+
},
49+
},
50+
},
51+
md: {
52+
components: {
53+
IonChip: {
54+
hue: {
55+
subtle: {
56+
bg: 'green',
57+
},
58+
},
59+
},
60+
},
61+
},
62+
};
63+
64+
const result = getCustomTheme(customTheme, 'ios');
65+
66+
const expected = {
67+
components: {
68+
IonChip: {
69+
hue: {
70+
subtle: {
71+
bg: 'blue',
72+
color: 'white',
73+
},
74+
},
75+
},
76+
},
77+
};
78+
79+
expect(result).toEqual(expected);
80+
});
81+
82+
it('should combine only with md overrides if mode is md', () => {
83+
const customTheme = {
84+
components: {
85+
IonChip: {
86+
hue: {
87+
subtle: {
88+
bg: 'red',
89+
color: 'white',
90+
},
91+
},
92+
},
93+
},
94+
ios: {
95+
components: {
96+
IonChip: {
97+
hue: {
98+
subtle: {
99+
bg: 'blue',
100+
},
101+
},
102+
},
103+
},
104+
},
105+
md: {
106+
components: {
107+
IonChip: {
108+
hue: {
109+
subtle: {
110+
bg: 'green',
111+
},
112+
},
113+
},
114+
},
115+
},
116+
};
117+
118+
const result = getCustomTheme(customTheme, 'md');
119+
120+
const expected = {
121+
components: {
122+
IonChip: {
123+
hue: {
124+
subtle: {
125+
bg: 'green',
126+
color: 'white',
127+
},
128+
},
129+
},
130+
},
131+
};
132+
133+
expect(result).toEqual(expected);
134+
});
135+
});
7136

8137
describe('generateCSSVars', () => {
9138
it('should not generate CSS variables for an empty theme', () => {

0 commit comments

Comments
 (0)