diff --git a/CHANGELOG.md b/CHANGELOG.md index a55f21060..bb371378f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ - Fix provider for Kovan network. - Bump limit for EventEmitter listeners before warning. +- Display Error when empty string is entered as a token address. ## 3.13.7 2018-1-22 diff --git a/package.json b/package.json index 283d1dd3a..74a9f15d0 100644 --- a/package.json +++ b/package.json @@ -172,12 +172,14 @@ "deep-freeze-strict": "^1.1.1", "del": "^3.0.0", "envify": "^4.0.0", - "enzyme": "^3.2.0", + "enzyme": "^3.3.0", + "enzyme-adapter-react-15": "^1.0.5", "eslint-plugin-chai": "0.0.1", "eslint-plugin-mocha": "^4.9.0", "eth-json-rpc-middleware": "^1.2.7", "fs-promise": "^2.0.3", "gulp": "github:gulpjs/gulp#6d71a658c61edb3090221579d8f97dbe086ba2ed", + "gulp-eslint": "^4.0.0", "gulp-if": "^2.0.1", "gulp-json-editor": "^2.2.1", "gulp-livereload": "^3.8.1", @@ -186,7 +188,6 @@ "gulp-util": "^3.0.7", "gulp-watch": "^5.0.0", "gulp-zip": "^4.0.0", - "gulp-eslint": "^4.0.0", "isomorphic-fetch": "^2.2.1", "jsdom": "^11.1.0", "jsdom-global": "^3.0.2", @@ -210,6 +211,7 @@ "react-addons-test-utils": "^15.5.1", "react-test-renderer": "^15.6.2", "react-testutils-additions": "^15.2.0", + "redux-test-utils": "^0.2.2", "sinon": "^4.0.0", "tape": "^4.5.1", "testem": "^2.0.0", diff --git a/test/helper.js b/test/helper.js index 1c5934a89..a3abbebf2 100644 --- a/test/helper.js +++ b/test/helper.js @@ -1,3 +1,7 @@ +import Enzyme from 'enzyme' +import Adapter from 'enzyme-adapter-react-15' + +Enzyme.configure({ adapter: new Adapter() }) // disallow promises from swallowing errors enableFailureOnUnhandledPromiseRejection() diff --git a/test/lib/shallow-with-store.js b/test/lib/shallow-with-store.js new file mode 100644 index 000000000..10c02a18c --- /dev/null +++ b/test/lib/shallow-with-store.js @@ -0,0 +1,20 @@ +const { shallow, mount } = require('enzyme') + +module.exports = { + shallowWithStore, + mountWithStore, +} + +function shallowWithStore (component, store) { + const context = { + store, + } + return shallow(component, {context}) +} + +function mountWithStore (component, store) { + const context = { + store, + } + return mount(component, {context}) +} \ No newline at end of file diff --git a/test/unit/ui/add-token.spec.js b/test/unit/ui/add-token.spec.js new file mode 100644 index 000000000..9e74aa37e --- /dev/null +++ b/test/unit/ui/add-token.spec.js @@ -0,0 +1,43 @@ +const assert = require('assert') +const { createMockStore } = require('redux-test-utils') +const h = require('react-hyperscript') +const { shallowWithStore } = require('../../lib/shallow-with-store') +const AddTokenScreen = require('../../../ui/app/add-token') + +describe('Add Token Screen', function () { + let addTokenComponent, store, component + const mockState = { + metamask: { + identities: { + '0x7d3517b0d011698406d6e0aed8453f0be2697926': { + 'address': '0x7d3517b0d011698406d6e0aed8453f0be2697926', + 'name': 'Add Token Name', + }, + }, + }, + } + beforeEach(function () { + store = createMockStore(mockState) + component = shallowWithStore(h(AddTokenScreen), store) + addTokenComponent = component.dive() + }) + + describe('#ValidateInputs', function () { + + it('Default State', function () { + addTokenComponent.instance().validateInputs() + const state = addTokenComponent.state() + assert.equal(state.warning, 'Address is invalid.') + }) + + it('Address is a Metamask Identity', function () { + addTokenComponent.setState({ + address: '0x7d3517b0d011698406d6e0aed8453f0be2697926', + }) + addTokenComponent.instance().validateInputs() + const state = addTokenComponent.state() + assert.equal(state.warning, 'Personal address detected. Input the token contract address.') + }) + + }) +}) diff --git a/ui/app/add-token.js b/ui/app/add-token.js index 9354a4cad..d5a23c360 100644 --- a/ui/app/add-token.js +++ b/ui/app/add-token.js @@ -25,7 +25,7 @@ inherits(AddTokenScreen, Component) function AddTokenScreen () { this.state = { warning: null, - address: null, + address: '', symbol: 'TOKEN', decimals: 18, } @@ -190,7 +190,7 @@ AddTokenScreen.prototype.validateInputs = function () { const validAddress = ethUtil.isValidAddress(address) if (!validAddress) { - msg += 'Address is invalid. ' + msg += 'Address is invalid.' } const validDecimals = decimals >= 0 && decimals < 36