|
1 | 1 | import 'react-dom' |
2 | 2 | import React from 'react' |
| 3 | +import {ThemeProvider} from 'theming' |
3 | 4 | import {mount} from 'enzyme' |
4 | 5 |
|
5 | 6 | import { |
@@ -131,4 +132,105 @@ describe('functional tests', () => { |
131 | 132 |
|
132 | 133 | wrapper.unmount() |
133 | 134 | }) |
| 135 | + |
| 136 | + describe('theming', () => { |
| 137 | + it('should work with ThemeProvider', () => { |
| 138 | + const theme = { |
| 139 | + color: { |
| 140 | + primary: 'red', |
| 141 | + secondary: 'black' |
| 142 | + } |
| 143 | + } |
| 144 | + |
| 145 | + const Button = styled('button')({ |
| 146 | + color: props => props.theme.color.primary, |
| 147 | + backgroundColor: props => props.theme.color.secondary, |
| 148 | + }) |
| 149 | + |
| 150 | + const wrapper = mount( |
| 151 | + <ThemeProvider theme={theme}> |
| 152 | + <Button /> |
| 153 | + </ThemeProvider> |
| 154 | + ) |
| 155 | + const {sheet} = styled |
| 156 | + |
| 157 | + assertSheet(sheet) |
| 158 | + |
| 159 | + wrapper.unmount() |
| 160 | + }) |
| 161 | + |
| 162 | + it('should update theme', () => { |
| 163 | + const initialTheme = { |
| 164 | + color: { |
| 165 | + primary: 'green', |
| 166 | + secondary: 'white' |
| 167 | + } |
| 168 | + } |
| 169 | + |
| 170 | + const Button = styled('button')({ |
| 171 | + color: props => props.theme.color.primary, |
| 172 | + backgroundColor: props => props.theme.color.secondary, |
| 173 | + }) |
| 174 | + |
| 175 | + const App = (props: {theme: Object}) => ( |
| 176 | + <ThemeProvider theme={props.theme}> |
| 177 | + <Button /> |
| 178 | + </ThemeProvider> |
| 179 | + ) |
| 180 | + |
| 181 | + const wrapper = mount(<App theme={initialTheme} />) |
| 182 | + const {sheet} = styled |
| 183 | + |
| 184 | + assertSheet(sheet) |
| 185 | + |
| 186 | + const nextTheme = { |
| 187 | + color: { |
| 188 | + primary: 'yellow', |
| 189 | + secondary: 'blue' |
| 190 | + } |
| 191 | + } |
| 192 | + wrapper.setProps({theme: nextTheme}) |
| 193 | + |
| 194 | + assertSheet(sheet) |
| 195 | + |
| 196 | + wrapper.unmount() |
| 197 | + }) |
| 198 | + |
| 199 | + it('should work with nested ThemeProvider', () => { |
| 200 | + const themes = [{ |
| 201 | + color: { |
| 202 | + primary: 'green', |
| 203 | + secondary: 'white' |
| 204 | + } |
| 205 | + }, { |
| 206 | + color: { |
| 207 | + primary: 'blue', |
| 208 | + secondary: 'yellow' |
| 209 | + } |
| 210 | + }] |
| 211 | + |
| 212 | + const Button = styled('button')({ |
| 213 | + color: props => props.theme.color.primary, |
| 214 | + backgroundColor: props => props.theme.color.secondary, |
| 215 | + }) |
| 216 | + |
| 217 | + const App = () => ( |
| 218 | + <ThemeProvider theme={themes[0]}> |
| 219 | + <div> |
| 220 | + <Button /> |
| 221 | + <ThemeProvider theme={themes[1]}> |
| 222 | + <Button /> |
| 223 | + </ThemeProvider> |
| 224 | + </div> |
| 225 | + </ThemeProvider> |
| 226 | + ) |
| 227 | + |
| 228 | + const wrapper = mount(<App />) |
| 229 | + const {sheet} = styled |
| 230 | + |
| 231 | + assertSheet(sheet) |
| 232 | + |
| 233 | + wrapper.unmount() |
| 234 | + }) |
| 235 | + }) |
134 | 236 | }) |
0 commit comments