|
| 1 | +import * as React from 'react' |
| 2 | +import { mount } from 'enzyme' |
| 3 | + |
| 4 | +import Provider from 'src/components/Provider/Provider' |
| 5 | +import ProviderConsumer from 'src/components/Provider/ProviderConsumer' |
| 6 | +import { IThemeInput } from 'types/theme' |
| 7 | + |
| 8 | +describe('ProviderConsumer', () => { |
| 9 | + test('is exported', () => { |
| 10 | + expect(require('src/index.ts').ProviderConsumer).toEqual(ProviderConsumer) |
| 11 | + }) |
| 12 | + |
| 13 | + test('is a subcomponent of the Provider', () => { |
| 14 | + expect(Provider.Consumer).toEqual(ProviderConsumer) |
| 15 | + }) |
| 16 | + |
| 17 | + describe('render', () => { |
| 18 | + test('is a callback that receives the prepared theme', () => { |
| 19 | + expect.assertions(13) |
| 20 | + |
| 21 | + const inputTheme: IThemeInput = { |
| 22 | + siteVariables: { a: 'b' }, |
| 23 | + componentVariables: { Button: { color: 'red' } }, |
| 24 | + componentStyles: { Button: { root: { color: 'red' } } }, |
| 25 | + fontFaces: [{ name: 'name', paths: ['path.woff2'], style: { fontWeight: 400 } }], |
| 26 | + staticStyles: ['body{margin:0;}', { body: { margin: 0 } }], |
| 27 | + icons: { |
| 28 | + user: { icon: { content: '\\f1', fontFamily: 'i' } }, |
| 29 | + userFunc: { icon: () => ({ content: '\\f1', fontFamily: 'i' }) }, |
| 30 | + userSvg: { isSvg: true, icon: <svg /> }, |
| 31 | + userSvgFunc: { isSvg: true, icon: () => <svg /> }, |
| 32 | + }, |
| 33 | + } |
| 34 | + |
| 35 | + mount( |
| 36 | + <Provider theme={inputTheme}> |
| 37 | + <Provider.Consumer |
| 38 | + render={preparedTheme => { |
| 39 | + // siteVariables |
| 40 | + expect(preparedTheme).toHaveProperty('siteVariables.a', 'b') |
| 41 | + |
| 42 | + // componentVariables |
| 43 | + expect(preparedTheme).toHaveProperty('componentVariables.Button') |
| 44 | + expect(preparedTheme.componentVariables.Button).toBeInstanceOf(Function) |
| 45 | + expect(preparedTheme.componentVariables.Button()).toMatchObject( |
| 46 | + inputTheme.componentVariables.Button, |
| 47 | + ) |
| 48 | + |
| 49 | + // componentStyles |
| 50 | + expect(preparedTheme).toHaveProperty('componentStyles.Button.root') |
| 51 | + expect(preparedTheme.componentStyles.Button.root).toBeInstanceOf(Function) |
| 52 | + expect(preparedTheme.componentStyles.Button.root()).toMatchObject( |
| 53 | + inputTheme.componentStyles.Button.root, |
| 54 | + ) |
| 55 | + |
| 56 | + // fontFaces |
| 57 | + expect(preparedTheme).toHaveProperty('fontFaces') |
| 58 | + expect(preparedTheme.fontFaces).toMatchObject(inputTheme.fontFaces) |
| 59 | + |
| 60 | + // staticStyles |
| 61 | + expect(preparedTheme).toHaveProperty('staticStyles') |
| 62 | + expect(preparedTheme.staticStyles).toMatchObject(inputTheme.staticStyles) |
| 63 | + |
| 64 | + // icons |
| 65 | + expect(preparedTheme).toHaveProperty('icons') |
| 66 | + expect(preparedTheme.icons).toMatchObject(inputTheme.icons) |
| 67 | + return null |
| 68 | + }} |
| 69 | + /> |
| 70 | + </Provider>, |
| 71 | + ) |
| 72 | + }) |
| 73 | + }) |
| 74 | +}) |
0 commit comments