1 | import React from 'react'
|
2 | import 'jest-styled-components'
|
3 |
|
4 | import { InlineImage } from 'SRC'
|
5 |
|
6 | const { mountWithTheme } = global
|
7 |
|
8 | describe('(Styled Component) InlineImage', () => {
|
9 | const defaultProps = {
|
10 | src: 'https://dummyInlineImage.com/100x100/CCC/333.png&text=small'
|
11 | }
|
12 | const createInlineImage = (inProps) => {
|
13 | const props = {
|
14 | ...defaultProps,
|
15 | ...inProps
|
16 | }
|
17 | return mountWithTheme(<InlineImage {...props} />)
|
18 | }
|
19 |
|
20 | describe('When no props are provided', () => {
|
21 | test('matching the snapshot', () => {
|
22 | expect(createInlineImage())
|
23 | .toMatchSnapshot()
|
24 | })
|
25 | })
|
26 | describe('When props are provided', () => {
|
27 | test('setting the src', () => {
|
28 | const srcString = 'https://dummyInlineImage.com/350x350/CCC/333.png&text=medium'
|
29 | const InlineImageComponent = createInlineImage({
|
30 | src: srcString
|
31 | })
|
32 | expect(InlineImageComponent.find('img').prop('src')).toEqual(srcString)
|
33 | })
|
34 |
|
35 | describe('setting the alt prop', () => {
|
36 | test('when the alt tag is unset alt should be empty string', () => {
|
37 | const InlineImageComponent = createInlineImage()
|
38 | expect(InlineImageComponent.find('img').prop('alt')).toEqual('')
|
39 | })
|
40 |
|
41 | test('when the alt tag is set', () => {
|
42 | const altString = 'Filler InlineImage with the text "small".'
|
43 | const InlineImageComponent = createInlineImage({alt: altString})
|
44 | expect(InlineImageComponent.find('img').prop('alt')).toEqual(altString)
|
45 | })
|
46 | })
|
47 |
|
48 | test('Setting the srcSet', () => {
|
49 | const srcSetString =
|
50 | `https://dummyInlineImage.com/800x800/CCC/333.png&text=large 800w,
|
51 | https://dummyInlineImage.com/350x350/CCC/333.png&text=medium 350w,
|
52 | https://dummyInlineImage.com/100x100/CCC/333.png&text=small 100w`
|
53 | const sizesString = `800px (min-width: 500px),
|
54 | 350px (min-width: 300px),
|
55 | 100px (min-width: 200px)`
|
56 | const InlineImageComponent = createInlineImage({
|
57 | sizes: {
|
58 | '800px': '(min-width: 500px)',
|
59 | '350px': '(min-width: 300px)',
|
60 | '100px': '(min-width: 200px)'
|
61 | },
|
62 | srcSet: {
|
63 | '800w': 'https://dummyInlineImage.com/800x800/CCC/333.png&text=large',
|
64 | '350w': 'https://dummyInlineImage.com/350x350/CCC/333.png&text=medium',
|
65 | '100w': 'https://dummyInlineImage.com/100x100/CCC/333.png&text=small'
|
66 | }
|
67 | })
|
68 | expect(InlineImageComponent.find('img').prop('srcSet')).toEqual(srcSetString)
|
69 | expect(InlineImageComponent.find('img').prop('sizes')).toContain(sizesString)
|
70 | })
|
71 | })
|
72 |
|
73 | test('data-src is set when lazyLoad prop is passed', () => {
|
74 | expect(createInlineImage({lazyLoad: true}).find('img').prop('src')).toEqual(undefined)
|
75 | expect(createInlineImage({lazyLoad: true}).find('img').prop('data-src')).toEqual(defaultProps.src)
|
76 | })
|
77 | })
|
78 |
|
\ | No newline at end of file |