Skip to content
Permalink
Browse files

Add snapshot specs for containers

  • Loading branch information...
jcemer committed Apr 11, 2017
1 parent 2a24fdc commit 78679a5220b90de82b4ae30eb228aa1360c04352
@@ -4,7 +4,6 @@
"homepage": "http://jcemer.com/minimalistic-shop/",
"dependencies": {
"classnames": "^2.2.5",
"enzyme": "^2.7.1",
"lodash": "^4.17.4",
"react": "^15.4.2",
"react-dom": "^15.4.2",
@@ -18,6 +17,8 @@
"semantic-ui-css": "^2.2.9"
},
"devDependencies": {
"enzyme": "^2.8.0",
"enzyme-to-json": "^1.5.0",
"gh-pages": "^0.12.0",
"react-addons-test-utils": "^15.4.2",
"react-scripts": "0.9.5"
@@ -1,5 +1,6 @@
import React from 'react'
import { shallow } from 'enzyme'
import { shallow, render } from 'enzyme'
import toJson from 'enzyme-to-json'

import { CartContainer, mapStateToProps } from '../CartContainer'
import Cart from '../../components/Cart'
@@ -14,6 +15,13 @@ describe('CartContainer', () => {

expect(wrapper.contains(<Cart checkout={checkout} items={items} />)).toBe(true)
})

it('should render the proper HTML of Cart with items', () => {
const items = { '123': { _id: '123', image: 'url', quantity: 2 } }
const wrapper = render(<CartContainer checkout={checkout} items={items} />)

expect(toJson(wrapper)).toMatchSnapshot()
})
})

describe('mapStateToProps', () => {
@@ -1,5 +1,7 @@
import React from 'react'
import { shallow } from 'enzyme'
import { shallow, render } from 'enzyme'
import toJson from 'enzyme-to-json'
import { MemoryRouter } from 'react-router-dom'

import { ProductDetailContainer, mapStateToProps } from '../ProductDetailContainer'
import ProductDetail from '../../components/ProductDetail'
@@ -26,6 +28,17 @@ describe('ProductDetailContainer', () => {

expect(wrapper.contains(<ProductDetail addToCart={addToCart} {...item} />)).toBe(true)
})

it('should render the proper HTML of ProductDetail with item', () => {
const item = { _id: '123', image: 'url', price: '$1', description: 'bla', stock: { remaining: 1 } }
const wrapper = render(
<MemoryRouter>
<ProductDetailContainer addToCart={addToCart} isReady item={item} />
</MemoryRouter>
)

expect(toJson(wrapper)).toMatchSnapshot()
})
})

describe('mapStateToProps', () => {
@@ -1,5 +1,7 @@
import React from 'react'
import { shallow } from 'enzyme'
import { shallow, render } from 'enzyme'
import toJson from 'enzyme-to-json'
import { MemoryRouter } from 'react-router-dom'

import { ProductListContainer, mapStateToProps } from '../ProductListContainer'
import ProductList from '../../components/ProductList'
@@ -20,6 +22,17 @@ describe('ProductListContainer', () => {

expect(wrapper.contains(<ProductList addToCart={addToCart} items={items} />)).toBe(true)
})

it('should render the proper HTML of ProductList with items', () => {
const items = [{ _id: '123', image: 'url', price: '$1', stock: { remaining: 2 } }]
const wrapper = render(
<MemoryRouter>
<ProductListContainer addToCart={addToCart} isReady items={items} />
</MemoryRouter>
)

expect(toJson(wrapper)).toMatchSnapshot()
})
})

