-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement reducers for article ReactionIcons
- Create reducer file - Add initial state - Update state with database response - Update view(Component) with new data
- Loading branch information
ibrahimalausa
committed
Mar 2, 2019
1 parent
4a19285
commit 1ae66d1
Showing
7 changed files
with
88 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import actionTypes from '../actions/articleReactionsAction/actionTypes'; | ||
import initialState from './initialState'; | ||
|
||
const { ARTICLE_REACTION_SUCCESS } = actionTypes; | ||
|
||
const { articleReaction } = initialState; | ||
|
||
export default (state = articleReaction, action) => { | ||
switch (action.type) { | ||
case ARTICLE_REACTION_SUCCESS: | ||
return { | ||
success: true, | ||
newReaction: action.payload | ||
}; | ||
default: | ||
return state; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import actionTypes from '../../actions/articleReactionsAction/actionTypes'; | ||
import initialState from '../initialState'; | ||
import articleReactionsReducer from '../articleReactionsReducer'; | ||
|
||
const { ARTICLE_REACTION_SUCCESS } = actionTypes; | ||
|
||
describe(' article reaction reducer', () => { | ||
it('should return the initial state', () => { | ||
expect(articleReactionsReducer(undefined, {})).toEqual(initialState.articleReaction); | ||
}); | ||
|
||
it('should update state when the start action is dispatched', () => { | ||
const action = { | ||
payload: 'dislike' | ||
}; | ||
expect( | ||
articleReactionsReducer(initialState.articleReaction, { | ||
type: ARTICLE_REACTION_SUCCESS, | ||
payload: 'dislike' | ||
}) | ||
).toEqual( | ||
(initialState, | ||
{ | ||
success: true, | ||
newReaction: action.payload | ||
}) | ||
); | ||
}); | ||
}); |