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:
parent
b991ac0422
commit
c2cef0f815
@ -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()
|
||||
|
||||
|
20
test/lib/shallow-with-store.js
Normal file
20
test/lib/shallow-with-store.js
Normal 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})
|
||||
}
|
44
test/unit/ui/add-token.spec.js
Normal file
44
test/unit/ui/add-token.spec.js
Normal 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.')
|
||||
})
|
||||
|
||||
})
|
||||
})
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user