1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Set address to default with empty string, add test validation.

This commit is contained in:
Thomas 2018-01-30 13:26:37 -08:00
parent b991ac0422
commit c2cef0f815
4 changed files with 70 additions and 2 deletions

View File

@ -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()

View File

@ -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})
}

View File

@ -0,0 +1,44 @@
const React = require('react')
const assert = require('assert')
const { createMockStore } = require('redux-test-utils')
const h = require('react-hyperscript')
const { shallowWithStore, mountWithStore } = require('../../lib/shallow-with-store')
const AddTokenScreen = require('../../../ui/app/add-token')
describe.only('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.')
})
})
})

View File

@ -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