-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from EmmanuelDemey/master
Update React + Add unit test
- Loading branch information
Showing
8 changed files
with
180 additions
and
75 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,4 +32,6 @@ yarn-error.log* | |
/swagger | ||
.cache | ||
cypress/videos | ||
cypress/screenshots | ||
cypress/screenshots | ||
|
||
coverage |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
38 changes: 38 additions & 0 deletions
38
src/js/actions/classifications/correspondences/association.spec.js
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,38 @@ | ||
import getCorrespondenceAssociation from './association'; | ||
import * as A from 'js/actions/constants'; | ||
import api from 'js/remote-api/classifications-api'; | ||
|
||
const dispatch = jest.fn(); | ||
jest.mock('js/remote-api/classifications-api'); | ||
|
||
describe('Associations actions', () => { | ||
it('should call dispatch LOAD_CLASSIFICATION_CORRESPONDENCE_ASSOCIATIONS_SUCCESS action with the right data', async () => { | ||
api.getCorrespondenceAssociation = function() { | ||
return Promise.resolve('results'); | ||
}; | ||
await getCorrespondenceAssociation(1, 2)(dispatch); | ||
expect(dispatch).toHaveBeenCalledWith({ | ||
type: A.LOAD_CLASSIFICATION_CORRESPONDENCE_ASSOCIATION, | ||
payload: { correspondenceId: 1, associationId: 2 }, | ||
}); | ||
expect(dispatch).toHaveBeenLastCalledWith({ | ||
type: A.LOAD_CLASSIFICATION_CORRESPONDENCE_ASSOCIATION_SUCCESS, | ||
payload: { correspondenceId: 1, associationId: 2, results: 'results' }, | ||
}); | ||
}); | ||
|
||
it('should call dispatch LOAD_CLASSIFICATION_CORRESPONDENCE_ASSOCIATIONS_FAILURE action with an error object', async () => { | ||
api.getCorrespondenceAssociation = function() { | ||
return Promise.reject('error'); | ||
}; | ||
await getCorrespondenceAssociation(1, 2)(dispatch); | ||
expect(dispatch).toHaveBeenCalledWith({ | ||
type: A.LOAD_CLASSIFICATION_CORRESPONDENCE_ASSOCIATION, | ||
payload: { correspondenceId: 1, associationId: 2 }, | ||
}); | ||
expect(dispatch).toHaveBeenLastCalledWith({ | ||
type: A.LOAD_CLASSIFICATION_CORRESPONDENCE_ASSOCIATION_FAILURE, | ||
payload: { err: 'error', correspondenceId: 1, associationId: 2 }, | ||
}); | ||
}); | ||
}); |
38 changes: 38 additions & 0 deletions
38
src/js/actions/classifications/correspondences/associations.spec.js
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,38 @@ | ||
import getCorrespondenceAssociations from './associations'; | ||
import * as A from 'js/actions/constants'; | ||
import api from 'js/remote-api/classifications-api'; | ||
|
||
const dispatch = jest.fn(); | ||
jest.mock('js/remote-api/classifications-api'); | ||
|
||
describe('Associations actions', () => { | ||
it('should call dispatch LOAD_CLASSIFICATION_CORRESPONDENCE_ASSOCIATIONS_SUCCESS action with the right data', async () => { | ||
api.getCorrespondenceAssociations = function() { | ||
return Promise.resolve('results'); | ||
}; | ||
await getCorrespondenceAssociations(1)(dispatch); | ||
expect(dispatch).toHaveBeenCalledWith({ | ||
type: A.LOAD_CLASSIFICATION_CORRESPONDENCE_ASSOCIATIONS, | ||
payload: { id: 1 }, | ||
}); | ||
expect(dispatch).toHaveBeenLastCalledWith({ | ||
type: A.LOAD_CLASSIFICATION_CORRESPONDENCE_ASSOCIATIONS_SUCCESS, | ||
payload: { id: 1, results: 'results' }, | ||
}); | ||
}); | ||
|
||
it('should call dispatch LOAD_CLASSIFICATION_CORRESPONDENCE_ASSOCIATIONS_FAILURE action with an error object', async () => { | ||
api.getCorrespondenceAssociations = function() { | ||
return Promise.reject('error'); | ||
}; | ||
await getCorrespondenceAssociations(1)(dispatch); | ||
expect(dispatch).toHaveBeenCalledWith({ | ||
type: A.LOAD_CLASSIFICATION_CORRESPONDENCE_ASSOCIATIONS, | ||
payload: { id: 1 }, | ||
}); | ||
expect(dispatch).toHaveBeenLastCalledWith({ | ||
type: A.LOAD_CLASSIFICATION_CORRESPONDENCE_ASSOCIATIONS_FAILURE, | ||
payload: { err: 'error', id: 1 }, | ||
}); | ||
}); | ||
}); |
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