Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
inventory-frontend
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Packages
Packages
Container Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
coding-brunch-hh
inventory-frontend
Commits
823b7331
Commit
823b7331
authored
Aug 13, 2018
by
Martin Fahl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
devides actions in multiple files
parent
86133c1e
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
199 additions
and
200 deletions
+199
-200
src/actions/actions.test.js
src/actions/actions.test.js
+0
-105
src/actions/addDialogActions.js
src/actions/addDialogActions.js
+19
-0
src/actions/addDialogActions.test.js
src/actions/addDialogActions.test.js
+36
-0
src/actions/debounced.js
src/actions/debounced.js
+14
-0
src/actions/filterTermActions.js
src/actions/filterTermActions.js
+6
-0
src/actions/filterTermActions.test.js
src/actions/filterTermActions.test.js
+13
-0
src/actions/index.js
src/actions/index.js
+3
-79
src/actions/itemsActions.js
src/actions/itemsActions.js
+44
-0
src/actions/itemsActions.test.js
src/actions/itemsActions.test.js
+48
-0
src/actions/itemsThunkActions.test.js
src/actions/itemsThunkActions.test.js
+16
-16
No files found.
src/actions/actions.test.js
deleted
100644 → 0
View file @
86133c1e
import
*
as
actions
from
'
.
'
import
*
as
types
from
'
../constants/ActionTypes
'
describe
(
'
actions
'
,
()
=>
{
it
(
'
should create an action to add an item locally
'
,
()
=>
{
const
id
=
'
a23
'
const
name
=
'
Coconut
'
const
quantity
=
3
const
expectedAction
=
{
type
:
types
.
ITEM_ADDED
,
id
,
name
,
quantity
}
expect
(
actions
.
itemAdded
(
id
,
name
,
quantity
)).
toEqual
(
expectedAction
)
})
})
describe
(
'
actions
'
,
()
=>
{
it
(
'
should create an action to update the filter
'
,
()
=>
{
const
filterTerm
=
'
Bananas
'
const
expectedAction
=
{
type
:
types
.
UPDATE_FILTER
,
filterTerm
}
expect
(
actions
.
updateFilter
(
filterTerm
)).
toEqual
(
expectedAction
)
})
})
describe
(
'
actions
'
,
()
=>
{
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
)
})
})
describe
(
'
actions
'
,
()
=>
{
it
(
'
should create an action to open the add dialog
'
,
()
=>
{
const
expectedAction
=
{
type
:
types
.
OPEN_ADD_DIALOG
,
}
expect
(
actions
.
openAddDialog
()).
toEqual
(
expectedAction
)
})
})
describe
(
'
actions
'
,
()
=>
{
it
(
'
should create an action to close the add dialog
'
,
()
=>
{
const
expectedAction
=
{
type
:
types
.
CLOSE_ADD_DIALOG
,
}
expect
(
actions
.
closeAddDialog
()).
toEqual
(
expectedAction
)
})
})
describe
(
'
actions
'
,
()
=>
{
it
(
'
should create an action to update the current name field for the add dialog
'
,
()
=>
{
const
name
=
'
Bananarama
'
const
expectedAction
=
{
type
:
types
.
UPDATE_ADD_DIALOG_NAME
,
name
}
expect
(
actions
.
updateAddDialogName
(
name
)).
toEqual
(
expectedAction
)
})
})
describe
(
'
actions
'
,
()
=>
{
it
(
'
should create an action to update the current quantity field for the add dialog
'
,
()
=>
{
const
quantity
=
3452552253523
const
expectedAction
=
{
type
:
types
.
UPDATE_ADD_DIALOG_QUANTITY
,
quantity
}
expect
(
actions
.
updateAddDialogQuantity
(
quantity
)).
toEqual
(
expectedAction
)
})
})
describe
(
'
actions
'
,
()
=>
{
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
)
})
})
describe
(
'
actions
'
,
()
=>
{
it
(
'
should create an action to signal that the items have been updated
'
,
()
=>
{
const
id
=
1
const
name
=
"
Butter
"
const
quantity
=
98
const
expectedAction
=
{
type
:
types
.
ITEM_UPDATED
,
id
,
name
,
quantity
}
expect
(
actions
.
itemUpdated
(
id
,
name
,
quantity
)).
toEqual
(
expectedAction
)
})
})
\ No newline at end of file
src/actions/addDialogActions.js
0 → 100644
View file @
823b7331
import
*
as
types
from
"
../constants/ActionTypes
"
export
const
openAddDialog
=
()
=>
({
type
:
types
.
OPEN_ADD_DIALOG
})
export
const
closeAddDialog
=
()
=>
({
type
:
types
.
CLOSE_ADD_DIALOG
})
export
const
updateAddDialogName
=
(
name
)
=>
({
type
:
types
.
UPDATE_ADD_DIALOG_NAME
,
name
})
export
const
updateAddDialogQuantity
=
(
quantity
)
=>
({
type
:
types
.
UPDATE_ADD_DIALOG_QUANTITY
,
quantity
})
src/actions/addDialogActions.test.js
0 → 100644
View file @
823b7331
import
*
as
actions
from
"
./addDialogActions
"
import
*
as
types
from
"
../constants/ActionTypes
"
describe
(
"
addDialogActions
"
,
()
=>
{
it
(
"
should create an action to open the add dialog
"
,
()
=>
{
const
expectedAction
=
{
type
:
types
.
OPEN_ADD_DIALOG
,
}
expect
(
actions
.
openAddDialog
()).
toEqual
(
expectedAction
)
})
it
(
"
should create an action to close the add dialog
"
,
()
=>
{
const
expectedAction
=
{
type
:
types
.
CLOSE_ADD_DIALOG
,
}
expect
(
actions
.
closeAddDialog
()).
toEqual
(
expectedAction
)
})
it
(
"
should create an action to update the current name field for the add dialog
"
,
()
=>
{
const
name
=
"
Bananarama
"
const
expectedAction
=
{
type
:
types
.
UPDATE_ADD_DIALOG_NAME
,
name
}
expect
(
actions
.
updateAddDialogName
(
name
)).
toEqual
(
expectedAction
)
})
it
(
"
should create an action to update the current quantity field for the add dialog
"
,
()
=>
{
const
quantity
=
3452552253523
const
expectedAction
=
{
type
:
types
.
UPDATE_ADD_DIALOG_QUANTITY
,
quantity
}
expect
(
actions
.
updateAddDialogQuantity
(
quantity
)).
toEqual
(
expectedAction
)
})
})
\ No newline at end of file
src/actions/debounced.js
0 → 100644
View file @
823b7331
const
debounced
=
(
delay
,
fn
)
=>
{
let
timerId
;
return
function
(...
args
)
{
if
(
timerId
)
{
clearTimeout
(
timerId
)
}
timerId
=
setTimeout
(()
=>
{
fn
(...
args
)
timerId
=
null
},
delay
)
}
}
export
default
debounced
\ No newline at end of file
src/actions/filterTermActions.js
0 → 100644
View file @
823b7331
import
*
as
types
from
"
../constants/ActionTypes
"
export
const
updateFilter
=
filterTerm
=>
({
type
:
types
.
UPDATE_FILTER
,
filterTerm
:
filterTerm
})
\ No newline at end of file
src/actions/filterTermActions.test.js
0 → 100644
View file @
823b7331
import
*
as
actions
from
"
./filterTermActions
"
import
*
as
types
from
"
../constants/ActionTypes
"
describe
(
"
filterTermActions
"
,
()
=>
{
it
(
"
should create an action to update the filter
"
,
()
=>
{
const
filterTerm
=
"
Bananas
"
const
expectedAction
=
{
type
:
types
.
UPDATE_FILTER
,
filterTerm
}
expect
(
actions
.
updateFilter
(
filterTerm
)).
toEqual
(
expectedAction
)
})
})
src/actions/index.js
View file @
823b7331
import
Axios
from
"
axios
"
import
*
as
types
from
"
../constants/ActionTypes
"
export
const
itemAdded
=
(
id
,
name
,
quantity
)
=>
({
type
:
types
.
ITEM_ADDED
,
id
,
name
,
quantity
})
export
const
updateFilter
=
filterTerm
=>
({
type
:
types
.
UPDATE_FILTER
,
filterTerm
:
filterTerm
})
export
const
itemDeleted
=
id
=>
({
type
:
types
.
ITEM_DELETED
,
id
})
export
const
itemUpdated
=
(
id
,
name
,
quantity
)
=>
({
type
:
types
.
ITEM_UPDATED
,
id
,
name
,
quantity
})
export
const
openAddDialog
=
()
=>
({
type
:
types
.
OPEN_ADD_DIALOG
})
export
const
closeAddDialog
=
()
=>
({
type
:
types
.
CLOSE_ADD_DIALOG
})
export
const
updateAddDialogName
=
(
name
)
=>
({
type
:
types
.
UPDATE_ADD_DIALOG_NAME
,
name
})
export
const
updateAddDialogQuantity
=
(
quantity
)
=>
({
type
:
types
.
UPDATE_ADD_DIALOG_QUANTITY
,
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
)))
}
export
const
addItem
=
(
name
,
quantity
)
=>
dispatch
=>
{
return
Axios
.
post
(
"
/api/items
"
,
{
name
,
quantity
}).
then
((
response
)
=>
dispatch
(
itemAdded
(
response
.
data
.
id
,
response
.
data
.
name
,
response
.
data
.
quantity
)))
}
export
const
deleteItem
=
(
id
)
=>
dispatch
=>
{
return
Axios
.
delete
(
"
/api/items/
"
+
id
).
then
(
dispatch
(
itemDeleted
(
id
)))
}
export
const
updateItem
=
(
id
,
name
,
quantity
)
=>
dispatch
=>
{
dispatch
(
itemUpdated
(
id
,
name
,
quantity
))
debounced
(
500
,
Axios
.
put
(
"
/api/items/
"
+
id
,
{
id
,
name
,
quantity
}).
catch
(
dispatch
(
getAllItems
)))
}
const
debounced
=
(
delay
,
fn
)
=>
{
let
timerId
;
return
function
(...
args
)
{
if
(
timerId
)
{
clearTimeout
(
timerId
);
}
timerId
=
setTimeout
(()
=>
{
fn
(...
args
);
timerId
=
null
;
},
delay
);
}
}
\ No newline at end of file
export
*
from
"
./addDialogActions
"
export
*
from
"
./filterTermActions
"
export
*
from
"
./itemsActions
"
\ No newline at end of file
src/actions/itemsActions.js
0 → 100644
View file @
823b7331
import
*
as
types
from
"
../constants/ActionTypes
"
import
Axios
from
"
axios
"
import
debounced
from
"
./debounced
"
export
const
itemAdded
=
(
id
,
name
,
quantity
)
=>
({
type
:
types
.
ITEM_ADDED
,
id
,
name
,
quantity
})
export
const
itemDeleted
=
id
=>
({
type
:
types
.
ITEM_DELETED
,
id
})
export
const
itemUpdated
=
(
id
,
name
,
quantity
)
=>
({
type
:
types
.
ITEM_UPDATED
,
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
)))
}
export
const
addItem
=
(
name
,
quantity
)
=>
dispatch
=>
{
return
Axios
.
post
(
"
/api/items
"
,
{
name
,
quantity
}).
then
((
response
)
=>
dispatch
(
itemAdded
(
response
.
data
.
id
,
response
.
data
.
name
,
response
.
data
.
quantity
)))
}
export
const
deleteItem
=
(
id
)
=>
dispatch
=>
{
return
Axios
.
delete
(
"
/api/items/
"
+
id
).
then
(
dispatch
(
itemDeleted
(
id
)))
}
export
const
updateItem
=
(
id
,
name
,
quantity
)
=>
dispatch
=>
{
dispatch
(
itemUpdated
(
id
,
name
,
quantity
))
debounced
(
500
,
Axios
.
put
(
"
/api/items/
"
+
id
,
{
id
,
name
,
quantity
}).
catch
(
dispatch
(
getAllItems
)))
}
\ No newline at end of file
src/actions/itemsActions.test.js
0 → 100644
View file @
823b7331
import
*
as
actions
from
"
./itemsActions
"
import
*
as
types
from
"
../constants/ActionTypes
"
describe
(
"
itemsActions
"
,
()
=>
{
it
(
"
should create an action to add an item locally
"
,
()
=>
{
const
id
=
"
a23
"
const
name
=
"
Coconut
"
const
quantity
=
3
const
expectedAction
=
{
type
:
types
.
ITEM_ADDED
,
id
,
name
,
quantity
}
expect
(
actions
.
itemAdded
(
id
,
name
,
quantity
)).
toEqual
(
expectedAction
)
})
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
}]
const
expectedAction
=
{
type
:
types
.
ITEMS_LOADED
,
items
}
expect
(
actions
.
itemsLoaded
(
items
)).
toEqual
(
expectedAction
)
})
it
(
"
should create an action to signal that the items have been updated
"
,
()
=>
{
const
id
=
1
const
name
=
"
Butter
"
const
quantity
=
98
const
expectedAction
=
{
type
:
types
.
ITEM_UPDATED
,
id
,
name
,
quantity
}
expect
(
actions
.
itemUpdated
(
id
,
name
,
quantity
)).
toEqual
(
expectedAction
)
})
})
\ No newline at end of file
src/actions/
t
hunkActions.test.js
→
src/actions/
itemsT
hunkActions.test.js
View file @
823b7331
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
'
.
'
import
*
as
types
from
'
../constants/ActionTypes
'
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
'
,
()
=>
{
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
}]
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
)
.
onGet
(
"
/api/items
"
).
replyOnce
(
200
,
items
)
const
expectedActions
=
[
{
type
:
types
.
ITEMS_LOADED
,
items
}
...
...
@@ -25,11 +25,11 @@ describe('async actions', () => {
return
expect
(
store
.
getActions
()).
toEqual
(
expectedActions
)
})
it
(
'
creates ITEM_DELETED when deleting an item has been done
'
,
async
()
=>
{
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
)
.
onDelete
(
"
/api/items/
"
+
id
).
replyOnce
(
204
)
const
expectedActions
=
[
{
type
:
types
.
ITEM_DELETED
,
id
}
...
...
@@ -40,10 +40,10 @@ describe('async actions', () => {
return
expect
(
store
.
getActions
()).
toEqual
(
expectedActions
)
})
it
(
'
creates ITEM_ADDED when adding an item has been done
'
,
async
()
=>
{
it
(
"
creates ITEM_ADDED when adding an item has been done
"
,
async
()
=>
{
const
item
=
{
id
:
25
,
name
:
"
Hammer
"
,
quantity
:
10
}
mockAxios
.
onPost
(
'
/api/items
'
).
replyOnce
(
200
,
item
)
.
onPost
(
"
/api/items
"
).
replyOnce
(
200
,
item
)
const
expectedActions
=
[
{
type
:
types
.
ITEM_ADDED
,
...
item
}
...
...
@@ -54,10 +54,10 @@ describe('async actions', () => {
return
expect
(
store
.
getActions
()).
toEqual
(
expectedActions
)
})
it
(
'
creates ITEM_UPDATED when an item has been updated
'
,
async
()
=>
{
it
(
"
creates ITEM_UPDATED when an item has been updated
"
,
async
()
=>
{
const
item
=
{
id
:
25
,
name
:
"
Hammer
"
,
quantity
:
10
}
mockAxios
.
onPut
(
'
/api/items/
'
+
item
.
id
).
replyOnce
(
204
,
item
)
.
onPut
(
"
/api/items/
"
+
item
.
id
).
replyOnce
(
204
,
item
)
const
expectedActions
=
[
{
type
:
types
.
ITEM_UPDATED
,
...
item
}
...
...
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