Commit d0956bc4 authored by Martin Fahl's avatar Martin Fahl

removes getItems from server

parent 31c6b075
......@@ -2,14 +2,6 @@ import * as actions from "../itemsActions"
import * as types from "../../constants/ActionTypes"
describe("itemsActions", () => {
it("should create an action to delete an item locally", () => {
const id = "aaaa-bbb23"
const expectedAction = {
type: types.ITEM_DELETED,
id
}
expect(actions.itemDeleted(id)).toEqual(expectedAction)
})
it("should create an action to signal that the items have been loaded", () => {
const items = [{id: 1, name: "Lemon", quantity: 98},{id: 2, name: "Orange", quantity: 22}]
......
......@@ -23,21 +23,6 @@ describe("async actions", () => {
await store.dispatch(actions.getAllItems())
return expect(store.getActions()).toEqual(expectedActions)
})
})
it("creates ITEM_DELETED when deleting an item has been done", async () => {
const id = 25
const item = { id, name: "Axe", quantity: 5}
mockAxios
.onDelete("/api/items/"+id).replyOnce(204)
const expectedActions = [
{ type: types.ITEM_DELETED, id }
]
const store = mockStore({ items: [item] })
await store.dispatch(actions.deleteItem(id))
return expect(store.getActions()).toEqual(expectedActions)
})
})
\ No newline at end of file
import * as types from "../constants/ActionTypes"
import Axios from "axios"
export const addItem = (id, name, quantity) => ({
type: types.ITEM_ADDED,
......@@ -18,13 +17,4 @@ export const updateItem = (id, name, quantity) => ({
id,
name,
quantity
})
export const itemsLoaded = (items) => ({
type: types.ITEMS_LOADED,
items
})
export const getAllItems = () => dispatch => {
return Axios.get("/api/items").then((response) => dispatch(itemsLoaded(response.data)))
}
\ No newline at end of file
})
\ No newline at end of file
import React, { Component } from 'react'
import { connect } from 'react-redux'
import InventoryList from '../../components/InventoryList/InventoryList'
import { updateFilter, getAllItems, openAddDialog } from '../../actions'
import { updateFilter, openAddDialog } from '../../actions'
import { createSelector } from 'reselect'
class InventoryListContainer extends Component {
componentDidMount() {
this.props.getAllItems();
}
render() {
return (
<InventoryList {...this.props} />
......@@ -36,7 +32,6 @@ const mapStateToProps = state => ({
const mapDispatchToProps = dispatch => ({
updateFilter: event => dispatch(updateFilter(event.target.value)),
getAllItems: () => dispatch(getAllItems()),
openAddDialog: () => dispatch(openAddDialog())
})
......
import React from "react";
import { render } from "react-dom"
import { createStore, applyMiddleware } from "redux"
import thunk from "redux-thunk";
import { createStore } from "redux"
import { Provider } from "react-redux"
import registerServiceWorker from "./registerServiceWorker";
import rootReducer from "./reducers"
import App from "./components/App/App";
import { addItem } from "./actions";
const store = createStore(
rootReducer,
applyMiddleware(thunk)
rootReducer
);
console.log("initial state: ", store.getState());
......@@ -17,6 +16,10 @@ store.subscribe(() => {
console.log(store.getState());
});
store.dispatch(addItem("1156", "Milk", 4));
store.dispatch(addItem("2257", "Chocolate", 1));
store.dispatch(addItem("3358", "Wine", 40));
render(
<Provider store={store}>
<App />
......
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