From c2cef0f815efb5667bf9aabff125cc1a8822283c Mon Sep 17 00:00:00 2001 From: Thomas Date: Tue, 30 Jan 2018 13:26:37 -0800 Subject: Set address to default with empty string, add test validation. --- test/helper.js | 4 ++++ test/lib/shallow-with-store.js | 20 +++++++++++++++++++ test/unit/ui/add-token.spec.js | 44 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 test/lib/shallow-with-store.js create mode 100644 test/unit/ui/add-token.spec.js (limited to 'test') 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.') + }) + + }) +}) -- cgit From 0f10aa372982c0d072bfd8f3466d3a044f0a7e94 Mon Sep 17 00:00:00 2001 From: Thomas Date: Tue, 30 Jan 2018 13:29:05 -0800 Subject: Clean up test, remove react & mountWithStore --- test/unit/ui/add-token.spec.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/unit/ui/add-token.spec.js b/test/unit/ui/add-token.spec.js index ee52f775f..9e74aa37e 100644 --- a/test/unit/ui/add-token.spec.js +++ b/test/unit/ui/add-token.spec.js @@ -1,11 +1,10 @@ -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 { shallowWithStore } = require('../../lib/shallow-with-store') const AddTokenScreen = require('../../../ui/app/add-token') -describe.only('Add Token Screen', function () { +describe('Add Token Screen', function () { let addTokenComponent, store, component const mockState = { metamask: { -- cgit