aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app
diff options
context:
space:
mode:
Diffstat (limited to 'ui/app')
-rw-r--r--ui/app/components/send_/tests/send-selectors-test-data.js20
-rw-r--r--ui/app/components/send_/tests/send-selectors.test.js6
-rw-r--r--ui/app/ducks/send.duck.js16
-rw-r--r--ui/app/ducks/tests/send-duck.test.js145
4 files changed, 167 insertions, 20 deletions
diff --git a/ui/app/components/send_/tests/send-selectors-test-data.js b/ui/app/components/send_/tests/send-selectors-test-data.js
index 1a95b5f41..ecfe9022f 100644
--- a/ui/app/components/send_/tests/send-selectors-test-data.js
+++ b/ui/app/components/send_/tests/send-selectors-test-data.js
@@ -90,31 +90,31 @@ module.exports = {
{
'id': 'mockTokenTx1',
'txParams': {
- 'to': '0x8d6b81208414189a58339873ab429b6c47ab92d3'
+ 'to': '0x8d6b81208414189a58339873ab429b6c47ab92d3',
},
- 'time': 1700000000000
+ 'time': 1700000000000,
},
{
'id': 'mockTokenTx2',
'txParams': {
- 'to': '0xafaketokenaddress'
+ 'to': '0xafaketokenaddress',
},
- 'time': 1600000000000
+ 'time': 1600000000000,
},
{
'id': 'mockTokenTx3',
'txParams': {
- 'to': '0x8d6b81208414189a58339873ab429b6c47ab92d3'
+ 'to': '0x8d6b81208414189a58339873ab429b6c47ab92d3',
},
- 'time': 1500000000000
+ 'time': 1500000000000,
},
{
'id': 'mockEthTx1',
'txParams': {
- 'to': '0xd85a4b6a394794842887b8284293d69163007bbb'
+ 'to': '0xd85a4b6a394794842887b8284293d69163007bbb',
},
- 'time': 1400000000000
- }
+ 'time': 1400000000000,
+ },
],
'selectedTokenAddress': '0x8d6b81208414189a58339873ab429b6c47ab92d3',
'unapprovedMsgs': {
@@ -195,7 +195,7 @@ module.exports = {
'txValue': 'de0b6b3a7640000',
'maxCost': 'de234b52e4a0800',
'gasPrice': '4a817c800',
- }
+ },
},
'currentLocale': 'en',
},
diff --git a/ui/app/components/send_/tests/send-selectors.test.js b/ui/app/components/send_/tests/send-selectors.test.js
index e2acc15f6..9dc207ead 100644
--- a/ui/app/components/send_/tests/send-selectors.test.js
+++ b/ui/app/components/send_/tests/send-selectors.test.js
@@ -42,12 +42,12 @@ const {
import mockState from './send-selectors-test-data'
describe('send selectors', () => {
- let tempGlobalEth = Object.assign({}, global.eth)
+ const tempGlobalEth = Object.assign({}, global.eth)
beforeEach(() => {
global.eth = {
contract: sinon.stub().returns({
- at: address => 'mockAt:' + address
- })
+ at: address => 'mockAt:' + address,
+ }),
}
})
diff --git a/ui/app/ducks/send.duck.js b/ui/app/ducks/send.duck.js
index aef493ea0..055cc05c1 100644
--- a/ui/app/ducks/send.duck.js
+++ b/ui/app/ducks/send.duck.js
@@ -16,32 +16,34 @@ const initState = {
// Reducer
export default function reducer ({ send: sendState = initState }, action = {}) {
+ const newState = extend({}, sendState)
+
switch (action.type) {
case OPEN_FROM_DROPDOWN:
- return extend(sendState, {
+ return extend(newState, {
fromDropdownOpen: true,
})
case CLOSE_FROM_DROPDOWN:
- return extend(sendState, {
+ return extend(newState, {
fromDropdownOpen: false,
})
case OPEN_TO_DROPDOWN:
- return extend(sendState, {
+ return extend(newState, {
toDropdownOpen: true,
})
case CLOSE_TO_DROPDOWN:
- return extend(sendState, {
+ return extend(newState, {
toDropdownOpen: false,
})
case UPDATE_SEND_ERRORS:
- return extend(sendState, {
+ return extend(newState, {
errors: {
- ...sendState.errors,
+ ...newState.errors,
...action.value,
},
})
default:
- return sendState
+ return newState
}
}
diff --git a/ui/app/ducks/tests/send-duck.test.js b/ui/app/ducks/tests/send-duck.test.js
new file mode 100644
index 000000000..c06cf55d2
--- /dev/null
+++ b/ui/app/ducks/tests/send-duck.test.js
@@ -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' }
+ )
+ })
+
+})