From bd45d4c7aac6d1c6b054185058a96b2e01669828 Mon Sep 17 00:00:00 2001 From: Wes Bos Date: Wed, 14 Mar 2018 21:00:08 -0400 Subject: tests --- frontend/components/Cart.js | 82 +++++++++++++++++++++------------------------ 1 file changed, 38 insertions(+), 44 deletions(-) (limited to 'frontend/components/Cart.js') diff --git a/frontend/components/Cart.js b/frontend/components/Cart.js index f270b80..8752c54 100644 --- a/frontend/components/Cart.js +++ b/frontend/components/Cart.js @@ -1,9 +1,8 @@ -import { Component } from 'react'; -import { graphql, compose } from 'react-apollo'; +import React from 'react'; +import { compose } from 'react-apollo'; import styled from 'styled-components'; -import Title from './styles/Title'; -import { updateUIEnhancer, userEnhancer, uiEnhancer } from '../enhancers/enhancers'; -import RemoveFromCart from './RemoveFromCart'; +import PropTypes from 'prop-types'; +import { userEnhancer } from '../enhancers/enhancers'; import TakeMyMoney from './TakeMyMoney'; import formatMoney from '../lib/formatMoney'; import { UIContext } from './UIContext'; @@ -74,48 +73,43 @@ const CloseButton = styled.button` right: 0; `; -class Cart extends Component { - componentDidMount() { - // TODO listen for escape - } +const Cart = props => { + const { me } = props.currentUser; + if (!me) return null; + const itemCount = me.cart.length; + const totalPrice = me.cart.reduce((tally, cartItem) => tally + cartItem.quantity * cartItem.item.price, 0); - componentWillUnmount() { - // TODO unlisten for escape - } - render() { - const { me } = this.props.currentUser; - if (!me) return null; - const itemCount = me.cart.length; - const quantityCount = me.cart.reduce((tally, cartItem) => tally + cartItem.quantity, 0); - const totalPrice = me.cart.reduce((tally, cartItem) => tally + cartItem.quantity * cartItem.item.price, 0); + return ( + + {context => ( + +
+ + × + - return ( - - {context => ( - -
- - × - + {me.name}'s Cart. +

+ You have {itemCount} item{itemCount === 1 ? '' : 's'} in your cart. +

+
- {me.name}'s Cart. -

- You have {itemCount} item{itemCount === 1 ? '' : 's'} in your cart. -

-
+ {me.cart.map(cartItem => )} +
+

{formatMoney(totalPrice)}

+ + + +
+
+ )} +
+ ); +}; - {me.cart.map(cartItem => )} - - - )} - - ); - } -} +Cart.propTypes = { + currentUser: PropTypes.object.isRequired, +}; export default compose(userEnhancer)(Cart); +export { Cart }; -- cgit v1.3