-
Notifications
You must be signed in to change notification settings - Fork 683
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds unit tests to Catalog actions (#875)
* Adds unit tests to Catalog actions. Minor scroll refactor. * Reverts ~~ change and adds comment instead.
- Loading branch information
1 parent
4a042e7
commit e4568a8
Showing
5 changed files
with
255 additions
and
1 deletion.
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
154 changes: 154 additions & 0 deletions
154
packages/venia-concept/src/actions/catalog/__tests__/actions.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,154 @@ | ||
import actions from '../actions'; | ||
|
||
const MOCK_PAYLOAD = 'Unit Test Payload'; | ||
const ERROR = new Error('Unit Test'); | ||
|
||
describe('getAllCategories', () => { | ||
const PREFIX = 'CATALOG/GET_ALL_CATEGORIES'; | ||
|
||
describe('REQUEST', () => { | ||
const EXPECTED_NAME = `${PREFIX}/REQUEST`; | ||
|
||
test('it returns the proper action type', () => { | ||
expect(actions.getAllCategories.request.toString()).toBe( | ||
EXPECTED_NAME | ||
); | ||
}); | ||
|
||
test('it returns a proper action object', () => { | ||
expect(actions.getAllCategories.request(MOCK_PAYLOAD)).toEqual({ | ||
type: EXPECTED_NAME, | ||
payload: MOCK_PAYLOAD | ||
}); | ||
|
||
expect(actions.getAllCategories.request(ERROR)).toEqual({ | ||
type: EXPECTED_NAME, | ||
payload: ERROR, | ||
error: true | ||
}); | ||
}); | ||
}); | ||
|
||
describe('RECEIVE', () => { | ||
const EXPECTED_NAME = `${PREFIX}/RECEIVE`; | ||
|
||
test('it returns the proper action type', () => { | ||
expect(actions.getAllCategories.receive.toString()).toBe( | ||
EXPECTED_NAME | ||
); | ||
}); | ||
|
||
test('it returns a proper action object', () => { | ||
expect(actions.getAllCategories.receive(MOCK_PAYLOAD)).toEqual({ | ||
type: EXPECTED_NAME, | ||
payload: MOCK_PAYLOAD | ||
}); | ||
|
||
expect(actions.getAllCategories.receive(ERROR)).toEqual({ | ||
type: EXPECTED_NAME, | ||
payload: ERROR, | ||
error: true | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('setCurrentPage', () => { | ||
const PREFIX = 'CATALOG/SET_CURRENT_PAGE'; | ||
|
||
describe('REQUEST', () => { | ||
const EXPECTED_NAME = `${PREFIX}/REQUEST`; | ||
|
||
test('it returns the proper action type', () => { | ||
expect(actions.setCurrentPage.request.toString()).toBe( | ||
EXPECTED_NAME | ||
); | ||
}); | ||
|
||
test('it returns a proper action object', () => { | ||
expect(actions.setCurrentPage.request(MOCK_PAYLOAD)).toEqual({ | ||
type: EXPECTED_NAME, | ||
payload: MOCK_PAYLOAD | ||
}); | ||
|
||
expect(actions.setCurrentPage.request(ERROR)).toEqual({ | ||
type: EXPECTED_NAME, | ||
payload: ERROR, | ||
error: true | ||
}); | ||
}); | ||
}); | ||
|
||
describe('RECEIVE', () => { | ||
const EXPECTED_NAME = `${PREFIX}/RECEIVE`; | ||
|
||
test('it returns the proper action type', () => { | ||
expect(actions.setCurrentPage.receive.toString()).toBe( | ||
EXPECTED_NAME | ||
); | ||
}); | ||
|
||
test('it returns a proper action object', () => { | ||
expect(actions.setCurrentPage.receive(MOCK_PAYLOAD)).toEqual({ | ||
type: EXPECTED_NAME, | ||
payload: MOCK_PAYLOAD | ||
}); | ||
|
||
expect(actions.setCurrentPage.receive(ERROR)).toEqual({ | ||
type: EXPECTED_NAME, | ||
payload: ERROR, | ||
error: true | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('setPrevPageTotal', () => { | ||
const PREFIX = 'CATALOG/SET_PREV_PAGE_TOTAL'; | ||
|
||
describe('REQUEST', () => { | ||
const EXPECTED_NAME = `${PREFIX}/REQUEST`; | ||
|
||
test('it returns the proper action type', () => { | ||
expect(actions.setPrevPageTotal.request.toString()).toBe( | ||
EXPECTED_NAME | ||
); | ||
}); | ||
|
||
test('it returns a proper action object', () => { | ||
expect(actions.setPrevPageTotal.request(MOCK_PAYLOAD)).toEqual({ | ||
type: EXPECTED_NAME, | ||
payload: MOCK_PAYLOAD | ||
}); | ||
|
||
expect(actions.setPrevPageTotal.request(ERROR)).toEqual({ | ||
type: EXPECTED_NAME, | ||
payload: ERROR, | ||
error: true | ||
}); | ||
}); | ||
}); | ||
|
||
describe('RECEIVE', () => { | ||
const EXPECTED_NAME = `${PREFIX}/RECEIVE`; | ||
|
||
test('it returns the proper action type', () => { | ||
expect(actions.setPrevPageTotal.receive.toString()).toBe( | ||
EXPECTED_NAME | ||
); | ||
}); | ||
|
||
test('it returns a proper action object', () => { | ||
expect(actions.setPrevPageTotal.receive(MOCK_PAYLOAD)).toEqual({ | ||
type: EXPECTED_NAME, | ||
payload: MOCK_PAYLOAD | ||
}); | ||
|
||
expect(actions.setPrevPageTotal.receive(ERROR)).toEqual({ | ||
type: EXPECTED_NAME, | ||
payload: ERROR, | ||
error: true | ||
}); | ||
}); | ||
}); | ||
}); |
90 changes: 90 additions & 0 deletions
90
packages/venia-concept/src/actions/catalog/__tests__/asyncActions.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,90 @@ | ||
import { dispatch, getState } from 'src/store'; | ||
import actions from '../actions'; | ||
import mockData from '../mockData'; | ||
import { | ||
getAllCategories, | ||
setCurrentPage, | ||
setPrevPageTotal | ||
} from '../asyncActions'; | ||
|
||
jest.mock('src/store'); | ||
|
||
const thunkArgs = [dispatch, getState]; | ||
|
||
afterEach(() => { | ||
dispatch.mockClear(); | ||
}); | ||
|
||
describe('getAllCategories', () => { | ||
test('it returns a thunk', () => { | ||
expect(getAllCategories()).toBeInstanceOf(Function); | ||
}); | ||
|
||
test('its thunk returns undefined', async () => { | ||
const result = await getAllCategories()(...thunkArgs); | ||
|
||
expect(result).toBeUndefined(); | ||
}); | ||
|
||
test('its thunk dispatches actions', async () => { | ||
await getAllCategories()(...thunkArgs); | ||
|
||
expect(dispatch).toHaveBeenCalledTimes(2); | ||
expect(dispatch).toHaveBeenNthCalledWith( | ||
1, | ||
actions.getAllCategories.request() | ||
); | ||
expect(dispatch).toHaveBeenNthCalledWith( | ||
2, | ||
actions.getAllCategories.receive(mockData) | ||
); | ||
}); | ||
}); | ||
|
||
describe('setCurrentPage', () => { | ||
const PAYLOAD = 2; | ||
|
||
test('it returns a thunk', () => { | ||
expect(setCurrentPage(PAYLOAD)).toBeInstanceOf(Function); | ||
}); | ||
|
||
test('its thunk returns undefined', async () => { | ||
const result = await setCurrentPage(PAYLOAD)(...thunkArgs); | ||
|
||
expect(result).toBeUndefined(); | ||
}); | ||
|
||
test('its thunk dispatches actions', async () => { | ||
await setCurrentPage(PAYLOAD)(...thunkArgs); | ||
|
||
expect(dispatch).toHaveBeenCalledTimes(1); | ||
expect(dispatch).toHaveBeenNthCalledWith( | ||
1, | ||
actions.setCurrentPage.receive(PAYLOAD) | ||
); | ||
}); | ||
}); | ||
|
||
describe('setPrevPageTotal', () => { | ||
const PAYLOAD = 10; | ||
|
||
test('it returns a thunk', () => { | ||
expect(setPrevPageTotal(PAYLOAD)).toBeInstanceOf(Function); | ||
}); | ||
|
||
test('its thunk returns undefined', async () => { | ||
const result = await setPrevPageTotal(PAYLOAD)(...thunkArgs); | ||
|
||
expect(result).toBeUndefined(); | ||
}); | ||
|
||
test('its thunk dispatches actions', async () => { | ||
await setPrevPageTotal(PAYLOAD)(...thunkArgs); | ||
|
||
expect(dispatch).toHaveBeenCalledTimes(1); | ||
expect(dispatch).toHaveBeenNthCalledWith( | ||
1, | ||
actions.setPrevPageTotal.receive(PAYLOAD) | ||
); | ||
}); | ||
}); |
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
e4568a8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully aliased the URL https://magento-venia-uzktqcapmc.now.sh to the following aliases.