|
| 1 | +import React from 'react' |
| 2 | +import { shallow } from 'enzyme' |
| 3 | +import Block, * as styles from '.' |
| 4 | + |
| 5 | +const wrap = (props = {}) => shallow(<Block {...props} />) |
| 6 | + |
| 7 | +it('renders children when passed in', () => { |
| 8 | + const wrapper = wrap({ children: 'test' }) |
| 9 | + expect(wrapper.contains('test')).toBe(true) |
| 10 | +}) |
| 11 | + |
| 12 | +it('renders props when passed in', () => { |
| 13 | + const wrapper = wrap({ id: 'foo' }) |
| 14 | + expect(wrapper.find({ id: 'foo' })).toHaveLength(1) |
| 15 | +}) |
| 16 | + |
| 17 | +describe('styles', () => { |
| 18 | + const theme = { |
| 19 | + fonts: { |
| 20 | + primary: 'sans-serif' |
| 21 | + }, |
| 22 | + colors: { |
| 23 | + grayscale: { 0: '#222' }, |
| 24 | + primary: { 0: 'darkred', 1: 'red' } |
| 25 | + }, |
| 26 | + reverseColors: { |
| 27 | + grayscale: { 0: '#fff' }, |
| 28 | + primary: { 0: 'lightblue', 1: 'blue' } |
| 29 | + } |
| 30 | + } |
| 31 | + |
| 32 | + test('fontFamily', () => { |
| 33 | + expect(styles.fontFamily({ theme })).toBe(theme.fonts.primary) |
| 34 | + }) |
| 35 | + |
| 36 | + test('backgroundColor', () => { |
| 37 | + const props = { |
| 38 | + color: 'grayscale', |
| 39 | + reverse: false, |
| 40 | + theme |
| 41 | + } |
| 42 | + expect(styles.backgroundColor(props)).toBe(theme.reverseColors.grayscale[0]) |
| 43 | + expect(styles.backgroundColor({ ...props, transparent: true })).toBe('transparent') |
| 44 | + expect(styles.backgroundColor({ ...props, reverse: true })).toBe(theme.colors.grayscale[0]) |
| 45 | + expect(styles.backgroundColor({ ...props, color: 'primary' })) |
| 46 | + .toBe(theme.reverseColors.primary[0]) |
| 47 | + }) |
| 48 | + |
| 49 | + test('color', () => { |
| 50 | + const props = { |
| 51 | + color: 'grayscale', |
| 52 | + reverse: false, |
| 53 | + theme |
| 54 | + } |
| 55 | + expect(styles.color(props)).toBe(theme.colors.grayscale[0]) |
| 56 | + expect(styles.color({ ...props, reverse: true })).toBe(theme.reverseColors.grayscale[0]) |
| 57 | + expect(styles.color({ ...props, color: 'primary' })).toBe(theme.colors.primary[1]) |
| 58 | + }) |
| 59 | +}) |
0 commit comments