diff options
author | Frankie <frankie.diamond@gmail.com> | 2018-02-01 06:18:47 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-01 06:18:47 +0800 |
commit | 1a93b1ade292369bff2ceecf036f856fe0b20dbb (patch) | |
tree | 2fedac9028936ba3b371873a10283b4bb5ed8e41 /test | |
parent | 1eec2ca8c0e42fdf603f4f6b19c75f61ecbc8fc3 (diff) | |
parent | 1f8dd5f0def9856efa867c74dba71dba47433a46 (diff) | |
download | tangerine-wallet-browser-1a93b1ade292369bff2ceecf036f856fe0b20dbb.tar tangerine-wallet-browser-1a93b1ade292369bff2ceecf036f856fe0b20dbb.tar.gz tangerine-wallet-browser-1a93b1ade292369bff2ceecf036f856fe0b20dbb.tar.bz2 tangerine-wallet-browser-1a93b1ade292369bff2ceecf036f856fe0b20dbb.tar.lz tangerine-wallet-browser-1a93b1ade292369bff2ceecf036f856fe0b20dbb.tar.xz tangerine-wallet-browser-1a93b1ade292369bff2ceecf036f856fe0b20dbb.tar.zst tangerine-wallet-browser-1a93b1ade292369bff2ceecf036f856fe0b20dbb.zip |
Merge pull request #3146 from MetaMask/i3082-AddTokenValidateInputs
Set address to default with empty string, add test validation.
Diffstat (limited to 'test')
-rw-r--r-- | test/helper.js | 4 | ||||
-rw-r--r-- | test/lib/shallow-with-store.js | 20 | ||||
-rw-r--r-- | test/unit/ui/add-token.spec.js | 43 |
3 files changed, 67 insertions, 0 deletions
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.') + }) + + }) +}) |