1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-18 07:23:21 +01:00
metamask-extension/ui/app/ducks/send/send-duck.test.js

132 lines
3.7 KiB
JavaScript
Raw Normal View History

2018-05-14 14:57:36 +02:00
import assert from 'assert'
import SendReducer, {
openToDropdown,
closeToDropdown,
updateSendErrors,
showGasButtonGroup,
hideGasButtonGroup,
} from './send.duck'
2018-05-14 14:57:36 +02:00
describe('Send Duck', function () {
2018-05-14 14:57:36 +02:00
const mockState = {
mockProp: 123,
2018-05-14 14:57:36 +02:00
}
const initState = {
toDropdownOpen: false,
errors: {},
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'
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()', function () {
it('should initialize state', function () {
assert.deepEqual(SendReducer(undefined, {}), initState)
2018-05-14 14:57:36 +02:00
})
it('should return state unchanged if it does not match a dispatched actions type', function () {
2018-05-14 14:57:36 +02:00
assert.deepEqual(
SendReducer(mockState, {
type: 'someOtherAction',
value: 'someValue',
}),
mockState,
2018-05-14 14:57:36 +02:00
)
})
it('should set toDropdownOpen to true when receiving a OPEN_TO_DROPDOWN action', function () {
2018-05-14 14:57:36 +02:00
assert.deepEqual(
SendReducer(mockState, {
type: OPEN_TO_DROPDOWN,
}),
{ toDropdownOpen: true, ...mockState },
2018-05-14 14:57:36 +02:00
)
})
it('should set toDropdownOpen to false when receiving a CLOSE_TO_DROPDOWN action', function () {
2018-05-14 14:57:36 +02:00
assert.deepEqual(
SendReducer(mockState, {
type: CLOSE_TO_DROPDOWN,
}),
{ toDropdownOpen: false, ...mockState },
2018-05-14 14:57:36 +02:00
)
})
it('should set gasButtonGroupShown to true when receiving a SHOW_GAS_BUTTON_GROUP action', function () {
assert.deepEqual(
2020-11-03 00:41:28 +01:00
SendReducer(
{ ...mockState, gasButtonGroupShown: false },
{ type: SHOW_GAS_BUTTON_GROUP },
),
{ gasButtonGroupShown: true, ...mockState },
)
})
it('should set gasButtonGroupShown to false when receiving a HIDE_GAS_BUTTON_GROUP action', function () {
assert.deepEqual(
SendReducer(mockState, { type: HIDE_GAS_BUTTON_GROUP }),
{ gasButtonGroupShown: false, ...mockState },
)
})
it('should extend send.errors with the value of a UPDATE_SEND_ERRORS action', function () {
const modifiedMockState = {
...mockState,
errors: {
someError: false,
2018-05-14 14:57:36 +02:00
},
}
2018-05-14 14:57:36 +02:00
assert.deepEqual(
SendReducer(modifiedMockState, {
type: UPDATE_SEND_ERRORS,
value: { someOtherError: true },
}),
{
...modifiedMockState,
2018-05-14 14:57:36 +02:00
errors: {
someError: false,
someOtherError: true,
},
},
2018-05-14 14:57:36 +02:00
)
})
2018-06-29 19:19:40 +02:00
it('should return the initial state in response to a RESET_SEND_STATE action', function () {
2018-06-29 19:19:40 +02:00
assert.deepEqual(
SendReducer(mockState, {
type: RESET_SEND_STATE,
}),
initState,
2018-06-29 19:19:40 +02:00
)
})
2018-05-14 14:57:36 +02:00
})
describe('openToDropdown', function () {
assert.deepEqual(openToDropdown(), { type: OPEN_TO_DROPDOWN })
2018-05-14 14:57:36 +02:00
})
describe('closeToDropdown', function () {
assert.deepEqual(closeToDropdown(), { type: CLOSE_TO_DROPDOWN })
2018-05-14 14:57:36 +02:00
})
describe('showGasButtonGroup', function () {
assert.deepEqual(showGasButtonGroup(), { type: SHOW_GAS_BUTTON_GROUP })
})
describe('hideGasButtonGroup', function () {
assert.deepEqual(hideGasButtonGroup(), { type: HIDE_GAS_BUTTON_GROUP })
})
describe('updateSendErrors', function () {
2020-11-03 00:41:28 +01:00
assert.deepEqual(updateSendErrors('mockErrorObject'), {
type: UPDATE_SEND_ERRORS,
value: 'mockErrorObject',
})
2018-05-14 14:57:36 +02:00
})
})