Commit 4f884ba8 authored by Martin Fahl's avatar Martin Fahl

removes code for increment and decrement

parent 81a8bc1a
import * as types from "../constants/ActionTypes"
export const updateItem = (id, name, quantity) => ({
type: types.ITEM_UPDATED,
id,
name,
quantity
})
\ No newline at end of file
/* TODO add updateItem action */
\ No newline at end of file
......@@ -3,17 +3,16 @@ import PropTypes from "prop-types"
import { ListItem, ListItemText, Typography, Icon, IconButton, Avatar } from "@material-ui/core/"
import DeleteIcon from "@material-ui/icons/Delete"
const increment = (quantity) => quantity + 1
const decrement = (quantity) => quantity > 1 ? quantity - 1 : 0
/* TODO add function to increment/decrement */
const Item = ({ id, name, quantity, updateItem }) => (
const Item = ({ id, name, quantity /* TODO pass updateItem function */ }) => (
<ListItem>
<ListItemText>
<Typography id="nameText" variant="subheading">
{name}
</Typography>
</ListItemText>
<IconButton id="decrement" onClick={() => updateItem(id, name, decrement(quantity))} aria-label="Decrement">
<IconButton id="decrement" /* TODO add onclick */ aria-label="Decrement">
<Icon color="secondary">arrow_downward</Icon>
</IconButton>
......@@ -23,7 +22,7 @@ const Item = ({ id, name, quantity, updateItem }) => (
</Typography>
</Avatar>
<IconButton id="increment" onClick={() => updateItem(id, name, increment(quantity))} aria-label="Increment">
<IconButton id="increment" /* TODO add onclick */ aria-label="Increment">
<Icon color="secondary">arrow_upward</Icon>
</IconButton>
<IconButton id="delete" aria-label="Delete">
......@@ -35,10 +34,7 @@ const Item = ({ id, name, quantity, updateItem }) => (
Item.propTypes = {
id: PropTypes.string.isRequired,
name: PropTypes.string.isRequired,
quantity: PropTypes.number,
increment: PropTypes.func,
decrement: PropTypes.func,
deleteItem: PropTypes.func
quantity: PropTypes.number
}
export default Item
\ No newline at end of file
......@@ -48,12 +48,7 @@ describe('components', () => {
wrapper.find('#decrement').simulate('click')
expect(mockUpdateFunction.mock.calls.length).toBe(1)
})
it('should call deleteItem', () => {
wrapper.find('#delete').simulate('click')
expect(mockDeleteFunction.mock.calls.length).toBe(1)
})
it('should render the supplied name', () => {
expect(wrapper.find('#nameText').html()).toContain(props.name)
})
......
import { connect } from "react-redux"
import Item from "../../components/Item/Item"
import { updateItem } from "../../actions"
import { createSelector } from "reselect"
const getItem = (state, props) => state.items.find(item => item.id === props.id)
......@@ -15,7 +14,7 @@ const mapStateToProps = (state, props) => ({
})
const mapDispatchToProps = dispatch => ({
updateItem: (id, name, quantity) => dispatch(updateItem(id, name, quantity))
/* TODO map updateItem action */
})
export default connect(
......
......@@ -7,12 +7,10 @@ const INITIAL_STATE = [ {id: "1156", name: "Peanuts", quantity: 4},
const items = (state = INITIAL_STATE, action) => {
switch (action.type) {
case ITEM_UPDATED:
return state.map(item => (
item.id === action.id ? {...item, name: action.name, quantity: action.quantity } : item
));
/* TODO carry out item update */
default:
return state
}
}
}
export default items
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment