-
Notifications
You must be signed in to change notification settings - Fork 685
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
35 changed files
with
1,106 additions
and
189 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
...ncept/src/__mocks__/@magento/peregrine.js → ...a-concept/__mocks__/@magento/peregrine.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
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,7 @@ | ||
const initialState = {}; | ||
|
||
export const addReducer = jest.fn(); | ||
export const dispatch = jest.fn(); | ||
export const getState = jest.fn(() => initialState); | ||
|
||
export default { addReducer, dispatch, getState }; |
This file was deleted.
Oops, something went wrong.
20 changes: 20 additions & 0 deletions
20
packages/venia-concept/src/actions/app/__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,20 @@ | ||
import actions from '../actions'; | ||
|
||
const payload = 'FOO'; | ||
const error = new Error('BAR'); | ||
|
||
test('toggleDrawer.toString() returns the proper action type', () => { | ||
expect(actions.toggleDrawer.toString()).toBe('APP/TOGGLE_DRAWER'); | ||
}); | ||
|
||
test('toggleDrawer() returns a proper action object', () => { | ||
expect(actions.toggleDrawer(payload)).toEqual({ | ||
type: 'APP/TOGGLE_DRAWER', | ||
payload | ||
}); | ||
expect(actions.toggleDrawer(error)).toEqual({ | ||
type: 'APP/TOGGLE_DRAWER', | ||
payload: error, | ||
error: true | ||
}); | ||
}); |
47 changes: 47 additions & 0 deletions
47
packages/venia-concept/src/actions/app/__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,47 @@ | ||
import { dispatch, getState } from 'src/store'; | ||
import actions from '../actions'; | ||
import { closeDrawer, toggleDrawer } from '../asyncActions'; | ||
|
||
jest.mock('src/store'); | ||
|
||
const thunkArgs = [dispatch, getState]; | ||
|
||
afterEach(() => { | ||
dispatch.mockClear(); | ||
}); | ||
|
||
test('toggleDrawer() to return a thunk', () => { | ||
expect(toggleDrawer()).toBeInstanceOf(Function); | ||
}); | ||
|
||
test('toggleDrawer thunk returns undefined', async () => { | ||
const payload = 'FOO'; | ||
const result = await toggleDrawer(payload)(...thunkArgs); | ||
|
||
expect(result).toBeUndefined(); | ||
}); | ||
|
||
test('toggleDrawer thunk dispatches actions', async () => { | ||
const payload = 'FOO'; | ||
await toggleDrawer(payload)(...thunkArgs); | ||
|
||
expect(dispatch).toHaveBeenCalledWith(actions.toggleDrawer(payload)); | ||
expect(dispatch).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
test('closeDrawer() to return a thunk ', () => { | ||
expect(closeDrawer()).toBeInstanceOf(Function); | ||
}); | ||
|
||
test('closeDrawer thunk returns undefined', async () => { | ||
const result = await closeDrawer()(...thunkArgs); | ||
|
||
expect(result).toBeUndefined(); | ||
}); | ||
|
||
test('closeDrawer thunk dispatches actions', async () => { | ||
await closeDrawer()(...thunkArgs); | ||
|
||
expect(dispatch).toHaveBeenCalledWith(actions.toggleDrawer(null)); | ||
expect(dispatch).toHaveBeenCalledTimes(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { createActions } from 'redux-actions'; | ||
|
||
const prefix = 'APP'; | ||
const actionTypes = ['TOGGLE_DRAWER']; | ||
|
||
export default createActions(...actionTypes, { prefix }); |
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,7 @@ | ||
import actions from './actions'; | ||
|
||
export const toggleDrawer = name => async dispatch => | ||
dispatch(actions.toggleDrawer(name)); | ||
|
||
export const closeDrawer = () => async dispatch => | ||
dispatch(actions.toggleDrawer(null)); |
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,2 @@ | ||
export { default } from './actions'; | ||
export * from './asyncActions'; |
93 changes: 93 additions & 0 deletions
93
packages/venia-concept/src/actions/cart/__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,93 @@ | ||
import actions from '../actions'; | ||
|
||
const payload = 'PAYLOAD'; | ||
const error = new Error('ERROR'); | ||
|
||
test('addItem.request.toString() returns the proper action type', () => { | ||
expect(actions.addItem.request.toString()).toBe('CART/ADD_ITEM/REQUEST'); | ||
}); | ||
|
||
test('addItem.request() returns a proper action object', () => { | ||
expect(actions.addItem.request(payload)).toEqual({ | ||
type: 'CART/ADD_ITEM/REQUEST', | ||
payload | ||
}); | ||
}); | ||
|
||
test('addItem.receive.toString() returns the proper action type', () => { | ||
expect(actions.addItem.receive.toString()).toBe('CART/ADD_ITEM/RECEIVE'); | ||
}); | ||
|
||
test('addItem.receive() returns a proper action object', () => { | ||
expect(actions.addItem.receive(payload)).toEqual({ | ||
type: 'CART/ADD_ITEM/RECEIVE', | ||
payload | ||
}); | ||
expect(actions.addItem.receive(error)).toEqual({ | ||
type: 'CART/ADD_ITEM/RECEIVE', | ||
payload: error, | ||
error: true | ||
}); | ||
}); | ||
|
||
test('getGuestCart.request.toString() returns the proper action type', () => { | ||
expect(actions.getGuestCart.request.toString()).toBe( | ||
'CART/GET_GUEST_CART/REQUEST' | ||
); | ||
}); | ||
|
||
test('getGuestCart.request() returns a proper action object', () => { | ||
expect(actions.getGuestCart.request(payload)).toEqual({ | ||
type: 'CART/GET_GUEST_CART/REQUEST', | ||
payload | ||
}); | ||
}); | ||
|
||
test('getGuestCart.receive.toString() returns the proper action type', () => { | ||
expect(actions.getGuestCart.receive.toString()).toBe( | ||
'CART/GET_GUEST_CART/RECEIVE' | ||
); | ||
}); | ||
|
||
test('getGuestCart.receive() returns a proper action object', () => { | ||
expect(actions.getGuestCart.receive(payload)).toEqual({ | ||
type: 'CART/GET_GUEST_CART/RECEIVE', | ||
payload | ||
}); | ||
expect(actions.getGuestCart.receive(error)).toEqual({ | ||
type: 'CART/GET_GUEST_CART/RECEIVE', | ||
payload: error, | ||
error: true | ||
}); | ||
}); | ||
|
||
test('getDetails.request.toString() returns the proper action type', () => { | ||
expect(actions.getDetails.request.toString()).toBe( | ||
'CART/GET_DETAILS/REQUEST' | ||
); | ||
}); | ||
|
||
test('getDetails.request() returns a proper action object', () => { | ||
expect(actions.getDetails.request(payload)).toEqual({ | ||
type: 'CART/GET_DETAILS/REQUEST', | ||
payload | ||
}); | ||
}); | ||
|
||
test('getDetails.receive.toString() returns the proper action type', () => { | ||
expect(actions.getDetails.receive.toString()).toBe( | ||
'CART/GET_DETAILS/RECEIVE' | ||
); | ||
}); | ||
|
||
test('getDetails.receive() returns a proper action object', () => { | ||
expect(actions.getDetails.receive(payload)).toEqual({ | ||
type: 'CART/GET_DETAILS/RECEIVE', | ||
payload | ||
}); | ||
expect(actions.getDetails.receive(error)).toEqual({ | ||
type: 'CART/GET_DETAILS/RECEIVE', | ||
payload: error, | ||
error: true | ||
}); | ||
}); |
Oops, something went wrong.