Commit b397e3bb authored by Martin Fahl's avatar Martin Fahl

refactors reducer tests

parent d7c84a84
......@@ -2,67 +2,51 @@ import reducer from "../addDialog"
import * as types from "../../constants/ActionTypes"
describe("addDialog reducer", () => {
it("should return the initial state", () => {
let defaultState
let testState
beforeEach(() => {
defaultState = { isOpen: false, name: "", quantity: 0 }
testState = { isOpen: true, name: "Test", quantity: 2 }
})
it("should return the initial defaultState", () => {
expect(reducer(undefined, {})).toEqual(
{isOpen: false, name: "", quantity: 0}
defaultState
)
})
it("should handle OPEN_ADD_DIALOG", () => {
expect(
reducer(
{
isOpen: false,
name: "",
quantity: 0
},
{
type: types.OPEN_ADD_DIALOG,
}
reducer(defaultState,
{ type: types.OPEN_ADD_DIALOG }
)
).toEqual(
{
isOpen: true,
name: "",
quantity: 0
...defaultState,
isOpen: true
}
)
expect(
reducer(
{
isOpen: true,
name: "Test",
quantity: 2
},
{
type: types.OPEN_ADD_DIALOG,
}
testState,
{ type: types.OPEN_ADD_DIALOG }
)
).toEqual(
{
isOpen: true,
name: "Test",
quantity: 2
}
)
).toEqual(testState)
expect(
reducer(
{
isOpen: false,
name: "Test",
quantity: 2
...testState,
isOpen: false
},
{
type: types.OPEN_ADD_DIALOG,
}
{ type: types.OPEN_ADD_DIALOG }
)
).toEqual(
{
isOpen: true,
name: "Test",
quantity: 2
...testState,
isOpen: true
}
)
})
......@@ -70,71 +54,47 @@ describe("addDialog reducer", () => {
it("should handle CLOSE_ADD_DIALOG", () => {
expect(
reducer(
{
isOpen: false,
name: "",
quantity: 0
},
{
type: types.CLOSE_ADD_DIALOG,
}
defaultState,
{ type: types.CLOSE_ADD_DIALOG }
)
).toEqual(
{
isOpen: false,
name: "",
quantity: 0
...defaultState,
isOpen: false
}
)
expect(
reducer(
{
isOpen: true,
name: "Test",
quantity: 2
},
{
type: types.CLOSE_ADD_DIALOG,
}
testState,
{ type: types.CLOSE_ADD_DIALOG }
)
).toEqual(
{
isOpen: false,
name: "",
quantity: 0
}
)
).toEqual(defaultState)
})
it("should handle UPDATE_ADD_DIALOG_NAME", () => {
expect(
reducer(
{
isOpen: true,
name: "",
quantity: 0
...defaultState,
isOpen: true
},
{
type: types.UPDATE_ADD_DIALOG_NAME,
name: "Axe"
type: types.UPDATE_ADD_DIALOG_NAME,
name: "Axe"
}
)
).toEqual(
{
...defaultState,
isOpen: true,
name: "Axe",
quantity: 0
name: "Axe"
}
)
expect(
reducer(
{
isOpen: true,
name: "Test",
quantity: 2
},
testState,
{
type: types.UPDATE_ADD_DIALOG_NAME,
name: "Axe"
......@@ -142,9 +102,8 @@ describe("addDialog reducer", () => {
)
).toEqual(
{
isOpen: true,
name: "Axe",
quantity: 2
...testState,
name: "Axe"
}
)
})
......@@ -153,30 +112,25 @@ describe("addDialog reducer", () => {
expect(
reducer(
{
isOpen: true,
name: "",
quantity: 0
...defaultState,
isOpen: true
},
{
type: types.UPDATE_ADD_DIALOG_QUANTITY,
quantity: 25
type: types.UPDATE_ADD_DIALOG_QUANTITY,
quantity: 25
}
)
).toEqual(
{
isOpen: true,
name: "",
...defaultState,
isOpen: true,
quantity: 25
}
)
expect(
reducer(
{
isOpen: true,
name: "Test",
quantity: 2
},
testState,
{
type: types.UPDATE_ADD_DIALOG_QUANTITY,
quantity: 27
......@@ -184,8 +138,7 @@ describe("addDialog reducer", () => {
)
).toEqual(
{
isOpen: true,
name: "Test",
...testState,
quantity: 27
}
)
......
......@@ -12,10 +12,8 @@ describe("filterTerm reducer", () => {
type: types.UPDATE_FILTER,
filterTerm: "Police Car"
})
).toEqual(
"Police Car"
)
).toEqual("Police Car")
expect(
reducer(
"Mac",
......@@ -24,8 +22,6 @@ describe("filterTerm reducer", () => {
filterTerm: "Macbook"
}
)
).toEqual(
"Macbook"
)
).toEqual("Macbook")
})
})
\ No newline at end of file
......@@ -2,6 +2,15 @@ import reducer from "../items"
import * as types from "../../constants/ActionTypes"
describe("items reducer", () => {
let item1
let item2
let item3
beforeEach(() => {
item1 = {id: "5", name: "Seat", quantity: 5}
item2 = {id: "dasasd", name: "Stool", quantity: 1000}
item3 = {id: "ab25", name: "Couch", quantity: 3}
})
it("should return the initial state", () => {
expect(reducer(undefined, {})).toEqual([])
})
......@@ -10,19 +19,19 @@ describe("items reducer", () => {
expect(
reducer([], {
type: types.ITEMS_LOADED,
items: [{id: "5", name: "Seat", quantity: 5}, {id: "dasasd", name: "Stool", quantity: 1000}]
items: [item1, item2]
})
).toEqual(
[{id: "5", name: "Seat", quantity: 5}, {id: "dasasd", name: "Stool", quantity: 1000}]
[item1, item2]
)
expect(
reducer([{id: "ab25", name: "Couch", quantity: 3}], {
reducer([item3], {
type: types.ITEMS_LOADED,
items: [{id: "5", name: "Seat", quantity: 5}, {id: "dasasd", name: "Stool", quantity: 1000}]
items: [item1, item2]
})
).toEqual(
[{id: "5", name: "Seat", quantity: 5}, {id: "dasasd", name: "Stool", quantity: 1000}]
[item1, item2]
)
})
......@@ -30,23 +39,19 @@ describe("items reducer", () => {
expect(
reducer([], {
type: types.ITEM_ADDED,
id: "5",
name: "Seat",
quantity: 5
...item1
})
).toEqual(
[{id: "5", name: "Seat", quantity: 5}]
[item1]
)
expect(
reducer([{id: "ab25", name: "Couch", quantity: 3}], {
reducer([item1], {
type: types.ITEM_ADDED,
id: "5",
name: "Seat",
quantity: 5
...item2
})
).toEqual(
[{id: "ab25", name: "Couch", quantity: 3}, {id: "5", name: "Seat", quantity: 5}]
[item1, item2]
)
})
......@@ -61,35 +66,32 @@ describe("items reducer", () => {
)
expect(
reducer([{id: "ab25", name: "Couch", quantity: 3},{id: "5", name: "Seat", quantity: 5}], {
reducer([item1, item2], {
type: types.ITEM_DELETED,
id: "5",
id: item2.id,
})
).toEqual(
[{id: "ab25", name: "Couch", quantity: 3}]
[item1]
)
})
it("should handle ITEM_UPDATED", () => {
expect(
reducer([], {
type: types.ITEM_UPDATED,
id: "5",
name: "Stool",
quantity: 6
...item1
})
).toEqual(
[]
)
expect(
reducer([{id: "ab25", name: "Couch", quantity: 3},{id: "5", name: "Seat", quantity: 5}], {
reducer([item1, item3], {
type: types.ITEM_UPDATED,
id: "5",
name: "Stool",
...item3,
quantity: 6
})
).toEqual(
[{id: "ab25", name: "Couch", quantity: 3}, { id: "5", name: "Stool", quantity: 6}]
[item1, {...item3, 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