aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas <tmashuang@gmail.com>2018-01-31 05:26:37 +0800
committerThomas <tmashuang@gmail.com>2018-01-31 05:26:37 +0800
commitc2cef0f815efb5667bf9aabff125cc1a8822283c (patch)
treed2fa8be7f4b83cbad52bc0672296102046fb7972
parentb991ac0422acd509d5fd4a4ab28c2e6c4004c62f (diff)
downloadtangerine-wallet-browser-c2cef0f815efb5667bf9aabff125cc1a8822283c.tar.gz
tangerine-wallet-browser-c2cef0f815efb5667bf9aabff125cc1a8822283c.tar.zst
tangerine-wallet-browser-c2cef0f815efb5667bf9aabff125cc1a8822283c.zip
Set address to default with empty string, add test validation.
-rw-r--r--test/helper.js4
-rw-r--r--test/lib/shallow-with-store.js20
-rw-r--r--test/unit/ui/add-token.spec.js44
-rw-r--r--ui/app/add-token.js4
4 files changed, 70 insertions, 2 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..ee52f775f
--- /dev/null
+++ b/test/unit/ui/add-token.spec.js
@@ -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.')
+ })
+
+ })
+})
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