Skip to content

Instantly share code, notes, and snippets.

@StevenLangbroek
Last active April 21, 2016 23:22
Show Gist options
  • Save StevenLangbroek/1b2fd82654639e24de6f395da93e0dfd to your computer and use it in GitHub Desktop.
Save StevenLangbroek/1b2fd82654639e24de6f395da93e0dfd to your computer and use it in GitHub Desktop.
import React from 'react';
import { connect } from 'react-redux';
import ProductBody from 'components/ProductBody';
import ProductImages from 'components/ProductImages';
import { openProduct } from 'reducers/product';
const ProductDetail = ({
product,
handleProductClick
}) => (
<div className="product" onClick={handleProductClick}>
<ProductImages images={product.get('images')} onSomeEvent={handleProductClick} />
<ProductBody productProperties={product.get('properties')} onMoreClick={handleProductClick} />
</div>
);
const mapStateToProps = (state, { params: { productId }}) => {
const product = getEntities(state).getIn(['products', parseInt(productId, 10)]);
return {
product
};
};
const mapDispatchToProps = {
handleProductClick: openProduct
};
export defaultconnect(mapStateToProps, mapDispatchToProps)(ProductDetail);
import ProductBody from 'components/ProductBody';
import { shallow } from 'enzyme';
describe('<ProductBody />', () => {
it('calls click succesfully', () => {
const product = {
id: 1,
title: 'Awesome product'
};
const subject = sinon.spy();
const component = shallow(<ProductBody product={product} onMoreClick={clickSpy} />);
component.find('.some-el').simulate('click');
expext(clickSpy).to.be.calledOnce.and.calledWith(product.id);
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment