Commit fbdee7c8 authored by Martin Fahl's avatar Martin Fahl

adds test for items reducer

parent dd0a470a
import reducer from './items'
import * as types from '../constants/ActionTypes'
describe('items reducer', () => {
it('should return the initial state', () => {
expect(reducer(undefined, {})).toEqual([])
})
it('should handle ITEMS_LOADED', () => {
expect(
reducer([], {
type: types.ITEMS_LOADED,
items: [{id: "5", name: "Seat", quantity: 5}, {id: "dasasd", name: "Stool", quantity: 1000}]
})
).toEqual(
[{id: "5", name: "Seat", quantity: 5}, {id: "dasasd", name: "Stool", quantity: 1000}]
)
expect(
reducer([{id: "ab25", name: "Couch", quantity: 3}], {
type: types.ITEMS_LOADED,
items: [{id: "5", name: "Seat", quantity: 5}, {id: "dasasd", name: "Stool", quantity: 1000}]
})
).toEqual(
[{id: "5", name: "Seat", quantity: 5}, {id: "dasasd", name: "Stool", quantity: 1000}]
)
})
it('should handle ITEM_ADDED', () => {
expect(
reducer([], {
type: types.ITEM_ADDED,
id: "5",
name: "Seat",
quantity: 5
})
).toEqual(
[{id: "5", name: "Seat", quantity: 5}]
)
expect(
reducer([{id: "ab25", name: "Couch", quantity: 3}], {
type: types.ITEM_ADDED,
id: "5",
name: "Seat",
quantity: 5
})
).toEqual(
[{id: "ab25", name: "Couch", quantity: 3}, {id: "5", name: "Seat", quantity: 5}]
)
})
it('should handle ITEM_DELETED', () => {
expect(
reducer([], {
type: types.ITEM_DELETED,
id: "5"
})
).toEqual(
[]
)
expect(
reducer([{id: "ab25", name: "Couch", quantity: 3},{id: "5", name: "Seat", quantity: 5}], {
type: types.ITEM_DELETED,
id: "5",
})
).toEqual(
[{id: "ab25", name: "Couch", quantity: 3}]
)
})
it('should handle ITEM_UPDATED', () => {
expect(
reducer([], {
type: types.ITEM_UPDATED,
id: "5",
name: "Stool",
quantity: 6
})
).toEqual(
[]
)
expect(
reducer([{id: "ab25", name: "Couch", quantity: 3},{id: "5", name: "Seat", quantity: 5}], {
type: types.ITEM_UPDATED,
id: "5",
name: "Stool",
quantity: 6
})
).toEqual(
[{id: "ab25", name: "Couch", quantity: 3}, { id: "5", name: "Stool", quantity: 6}]
)
})
})
\ 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