Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
inventory-frontend
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Jira
Jira
Operations
Operations
Incidents
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
coding-brunch-hh
inventory-frontend
Commits
88603a69
Commit
88603a69
authored
Aug 16, 2018
by
Martin Fahl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
removes code for adding items
parent
d0956bc4
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
10 additions
and
126 deletions
+10
-126
src/actions/__tests__/itemsActions.test.js
src/actions/__tests__/itemsActions.test.js
+0
-8
src/actions/__tests__/itemsThunkActions.test.js
src/actions/__tests__/itemsThunkActions.test.js
+0
-28
src/actions/itemsActions.js
src/actions/itemsActions.js
+0
-7
src/container/AddDialogContainer/AddDialogContainer.js
src/container/AddDialogContainer/AddDialogContainer.js
+1
-6
src/index.js
src/index.js
+0
-5
src/reducers/__tests__/items.test.js
src/reducers/__tests__/items.test.js
+4
-60
src/reducers/items.js
src/reducers/items.js
+5
-12
No files found.
src/actions/__tests__/itemsActions.test.js
View file @
88603a69
...
...
@@ -3,13 +3,5 @@ import * as types from "../../constants/ActionTypes"
describe
(
"
itemsActions
"
,
()
=>
{
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
}]
const
expectedAction
=
{
type
:
types
.
ITEMS_LOADED
,
items
}
expect
(
actions
.
itemsLoaded
(
items
)).
toEqual
(
expectedAction
)
})
})
\ No newline at end of file
src/actions/__tests__/itemsThunkActions.test.js
deleted
100644 → 0
View file @
d0956bc4
import
configureMockStore
from
"
redux-mock-store
"
import
thunk
from
"
redux-thunk
"
import
axios
from
"
axios
"
;
import
MockAdapter
from
"
axios-mock-adapter
"
;
import
*
as
actions
from
"
../itemsActions
"
import
*
as
types
from
"
../../constants/ActionTypes
"
const
middlewares
=
[
thunk
]
const
mockStore
=
configureMockStore
(
middlewares
)
const
mockAxios
=
new
MockAdapter
(
axios
)
describe
(
"
async actions
"
,
()
=>
{
it
(
"
creates ITEMS_LOADED when fetching items has been done
"
,
async
()
=>
{
const
items
=
[{
id
:
1
,
name
:
"
Football
"
,
quantity
:
2
},{
id
:
2
,
name
:
"
Headphones
"
,
quantity
:
3
}]
mockAxios
.
onGet
(
"
/api/items
"
).
replyOnce
(
200
,
items
)
const
expectedActions
=
[
{
type
:
types
.
ITEMS_LOADED
,
items
}
]
const
store
=
mockStore
({
items
:
[]
})
await
store
.
dispatch
(
actions
.
getAllItems
())
return
expect
(
store
.
getActions
()).
toEqual
(
expectedActions
)
})
})
\ No newline at end of file
src/actions/itemsActions.js
View file @
88603a69
import
*
as
types
from
"
../constants/ActionTypes
"
export
const
addItem
=
(
id
,
name
,
quantity
)
=>
({
type
:
types
.
ITEM_ADDED
,
id
,
name
,
quantity
})
export
const
deleteItem
=
id
=>
({
type
:
types
.
ITEM_DELETED
,
id
...
...
src/container/AddDialogContainer/AddDialogContainer.js
View file @
88603a69
import
{
connect
}
from
'
react-redux
'
import
AddDialog
from
'
../../components/AddDialog/AddDialog
'
import
{
createSelector
}
from
'
reselect
'
import
{
closeAddDialog
,
updateAddDialogName
,
updateAddDialogQuantity
,
addItem
}
from
'
../../actions
'
import
{
closeAddDialog
,
updateAddDialogName
,
updateAddDialogQuantity
}
from
'
../../actions
'
const
getAddDialog
=
state
=>
state
.
addDialog
;
...
...
@@ -26,14 +26,9 @@ const getNewQuantity = createSelector(
}
)
const
genId
=
()
=>
{
return
String
(
Math
.
floor
(
Math
.
random
()
*
10000
))
}
const
handleAdd
=
(
name
,
quantity
,
dispatch
)
=>
{
if
(
name
!==
""
)
{
dispatch
(
closeAddDialog
());
dispatch
(
addItem
(
genId
(),
name
,
quantity
))
}
}
...
...
src/index.js
View file @
88603a69
...
...
@@ -5,7 +5,6 @@ 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
...
...
@@ -16,10 +15,6 @@ 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
/>
...
...
src/reducers/__tests__/items.test.js
View file @
88603a69
...
...
@@ -12,27 +12,10 @@ describe("items reducer", () => {
item3
=
{
id
:
"
ab25
"
,
name
:
"
Couch
"
,
quantity
:
3
}
})
it
(
"
should return the initial state
"
,
()
=>
{
expect
(
reducer
(
undefined
,
{})).
toEqual
([])
})
it
(
"
should handle ITEMS_LOADED
"
,
()
=>
{
expect
(
reducer
([],
{
type
:
types
.
ITEMS_LOADED
,
items
:
[
item1
,
item2
]
})
).
toEqual
(
[
item1
,
item2
]
)
expect
(
reducer
([
item3
],
{
type
:
types
.
ITEMS_LOADED
,
items
:
[
item1
,
item2
]
})
).
toEqual
(
[
item1
,
item2
]
)
expect
(
reducer
(
undefined
,
{})).
toEqual
([
{
id
:
"
1156
"
,
name
:
"
Peanuts
"
,
quantity
:
4
},
{
id
:
"
2257
"
,
name
:
"
Chocolate
"
,
quantity
:
1
},
{
id
:
"
3358
"
,
name
:
"
Wine
"
,
quantity
:
40
}
])
})
it
(
"
should handle ITEM_ADDED
"
,
()
=>
{
...
...
@@ -55,43 +38,4 @@ describe("items reducer", () => {
)
})
it
(
"
should handle ITEM_DELETED
"
,
()
=>
{
expect
(
reducer
([],
{
type
:
types
.
ITEM_DELETED
,
id
:
"
5
"
})
).
toEqual
(
[]
)
expect
(
reducer
([
item1
,
item2
],
{
type
:
types
.
ITEM_DELETED
,
id
:
item2
.
id
,
})
).
toEqual
(
[
item1
]
)
})
it
(
"
should handle ITEM_UPDATED
"
,
()
=>
{
expect
(
reducer
([],
{
type
:
types
.
ITEM_UPDATED
,
...
item1
})
).
toEqual
(
[]
)
expect
(
reducer
([
item1
,
item3
],
{
type
:
types
.
ITEM_UPDATED
,
...
item3
,
quantity
:
6
})
).
toEqual
(
[
item1
,
{...
item3
,
quantity
:
6
}]
)
})
})
\ No newline at end of file
src/reducers/items.js
View file @
88603a69
import
{
ITEM_DELETED
,
ITEMS_LOADED
,
ITEM_ADDED
,
ITEM_UPDATED
}
from
"
../constants/ActionTypes
"
;
const
items
=
(
state
=
[],
action
)
=>
{
const
INITIAL_STATE
=
[
{
id
:
"
1156
"
,
name
:
"
Peanuts
"
,
quantity
:
4
},
{
id
:
"
2257
"
,
name
:
"
Chocolate
"
,
quantity
:
1
},
{
id
:
"
3358
"
,
name
:
"
Wine
"
,
quantity
:
40
}
]
const
items
=
(
state
=
INITIAL_STATE
,
action
)
=>
{
switch
(
action
.
type
)
{
case
ITEMS_LOADED
:
return
action
.
items
case
ITEM_ADDED
:
return
[
...
state
,
{
id
:
action
.
id
,
name
:
action
.
name
,
quantity
:
action
.
quantity
}
]
case
ITEM_DELETED
:
return
state
.
filter
(
item
=>
(
item
.
id
!==
action
.
id
))
case
ITEM_UPDATED
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment