1 | import React from 'react'
|
2 | import 'jest-styled-components'
|
3 |
|
4 | import { ColorPicker, InlineImage } from 'SRC'
|
5 |
|
6 | const { mountWithTheme } = global
|
7 |
|
8 | const defaultProps = {
|
9 | alt: 'Multi',
|
10 | src: 'https://d2lknnt52h7uhg.cloudfront.net/roa-canon/image/upload/c_scale,q_100,t_swatch_v2,w_40/v1/production/catalog/jbku3g2yunsmtxz1c8nc.jpg',
|
11 | input: {
|
12 | name: 'color-block',
|
13 | value: 'multi',
|
14 | checked: true,
|
15 | onChange: jest.fn()
|
16 | }
|
17 | }
|
18 | describe('(Styled Component) ColorPicker', () => {
|
19 | const createColorPicker = (inProps) => {
|
20 | const props = {
|
21 | ...defaultProps,
|
22 | ...inProps
|
23 | }
|
24 | return mountWithTheme(<ColorPicker {...props} />)
|
25 | }
|
26 |
|
27 | test('matching the snapshot', () => {
|
28 | expect(createColorPicker())
|
29 | .toMatchSnapshot()
|
30 | })
|
31 |
|
32 | test('rending out the image', () => {
|
33 | expect(
|
34 | createColorPicker().find(InlineImage).prop('src')
|
35 | ).toEqual(defaultProps.src)
|
36 | expect(
|
37 | createColorPicker().find(InlineImage).prop('alt')
|
38 | ).toEqual(defaultProps.alt)
|
39 | })
|
40 |
|
41 | test('setting the input to be checked', () => {
|
42 | expect(
|
43 | createColorPicker().find('input').prop('checked')
|
44 | ).toEqual(true)
|
45 | expect(
|
46 | createColorPicker({
|
47 | ...defaultProps,
|
48 | input: {
|
49 | ...defaultProps.input,
|
50 | checked: false
|
51 | }
|
52 | })
|
53 | .find('input').prop('checked')
|
54 | ).toEqual(false)
|
55 | })
|
56 |
|
57 | test('firing onChange', () => {
|
58 | createColorPicker().find('input').simulate('change')
|
59 | expect(defaultProps.input.onChange).toHaveBeenCalled()
|
60 | })
|
61 | })
|
62 |
|
\ | No newline at end of file |