Tests for send.duck.js

feature/default_network_editable
Dan 7 years ago
parent 0076b732bd
commit 0739618a61
  1. 20
      ui/app/components/send_/tests/send-selectors-test-data.js
  2. 6
      ui/app/components/send_/tests/send-selectors.test.js
  3. 16
      ui/app/ducks/send.duck.js
  4. 145
      ui/app/ducks/tests/send-duck.test.js

@ -90,31 +90,31 @@ module.exports = {
{ {
'id': 'mockTokenTx1', 'id': 'mockTokenTx1',
'txParams': { 'txParams': {
'to': '0x8d6b81208414189a58339873ab429b6c47ab92d3' 'to': '0x8d6b81208414189a58339873ab429b6c47ab92d3',
}, },
'time': 1700000000000 'time': 1700000000000,
}, },
{ {
'id': 'mockTokenTx2', 'id': 'mockTokenTx2',
'txParams': { 'txParams': {
'to': '0xafaketokenaddress' 'to': '0xafaketokenaddress',
}, },
'time': 1600000000000 'time': 1600000000000,
}, },
{ {
'id': 'mockTokenTx3', 'id': 'mockTokenTx3',
'txParams': { 'txParams': {
'to': '0x8d6b81208414189a58339873ab429b6c47ab92d3' 'to': '0x8d6b81208414189a58339873ab429b6c47ab92d3',
}, },
'time': 1500000000000 'time': 1500000000000,
}, },
{ {
'id': 'mockEthTx1', 'id': 'mockEthTx1',
'txParams': { 'txParams': {
'to': '0xd85a4b6a394794842887b8284293d69163007bbb' 'to': '0xd85a4b6a394794842887b8284293d69163007bbb',
}, },
'time': 1400000000000 'time': 1400000000000,
} },
], ],
'selectedTokenAddress': '0x8d6b81208414189a58339873ab429b6c47ab92d3', 'selectedTokenAddress': '0x8d6b81208414189a58339873ab429b6c47ab92d3',
'unapprovedMsgs': { 'unapprovedMsgs': {
@ -195,7 +195,7 @@ module.exports = {
'txValue': 'de0b6b3a7640000', 'txValue': 'de0b6b3a7640000',
'maxCost': 'de234b52e4a0800', 'maxCost': 'de234b52e4a0800',
'gasPrice': '4a817c800', 'gasPrice': '4a817c800',
} },
}, },
'currentLocale': 'en', 'currentLocale': 'en',
}, },

@ -42,12 +42,12 @@ const {
import mockState from './send-selectors-test-data' import mockState from './send-selectors-test-data'
describe('send selectors', () => { describe('send selectors', () => {
let tempGlobalEth = Object.assign({}, global.eth) const tempGlobalEth = Object.assign({}, global.eth)
beforeEach(() => { beforeEach(() => {
global.eth = { global.eth = {
contract: sinon.stub().returns({ contract: sinon.stub().returns({
at: address => 'mockAt:' + address at: address => 'mockAt:' + address,
}) }),
} }
}) })

@ -16,32 +16,34 @@ const initState = {
// Reducer // Reducer
export default function reducer ({ send: sendState = initState }, action = {}) { export default function reducer ({ send: sendState = initState }, action = {}) {
const newState = extend({}, sendState)
switch (action.type) { switch (action.type) {
case OPEN_FROM_DROPDOWN: case OPEN_FROM_DROPDOWN:
return extend(sendState, { return extend(newState, {
fromDropdownOpen: true, fromDropdownOpen: true,
}) })
case CLOSE_FROM_DROPDOWN: case CLOSE_FROM_DROPDOWN:
return extend(sendState, { return extend(newState, {
fromDropdownOpen: false, fromDropdownOpen: false,
}) })
case OPEN_TO_DROPDOWN: case OPEN_TO_DROPDOWN:
return extend(sendState, { return extend(newState, {
toDropdownOpen: true, toDropdownOpen: true,
}) })
case CLOSE_TO_DROPDOWN: case CLOSE_TO_DROPDOWN:
return extend(sendState, { return extend(newState, {
toDropdownOpen: false, toDropdownOpen: false,
}) })
case UPDATE_SEND_ERRORS: case UPDATE_SEND_ERRORS:
return extend(sendState, { return extend(newState, {
errors: { errors: {
...sendState.errors, ...newState.errors,
...action.value, ...action.value,
}, },
}) })
default: default:
return sendState return newState
} }
} }

@ -0,0 +1,145 @@
import assert from 'assert'
import SendReducer, {
openFromDropdown,
closeFromDropdown,
openToDropdown,
closeToDropdown,
updateSendErrors,
} from '../send.duck.js'
describe('Send Duck', () => {
const mockState = {
send: {
mockProp: 123,
},
}
const initState = {
fromDropdownOpen: false,
toDropdownOpen: false,
errors: {},
}
const OPEN_FROM_DROPDOWN = 'metamask/send/OPEN_FROM_DROPDOWN'
const CLOSE_FROM_DROPDOWN = 'metamask/send/CLOSE_FROM_DROPDOWN'
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'
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 set fromDropdownOpen to true when receiving a OPEN_FROM_DROPDOWN action', () => {
assert.deepEqual(
SendReducer(mockState, {
type: OPEN_FROM_DROPDOWN,
}),
Object.assign({fromDropdownOpen: true}, 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 fromDropdownOpen to false when receiving a CLOSE_FROM_DROPDOWN action', () => {
assert.deepEqual(
SendReducer(mockState, {
type: CLOSE_FROM_DROPDOWN,
}),
Object.assign({fromDropdownOpen: false}, mockState.send)
)
})
it('should set toDropdownOpen to true when receiving a OPEN_TO_DROPDOWN action', () => {
assert.deepEqual(
SendReducer(mockState, {
type: OPEN_TO_DROPDOWN,
}),
Object.assign({toDropdownOpen: true}, mockState.send)
)
})
it('should set toDropdownOpen to false when receiving a CLOSE_TO_DROPDOWN action', () => {
assert.deepEqual(
SendReducer(mockState, {
type: CLOSE_TO_DROPDOWN,
}),
Object.assign({toDropdownOpen: false}, mockState.send)
)
})
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,
},
})
)
})
})
describe('openFromDropdown', () => {
assert.deepEqual(
openFromDropdown(),
{ type: OPEN_FROM_DROPDOWN }
)
})
describe('closeFromDropdown', () => {
assert.deepEqual(
closeFromDropdown(),
{ type: CLOSE_FROM_DROPDOWN }
)
})
describe('openToDropdown', () => {
assert.deepEqual(
openToDropdown(),
{ type: OPEN_TO_DROPDOWN }
)
})
describe('closeToDropdown', () => {
assert.deepEqual(
closeToDropdown(),
{ type: CLOSE_TO_DROPDOWN }
)
})
describe('updateSendErrors', () => {
assert.deepEqual(
updateSendErrors('mockErrorObject'),
{ type: UPDATE_SEND_ERRORS, value: 'mockErrorObject' }
)
})
})
Loading…
Cancel
Save