2018-05-14 14:57:36 +02:00
|
|
|
import assert from 'assert'
|
|
|
|
|
|
|
|
import SendReducer, {
|
|
|
|
openToDropdown,
|
|
|
|
closeToDropdown,
|
|
|
|
updateSendErrors,
|
2018-09-20 06:16:43 +02:00
|
|
|
showGasButtonGroup,
|
|
|
|
hideGasButtonGroup,
|
2019-03-22 00:03:30 +01:00
|
|
|
} from './send.duck.js'
|
2018-05-14 14:57:36 +02:00
|
|
|
|
|
|
|
describe('Send Duck', () => {
|
|
|
|
const mockState = {
|
|
|
|
send: {
|
|
|
|
mockProp: 123,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
const initState = {
|
|
|
|
toDropdownOpen: false,
|
|
|
|
errors: {},
|
2018-09-20 06:16:43 +02:00
|
|
|
gasButtonGroupShown: true,
|
2018-05-14 14:57:36 +02:00
|
|
|
}
|
|
|
|
const OPEN_TO_DROPDOWN = 'metamask/send/OPEN_TO_DROPDOWN'
|
|
|
|
const CLOSE_TO_DROPDOWN = 'metamask/send/CLOSE_TO_DROPDOWN'
|
|
|
|
const UPDATE_SEND_ERRORS = 'metamask/send/UPDATE_SEND_ERRORS'
|
2018-06-29 19:19:40 +02:00
|
|
|
const RESET_SEND_STATE = 'metamask/send/RESET_SEND_STATE'
|
2018-09-20 06:16:43 +02:00
|
|
|
const SHOW_GAS_BUTTON_GROUP = 'metamask/send/SHOW_GAS_BUTTON_GROUP'
|
|
|
|
const HIDE_GAS_BUTTON_GROUP = 'metamask/send/HIDE_GAS_BUTTON_GROUP'
|
2018-05-14 14:57:36 +02:00
|
|
|
|
|
|
|
describe('SendReducer()', () => {
|
|
|
|
it('should initialize state', () => {
|
|
|
|
assert.deepEqual(
|
|
|
|
SendReducer({}),
|
|
|
|
initState
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should return state unchanged if it does not match a dispatched actions type', () => {
|
|
|
|
assert.deepEqual(
|
|
|
|
SendReducer(mockState, {
|
|
|
|
type: 'someOtherAction',
|
|
|
|
value: 'someValue',
|
|
|
|
}),
|
|
|
|
Object.assign({}, mockState.send)
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should return a new object (and not just modify the existing state object)', () => {
|
|
|
|
assert.deepEqual(SendReducer(mockState), mockState.send)
|
|
|
|
assert.notEqual(SendReducer(mockState), mockState.send)
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
it('should set toDropdownOpen to true when receiving a OPEN_TO_DROPDOWN action', () => {
|
|
|
|
assert.deepEqual(
|
|
|
|
SendReducer(mockState, {
|
|
|
|
type: OPEN_TO_DROPDOWN,
|
|
|
|
}),
|
2019-12-03 21:50:55 +01:00
|
|
|
Object.assign({ toDropdownOpen: true }, mockState.send)
|
2018-05-14 14:57:36 +02:00
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should set toDropdownOpen to false when receiving a CLOSE_TO_DROPDOWN action', () => {
|
|
|
|
assert.deepEqual(
|
|
|
|
SendReducer(mockState, {
|
|
|
|
type: CLOSE_TO_DROPDOWN,
|
|
|
|
}),
|
2019-12-03 21:50:55 +01:00
|
|
|
Object.assign({ toDropdownOpen: false }, mockState.send)
|
2018-05-14 14:57:36 +02:00
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2018-09-20 06:16:43 +02:00
|
|
|
it('should set gasButtonGroupShown to true when receiving a SHOW_GAS_BUTTON_GROUP action', () => {
|
|
|
|
assert.deepEqual(
|
|
|
|
SendReducer(Object.assign({}, mockState, { gasButtonGroupShown: false }), {
|
|
|
|
type: SHOW_GAS_BUTTON_GROUP,
|
|
|
|
}),
|
2019-12-03 21:50:55 +01:00
|
|
|
Object.assign({ gasButtonGroupShown: true }, mockState.send)
|
2018-09-20 06:16:43 +02:00
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should set gasButtonGroupShown to false when receiving a HIDE_GAS_BUTTON_GROUP action', () => {
|
|
|
|
assert.deepEqual(
|
|
|
|
SendReducer(mockState, {
|
|
|
|
type: HIDE_GAS_BUTTON_GROUP,
|
|
|
|
}),
|
2019-12-03 21:50:55 +01:00
|
|
|
Object.assign({ gasButtonGroupShown: false }, mockState.send)
|
2018-09-20 06:16:43 +02:00
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2018-05-14 14:57:36 +02:00
|
|
|
it('should extend send.errors with the value of a UPDATE_SEND_ERRORS action', () => {
|
|
|
|
const modifiedMockState = Object.assign({}, mockState, {
|
|
|
|
send: {
|
|
|
|
errors: {
|
|
|
|
someError: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.deepEqual(
|
|
|
|
SendReducer(modifiedMockState, {
|
|
|
|
type: UPDATE_SEND_ERRORS,
|
|
|
|
value: { someOtherError: true },
|
|
|
|
}),
|
|
|
|
Object.assign({}, modifiedMockState.send, {
|
|
|
|
errors: {
|
|
|
|
someError: false,
|
|
|
|
someOtherError: true,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
)
|
|
|
|
})
|
2018-06-29 19:19:40 +02:00
|
|
|
|
|
|
|
it('should return the initial state in response to a RESET_SEND_STATE action', () => {
|
|
|
|
assert.deepEqual(
|
|
|
|
SendReducer(mockState, {
|
|
|
|
type: RESET_SEND_STATE,
|
|
|
|
}),
|
|
|
|
Object.assign({}, initState)
|
|
|
|
)
|
|
|
|
})
|
2018-05-14 14:57:36 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
describe('openToDropdown', () => {
|
|
|
|
assert.deepEqual(
|
|
|
|
openToDropdown(),
|
|
|
|
{ type: OPEN_TO_DROPDOWN }
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('closeToDropdown', () => {
|
|
|
|
assert.deepEqual(
|
|
|
|
closeToDropdown(),
|
|
|
|
{ type: CLOSE_TO_DROPDOWN }
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2018-09-20 06:16:43 +02:00
|
|
|
describe('showGasButtonGroup', () => {
|
|
|
|
assert.deepEqual(
|
|
|
|
showGasButtonGroup(),
|
|
|
|
{ type: SHOW_GAS_BUTTON_GROUP }
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('hideGasButtonGroup', () => {
|
|
|
|
assert.deepEqual(
|
|
|
|
hideGasButtonGroup(),
|
|
|
|
{ type: HIDE_GAS_BUTTON_GROUP }
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2018-05-14 14:57:36 +02:00
|
|
|
describe('updateSendErrors', () => {
|
|
|
|
assert.deepEqual(
|
|
|
|
updateSendErrors('mockErrorObject'),
|
|
|
|
{ type: UPDATE_SEND_ERRORS, value: 'mockErrorObject' }
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|