describe('mapStateToProps', () => {
@@ -0,0 +1,36 @@
exports[`CartContainer <Component /> should render the proper HTML of Cart with items 1`] = `
<div>
<div
class="ui header">
Shopping Cart
</div>
<div>
<div
class="ui unstackable divided items">
<div
class="ui item">
<div
class="ui tiny image">
<img
alt="Product 123"
src="url" />
</div>
<div
class="middle aligned content">
<div
class="ui tiny header">
Product 123
</div>
<div>
Quantity: 2
</div>
</div>
</div>
</div>
<button
class="ui button fluid blue">
Checkout
</button>
</div>
</div>
`;
@@ -0,0 +1,57 @@
exports[`ProductDetailContainer <Component /> should render the proper HTML of ProductDetail with item 1`] = `
<div
class="ui container">
<div
class="ui breadcrumb">
<a
class="section"
href="/">
Home
</a>
<i
class="right angle icon divider" />
<div
class="active section">
Product
</div>
</div>
<div
class="ui unstackable items">
<div
class="item">
<div
class="image">
<img
alt="Product 123"
src="url" />
</div>
<div
class="content">
<div
class="ui header">
Product 123
</div>
<div
class="meta">
Price $1
</div>
<div
class="description">
Description: bla
</div>
<div
class="extra">
Remaining stock: 1 item(s)
</div>
<div
class="extra">
<button
class="ui green button">
Add to cart
</button>
</div>
</div>
</div>
</div>
</div>
`;
@@ -0,0 +1,28 @@
exports[`ProductListContainer <Component /> should render the proper HTML of ProductList with items 1`] = `
<div
class="ui five column doubling cards">
<div
class="ui card">
<a
class="ui image"
href="/product/123">
<img
alt="Product 123"
src="url" />
</a>
<div
class="content">
<div>
Price $1
</div>
</div>
<div
class="extra content">
<button
class="ui green button fluid">
Add to cart
</button>
</div>
</div>
</div>
`;
@@ -1714,9 +1714,21 @@ entities@^1.1.1, entities@~1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/entities/-/entities-1.1.1.tgz#6e5c2d0a5621b5dadaecef80b90edfb5cd7772f0"

enzyme@^2.7.1:
version "2.7.1"
resolved "https://registry.yarnpkg.com/enzyme/-/enzyme-2.7.1.tgz#76370e1d99e91f73091bb8c4314b7c128cc2d621"
enzyme-to-json@^1.5.0:
version "1.5.0"
resolved "https://registry.yarnpkg.com/enzyme-to-json/-/enzyme-to-json-1.5.0.tgz#bb94f21346866d68378adc9b26856dd6e2bfa60b"
dependencies:
lodash.filter "^4.6.0"
lodash.isnil "^4.0.0"
lodash.isplainobject "^4.0.6"
lodash.omitby "^4.5.0"
lodash.range "^3.2.0"
object-values "^1.0.0"
object.entries "^1.0.3"

enzyme@^2.8.0:
version "2.8.0"
resolved "https://registry.yarnpkg.com/enzyme/-/enzyme-2.8.0.tgz#86cc1fc96e5cbd7695766dd6e89deb13a0aead51"
dependencies:
cheerio "^0.22.0"
function.prototype.name "^1.0.0"
@@ -3384,7 +3396,7 @@ lodash.defaults@^4.0.1:
version "4.2.0"
resolved "https://registry.yarnpkg.com/lodash.defaults/-/lodash.defaults-4.2.0.tgz#d09178716ffea4dde9e5fb7b37f6f0802274580c"

lodash.filter@^4.4.0:
lodash.filter@^4.4.0, lodash.filter@^4.6.0:
version "4.6.0"
resolved "https://registry.yarnpkg.com/lodash.filter/-/lodash.filter-4.6.0.tgz#668b1d4981603ae1cc5a6fa760143e480b4c4ace"

@@ -3404,6 +3416,14 @@ lodash.isarray@^3.0.0:
version "3.0.4"
resolved "https://registry.yarnpkg.com/lodash.isarray/-/lodash.isarray-3.0.4.tgz#79e4eb88c36a8122af86f844aa9bcd851b5fbb55"

lodash.isnil@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/lodash.isnil/-/lodash.isnil-4.0.0.tgz#49e28cd559013458c814c5479d3c663a21bfaa6c"

lodash.isplainobject@^4.0.6:
version "4.0.6"
resolved "https://registry.yarnpkg.com/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz#7c526a52d89b45c45cc690b88163be0497f550cb"

lodash.keys@^3.0.0:
version "3.1.2"
resolved "https://registry.yarnpkg.com/lodash.keys/-/lodash.keys-3.1.2.tgz#4dbc0472b156be50a0b286855d1bd0b0c656098a"
@@ -3424,6 +3444,10 @@ lodash.merge@^4.4.0:
version "4.6.0"
resolved "https://registry.yarnpkg.com/lodash.merge/-/lodash.merge-4.6.0.tgz#69884ba144ac33fe699737a6086deffadd0f89c5"

lodash.omitby@^4.5.0:
version "4.6.0"
resolved "https://registry.yarnpkg.com/lodash.omitby/-/lodash.omitby-4.6.0.tgz#5c15ff4754ad555016b53c041311e8f079204791"

lodash.pick@^4.2.1:
version "4.4.0"
resolved "https://registry.yarnpkg.com/lodash.pick/-/lodash.pick-4.4.0.tgz#52f05610fff9ded422611441ed1fc123a03001b3"
@@ -3432,6 +3456,10 @@ lodash.pickby@^4.6.0:
version "4.6.0"
resolved "https://registry.yarnpkg.com/lodash.pickby/-/lodash.pickby-4.6.0.tgz#7dea21d8c18d7703a27c704c15d3b84a67e33aff"

lodash.range@^3.2.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/lodash.range/-/lodash.range-3.2.0.tgz#f461e588f66683f7eadeade513e38a69a565a15d"

lodash.reduce@^4.4.0:
version "4.6.0"
resolved "https://registry.yarnpkg.com/lodash.reduce/-/lodash.reduce-4.6.0.tgz#f1ab6b839299ad48f784abbf476596f03b914d3b"
@@ -3777,6 +3805,10 @@ object-keys@^1.0.10, object-keys@^1.0.8:
version "1.0.11"
resolved "https://registry.yarnpkg.com/object-keys/-/object-keys-1.0.11.tgz#c54601778ad560f1142ce0e01bcca8b56d13426d"

object-values@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/object-values/-/object-values-1.0.0.tgz#72af839630119e5b98c3b02bb8c27e3237158105"

object.assign@^4.0.4:
version "4.0.4"
resolved "https://registry.yarnpkg.com/object.assign/-/object.assign-4.0.4.tgz#b1c9cc044ef1b9fe63606fc141abbb32e14730cc"

0 comments on commit 78679a5

Please sign in to comment.
You can’t perform that action at this time.