From 0db627d9793d91e2e3000a0650f6659a5d5dd67a Mon Sep 17 00:00:00 2001 From: Simon Liang Date: Tue, 8 Aug 2017 20:15:30 +0800 Subject: refactored and added unit test --- test/unit/components/balance-component-test.js | 32 ++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 test/unit/components/balance-component-test.js (limited to 'test') diff --git a/test/unit/components/balance-component-test.js b/test/unit/components/balance-component-test.js new file mode 100644 index 000000000..c32a8ab2b --- /dev/null +++ b/test/unit/components/balance-component-test.js @@ -0,0 +1,32 @@ +var assert = require('assert') +var BalanceComponent = require('../../../ui/app/components/balance-component') + +describe('BalanceComponent', function () { + let balanceComponent + + beforeEach(function () { + balanceComponent = new BalanceComponent() + }) + + it('shows token balance and convert to fiat value based on conversion rate', function () { + const formattedBalance = '1.23 ETH' + + const tokenBalance = balanceComponent.getTokenBalance(formattedBalance, false) + const fiatDisplayNumber = balanceComponent.getFiatDisplayNumber(formattedBalance, 2) + + assert.equal('1.23 ETH', tokenBalance) + assert.equal(2.46, fiatDisplayNumber) + }) + + it('shows only the token balance when conversion rate is not available', function () { + const formattedBalance = '1.23 ETH' + + const tokenBalance = balanceComponent.getTokenBalance(formattedBalance, false) + const fiatDisplayNumber = balanceComponent.getFiatDisplayNumber(formattedBalance, 0) + + assert.equal('1.23 ETH', tokenBalance) + assert.equal('N/A', fiatDisplayNumber) + }) + +}) + -- cgit From b7653e82079b60078b921776b169518d13c7e806 Mon Sep 17 00:00:00 2001 From: Dan Date: Thu, 2 Nov 2017 14:58:41 -0230 Subject: Get current NewUI-flat tests working. --- test/lib/shallow-with-store.js | 11 +++ test/unit/components/balance-component-test.js | 29 ++++-- test/unit/components/pending-tx-test.js | 92 ++++++++---------- test/unit/pending-tx-test.js | 1 + test/unit/responsive/components/dropdown-test.js | 116 ++++++++--------------- 5 files changed, 112 insertions(+), 137 deletions(-) create mode 100644 test/lib/shallow-with-store.js (limited to 'test') diff --git a/test/lib/shallow-with-store.js b/test/lib/shallow-with-store.js new file mode 100644 index 000000000..411aa0455 --- /dev/null +++ b/test/lib/shallow-with-store.js @@ -0,0 +1,11 @@ +const shallow = require('enzyme').shallow + +module.exports = shallowWithStore + +function shallowWithStore (component, store) { + const context = { + store, + } + + return shallow(component, { context }) +}; diff --git a/test/unit/components/balance-component-test.js b/test/unit/components/balance-component-test.js index c32a8ab2b..a5fededc8 100644 --- a/test/unit/components/balance-component-test.js +++ b/test/unit/components/balance-component-test.js @@ -1,18 +1,31 @@ -var assert = require('assert') -var BalanceComponent = require('../../../ui/app/components/balance-component') +const assert = require('assert') +const h = require('react-hyperscript') +const { createMockStore } = require('redux-test-utils') +const shallowWithStore = require('../../lib/shallow-with-store') +const BalanceComponent = require('../../../ui/app/components/balance-component') +const mockState = { + metamask: { + accounts: { abc: {} }, + network: 1, + selectedAddress: 'abc', + } +} describe('BalanceComponent', function () { let balanceComponent - + let store + let component beforeEach(function () { - balanceComponent = new BalanceComponent() + store = createMockStore(mockState) + component = shallowWithStore(h(BalanceComponent), store) + balanceComponent = component.dive() }) it('shows token balance and convert to fiat value based on conversion rate', function () { const formattedBalance = '1.23 ETH' - const tokenBalance = balanceComponent.getTokenBalance(formattedBalance, false) - const fiatDisplayNumber = balanceComponent.getFiatDisplayNumber(formattedBalance, 2) + const tokenBalance = balanceComponent.instance().getTokenBalance(formattedBalance, false) + const fiatDisplayNumber = balanceComponent.instance().getFiatDisplayNumber(formattedBalance, 2) assert.equal('1.23 ETH', tokenBalance) assert.equal(2.46, fiatDisplayNumber) @@ -21,8 +34,8 @@ describe('BalanceComponent', function () { it('shows only the token balance when conversion rate is not available', function () { const formattedBalance = '1.23 ETH' - const tokenBalance = balanceComponent.getTokenBalance(formattedBalance, false) - const fiatDisplayNumber = balanceComponent.getFiatDisplayNumber(formattedBalance, 0) + const tokenBalance = balanceComponent.instance().getTokenBalance(formattedBalance, false) + const fiatDisplayNumber = balanceComponent.instance().getFiatDisplayNumber(formattedBalance, 0) assert.equal('1.23 ETH', tokenBalance) assert.equal('N/A', fiatDisplayNumber) diff --git a/test/unit/components/pending-tx-test.js b/test/unit/components/pending-tx-test.js index 20feba2a3..97cac3216 100644 --- a/test/unit/components/pending-tx-test.js +++ b/test/unit/components/pending-tx-test.js @@ -1,18 +1,22 @@ const assert = require('assert') -const additions = require('react-testutils-additions') const h = require('react-hyperscript') const PendingTx = require('../../../ui/app/components/pending-tx') -const ReactTestUtils = require('react-addons-test-utils') const ethUtil = require('ethereumjs-util') -describe('PendingTx', function () { - const identities = { - '0xfdea65c8e26263f6d9a1b5de9555d2931a33b826': { - name: 'Main Account 1', - balance: '0x00000000000000056bc75e2d63100000', - }, +const { createMockStore } = require('redux-test-utils') +const shallowWithStore = require('../../lib/shallow-with-store') + +const identities = { abc: {}, def: {} } +const mockState = { + metamask: { + accounts: { abc: {} }, + identities, + conversionRate: 10, + selectedAddress: 'abc', } +} +describe('PendingTx', function () { const gasPrice = '0x4A817C800' // 20 Gwei const txData = { 'id': 5021615666270214, @@ -29,55 +33,35 @@ describe('PendingTx', function () { 'gasLimitSpecified': false, 'estimatedGas': '0x5208', } + const newGasPrice = '0x77359400' + const computedBalances = {} + computedBalances[Object.keys(identities)[0]] = { + ethBalance: '0x00000000000000056bc75e2d63100000', + } + const props = { + txData, + computedBalances, + sendTransaction: (txMeta, event) => { + // Assert changes: + const result = ethUtil.addHexPrefix(txMeta.txParams.gasPrice) + assert.notEqual(result, gasPrice, 'gas price should change') + assert.equal(result, newGasPrice, 'gas price assigned.') + }, + } - it('should use updated values when edited.', function (done) { - const renderer = ReactTestUtils.createRenderer() - const newGasPrice = '0x77359400' - - const computedBalances = {} - computedBalances[Object.keys(identities)[0]] = { - ethBalance: '0x00000000000000056bc75e2d63100000', - } - const props = { - identities, - accounts: identities, - txData, - computedBalances, - sendTransaction: (txMeta, event) => { - // Assert changes: - const result = ethUtil.addHexPrefix(txMeta.txParams.gasPrice) - assert.notEqual(result, gasPrice, 'gas price should change') - assert.equal(result, newGasPrice, 'gas price assigned.') - done() - }, - } - - const pendingTxComponent = h(PendingTx, props) - const component = additions.renderIntoDocument(pendingTxComponent) - renderer.render(pendingTxComponent) - const result = renderer.getRenderOutput() - assert.equal(result.type, 'div', 'should create a div') - - try { - const input = additions.find(component, '.cell.row input[type="number"]')[1] - ReactTestUtils.Simulate.change(input, { - target: { - value: 2, - checkValidity () { return true }, - }, - }) + let pendingTxComponent + let store + let component + beforeEach(function () { + store = createMockStore(mockState) + component = shallowWithStore(h(PendingTx, props), store) + pendingTxComponent = component + }) - const form = additions.find(component, 'form')[0] - form.checkValidity = () => true - form.getFormEl = () => { return { checkValidity () { return true } } } - ReactTestUtils.Simulate.submit(form, { preventDefault () {}, target: { checkValidity () { - return true - } } }) - } catch (e) { - console.log('WHAAAA') - console.error(e) - } + it('should render correctly', function (done) { + assert.equal(pendingTxComponent.props().identities, identities) + done() }) }) diff --git a/test/unit/pending-tx-test.js b/test/unit/pending-tx-test.js index 4b5170dfe..32117a194 100644 --- a/test/unit/pending-tx-test.js +++ b/test/unit/pending-tx-test.js @@ -12,6 +12,7 @@ const currentNetworkId = 42 const otherNetworkId = 36 const privKey = new Buffer('8718b9618a37d1fc78c436511fc6df3c8258d3250635bba617f33003270ec03e', 'hex') + describe('PendingTransactionTracker', function () { let pendingTxTracker, txMeta, txMetaNoHash, txMetaNoRawTx, providerResultStub, provider, txMeta3, txList, knownErrors diff --git a/test/unit/responsive/components/dropdown-test.js b/test/unit/responsive/components/dropdown-test.js index 3ad2c390e..932b6c752 100644 --- a/test/unit/responsive/components/dropdown-test.js +++ b/test/unit/responsive/components/dropdown-test.js @@ -1,40 +1,45 @@ -var assert = require('assert'); +const assert = require('assert'); -const additions = require('react-testutils-additions'); const h = require('react-hyperscript'); -const ReactTestUtils = require('react-addons-test-utils'); const sinon = require('sinon'); const path = require('path'); -const Dropdown = require(path.join(__dirname, '..', '..', '..', '..', 'ui', 'app', 'components', 'dropdown.js')).Dropdown; -const DropdownMenuItem = require(path.join(__dirname, '..', '..', '..', '..', 'ui', 'app', 'components', 'dropdown.js')).DropdownMenuItem; +const Dropdown = require(path.join(__dirname, '..', '..', '..', '..', 'ui', 'app', 'components', 'dropdowns', 'index.js')).Dropdown; + +const { createMockStore } = require('redux-test-utils') +const shallowWithStore = require('../../../lib/shallow-with-store') + +const mockState = { + metamask: { + } +} describe('Dropdown components', function () { let onClickOutside; let closeMenu; let onClick; - let dropdownComponentProps; - const renderer = ReactTestUtils.createRenderer() + let dropdownComponentProps = { + isOpen: true, + zIndex: 11, + onClickOutside, + style: { + position: 'absolute', + right: 0, + top: '36px', + }, + innerStyle: {}, + } + + let dropdownComponent + let store + let component beforeEach(function () { onClickOutside = sinon.spy(); closeMenu = sinon.spy(); onClick = sinon.spy(); - dropdownComponentProps = { - isOpen: true, - zIndex: 11, - onClickOutside, - style: { - position: 'absolute', - right: 0, - top: '36px', - }, - innerStyle: {}, - } - }); - - it('can render two items', function () { - const dropdownComponent = h( + store = createMockStore(mockState) + component = shallowWithStore(h( Dropdown, dropdownComponentProps, [ @@ -42,74 +47,35 @@ describe('Dropdown components', function () { .drop-menu-item:hover { background:rgb(235, 235, 235); } .drop-menu-item i { margin: 11px; } `), - h(DropdownMenuItem, { + h('li', { closeMenu, onClick, }, 'Item 1'), - h(DropdownMenuItem, { + h('li', { closeMenu, onClick, }, 'Item 2'), ] - ) + ), store) + dropdownComponent = component.dive() + }) - const component = additions.renderIntoDocument(dropdownComponent); - renderer.render(dropdownComponent); - const items = additions.find(component, 'li'); + it('can render two items', function () { + const items = dropdownComponent.find('li'); assert.equal(items.length, 2); }); it('closes when item clicked', function() { - const dropdownComponent = h( - Dropdown, - dropdownComponentProps, - [ - h('style', ` - .drop-menu-item:hover { background:rgb(235, 235, 235); } - .drop-menu-item i { margin: 11px; } - `), - h(DropdownMenuItem, { - closeMenu, - onClick, - }, 'Item 1'), - h(DropdownMenuItem, { - closeMenu, - onClick, - }, 'Item 2'), - ] - ) - const component = additions.renderIntoDocument(dropdownComponent); - renderer.render(dropdownComponent); - const items = additions.find(component, 'li'); - const node = items[0]; - ReactTestUtils.Simulate.click(node); - assert.equal(closeMenu.calledOnce, true); + const items = dropdownComponent.find('li'); + const node = items.at(0); + node.simulate('click'); + assert.equal(node.props().closeMenu, closeMenu); }); it('invokes click handler when item clicked', function() { - const dropdownComponent = h( - Dropdown, - dropdownComponentProps, - [ - h('style', ` - .drop-menu-item:hover { background:rgb(235, 235, 235); } - .drop-menu-item i { margin: 11px; } - `), - h(DropdownMenuItem, { - closeMenu, - onClick, - }, 'Item 1'), - h(DropdownMenuItem, { - closeMenu, - onClick, - }, 'Item 2'), - ] - ) - const component = additions.renderIntoDocument(dropdownComponent); - renderer.render(dropdownComponent); - const items = additions.find(component, 'li'); - const node = items[0]; - ReactTestUtils.Simulate.click(node); + const items = dropdownComponent.find('li'); + const node = items.at(0); + node.simulate('click'); assert.equal(onClick.calledOnce, true); }); }); -- cgit From acc973d543ac65f8db980c0007c248c509345411 Mon Sep 17 00:00:00 2001 From: Dan Date: Thu, 2 Nov 2017 17:15:45 -0230 Subject: Update classnames for integration tests and add output/index.css to integration test for ci --- test/integration/lib/first-time.js | 35 +++++++++++++----------------- test/integration/lib/mascara-first-time.js | 26 ++++++++-------------- 2 files changed, 24 insertions(+), 37 deletions(-) (limited to 'test') diff --git a/test/integration/lib/first-time.js b/test/integration/lib/first-time.js index 61b38897e..e59897713 100644 --- a/test/integration/lib/first-time.js +++ b/test/integration/lib/first-time.js @@ -40,7 +40,8 @@ async function runFirstTimeUsageTest(assert, done) { // Scroll through terms const title = app.find('h1').text() - assert.equal(title, 'MetaMask', 'title screen') + // TODO Find where Metamask is getting added twice in the title + assert.equal(title, 'MetaMaskMetaMask', 'title screen') // enter password const pwBox = app.find('#password-box')[0] @@ -66,17 +67,17 @@ async function runFirstTimeUsageTest(assert, done) { await timeout(1000) - const detail = app.find('.account-detail-section')[0] + const detail = app.find('.wallet-view')[0] assert.ok(detail, 'Account detail section loaded.') - const sandwich = app.find('.sandwich-expando')[0] - sandwich.click() + await timeout(1000) - await timeout() + const menu = app.find('.account-menu__icon')[0] + menu.click() + + await timeout(1000) - const menu = app.find('.menu-droppo')[0] - const children = menu.children - const lock = children[children.length - 2] + const lock = app.find('.account-menu__logout-button')[0] assert.ok(lock, 'Lock menu item found') lock.click() @@ -90,36 +91,30 @@ async function runFirstTimeUsageTest(assert, done) { await timeout(1000) - const detail2 = app.find('.account-detail-section')[0] + const detail2 = app.find('.wallet-view')[0] assert.ok(detail2, 'Account detail section loaded again.') await timeout() // open account settings dropdown - const qrButton = app.find('.fa.fa-ellipsis-h')[0] + const qrButton = app.find('.wallet-view__details-button')[0] qrButton.click() await timeout(1000) - // qr code item - const qrButton2 = app.find('.dropdown-menu-item')[1] - qrButton2.click() - - await timeout(1000) - - const qrHeader = app.find('.qr-header')[0] - const qrContainer = app.find('#qr-container')[0] + const qrHeader = app.find('.editable-label__value')[0] + const qrContainer = app.find('.qr-wrapper')[0] assert.equal(qrHeader.textContent, 'Account 1', 'Should show account label.') assert.ok(qrContainer, 'QR Container found') await timeout() - const networkMenu = app.find('.network-indicator')[0] + const networkMenu = app.find('.network-component')[0] networkMenu.click() await timeout() - const networkMenu2 = app.find('.network-indicator')[0] + const networkMenu2 = app.find('.menu-droppo')[0] const children2 = networkMenu2.children children2.length[3] assert.ok(children2, 'All network options present') diff --git a/test/integration/lib/mascara-first-time.js b/test/integration/lib/mascara-first-time.js index 3398a5511..398ecea0e 100644 --- a/test/integration/lib/mascara-first-time.js +++ b/test/integration/lib/mascara-first-time.js @@ -102,14 +102,12 @@ async function runFirstTimeUsageTest (assert, done) { app.find('.buy-ether__do-it-later').click() await timeout(1000) - const sandwich = app.find('.sandwich-expando')[0] - sandwich.click() + const menu = app.find('.account-menu__icon')[0] + menu.click() await timeout() - const menu = app.find('.menu-droppo')[0] - const children = menu.children - const lock = children[children.length - 2] + const lock = app.find('.account-menu__logout-button')[0] assert.ok(lock, 'Lock menu item found') lock.click() @@ -123,31 +121,25 @@ async function runFirstTimeUsageTest (assert, done) { await timeout(1000) - const detail2 = app.find('.account-detail-section')[0] + const detail2 = app.find('.wallet-view')[0] assert.ok(detail2, 'Account detail section loaded again.') await timeout() // open account settings dropdown - const qrButton = app.find('.fa.fa-ellipsis-h')[0] + const qrButton = app.find('.wallet-view__details-button')[0] qrButton.click() await timeout(1000) - // qr code item - const qrButton2 = app.find('.dropdown-menu-item')[1] - qrButton2.click() - - await timeout(1000) - - const qrHeader = app.find('.qr-header')[0] - const qrContainer = app.find('#qr-container')[0] + const qrHeader = app.find('.editable-label__value')[0] + const qrContainer = app.find('.qr-wrapper')[0] assert.equal(qrHeader.textContent, 'Account 1', 'Should show account label.') assert.ok(qrContainer, 'QR Container found') await timeout() - const networkMenu = app.find('.network-indicator')[0] + const networkMenu = app.find('.network-component')[0] networkMenu.click() await timeout() @@ -164,4 +156,4 @@ function timeout (time) { return new Promise((resolve, reject) => { setTimeout(resolve, time || 1500) }) -} +} \ No newline at end of file -- cgit From cefe6cded6728ff95d951435430da311356c3b23 Mon Sep 17 00:00:00 2001 From: Thomas Huang Date: Sat, 25 Nov 2017 18:37:12 -0600 Subject: Update to Enzyme 3.2.0 --- test/helper.js | 4 ++++ test/lib/shallow-with-store.js | 15 ++++++++++----- test/unit/components/balance-component-test.js | 2 +- test/unit/components/pending-tx-test.js | 2 +- test/unit/responsive/components/dropdown-test.js | 6 +++--- 5 files changed, 19 insertions(+), 10 deletions(-) (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 index 411aa0455..2a66adb17 100644 --- a/test/lib/shallow-with-store.js +++ b/test/lib/shallow-with-store.js @@ -1,11 +1,16 @@ -const shallow = require('enzyme').shallow +const { shallow, mount } = require('enzyme') -module.exports = shallowWithStore - -function shallowWithStore (component, store) { +exports.shallowWithStore = function shallowWithStore (component, store) { const context = { store, } return shallow(component, { context }) -}; +} + +exports.mountWithStore = function mountWithStore (component, store) { + const context = { + store, + } + return mount(component, { context }) +} diff --git a/test/unit/components/balance-component-test.js b/test/unit/components/balance-component-test.js index a5fededc8..9b1e82acf 100644 --- a/test/unit/components/balance-component-test.js +++ b/test/unit/components/balance-component-test.js @@ -1,7 +1,7 @@ const assert = require('assert') const h = require('react-hyperscript') const { createMockStore } = require('redux-test-utils') -const shallowWithStore = require('../../lib/shallow-with-store') +const { shallowWithStore } = require('../../lib/shallow-with-store') const BalanceComponent = require('../../../ui/app/components/balance-component') const mockState = { metamask: { diff --git a/test/unit/components/pending-tx-test.js b/test/unit/components/pending-tx-test.js index 97cac3216..c6c588e1c 100644 --- a/test/unit/components/pending-tx-test.js +++ b/test/unit/components/pending-tx-test.js @@ -4,7 +4,7 @@ const PendingTx = require('../../../ui/app/components/pending-tx') const ethUtil = require('ethereumjs-util') const { createMockStore } = require('redux-test-utils') -const shallowWithStore = require('../../lib/shallow-with-store') +const { shallowWithStore } = require('../../lib/shallow-with-store') const identities = { abc: {}, def: {} } const mockState = { diff --git a/test/unit/responsive/components/dropdown-test.js b/test/unit/responsive/components/dropdown-test.js index 932b6c752..982d8c6ec 100644 --- a/test/unit/responsive/components/dropdown-test.js +++ b/test/unit/responsive/components/dropdown-test.js @@ -6,7 +6,7 @@ const path = require('path'); const Dropdown = require(path.join(__dirname, '..', '..', '..', '..', 'ui', 'app', 'components', 'dropdowns', 'index.js')).Dropdown; const { createMockStore } = require('redux-test-utils') -const shallowWithStore = require('../../../lib/shallow-with-store') +const { mountWithStore } = require('../../../lib/shallow-with-store') const mockState = { metamask: { @@ -39,7 +39,7 @@ describe('Dropdown components', function () { onClick = sinon.spy(); store = createMockStore(mockState) - component = shallowWithStore(h( + component = mountWithStore(h( Dropdown, dropdownComponentProps, [ @@ -57,7 +57,7 @@ describe('Dropdown components', function () { }, 'Item 2'), ] ), store) - dropdownComponent = component.dive() + dropdownComponent = component }) it('can render two items', function () { -- cgit From ec6c3c33bdbe2d90dc71649d0cc5fb3c07d96af7 Mon Sep 17 00:00:00 2001 From: Dan Date: Tue, 5 Dec 2017 13:11:59 -0330 Subject: Merge branch 'master' into NewUI-flat-merge-with-master --- test/integration/lib/mascara-first-time.js | 59 ++++++++++++------------------ test/unit/metamask-controller-test.js | 33 +++++++++++++++++ 2 files changed, 57 insertions(+), 35 deletions(-) (limited to 'test') diff --git a/test/integration/lib/mascara-first-time.js b/test/integration/lib/mascara-first-time.js index 398ecea0e..515c7f383 100644 --- a/test/integration/lib/mascara-first-time.js +++ b/test/integration/lib/mascara-first-time.js @@ -6,23 +6,7 @@ async function runFirstTimeUsageTest (assert, done) { const app = $('#app-content') - // recurse notices - while (true) { - const button = app.find('button') - if (button.html() === 'Accept') { - // still notices to accept - const termsPage = app.find('.markdown')[0] - termsPage.scrollTop = termsPage.scrollHeight - await timeout() - console.log('Clearing notice') - button.click() - await timeout() - } else { - // exit loop - console.log('No more notices...') - break - } - } + await skipNotices(app) await timeout() @@ -51,28 +35,13 @@ async function runFirstTimeUsageTest (assert, done) { assert.equal(created.textContent, 'Your unique account image', 'unique image screen') // Agree button - const button = app.find('button')[0] + let button = app.find('button')[0] assert.ok(button, 'button present') button.click() await timeout(1000) - // Privacy Screen - const detail = app.find('.tou__title')[0] - assert.equal(detail.textContent, 'Privacy Notice', 'privacy notice screen') - app.find('button').click() - - await timeout(1000) - - - // terms of service screen - const tou = app.find('.tou__title')[0] - assert.equal(tou.textContent, 'Terms of Use', 'terms of use screen') - app.find('.tou__body').scrollTop(100000) - await timeout(1000) - - app.find('.first-time-flow__button').click() - await timeout(1000) + await skipNotices(app) // secret backup phrase const seedTitle = app.find('.backup-phrase__title')[0] @@ -156,4 +125,24 @@ function timeout (time) { return new Promise((resolve, reject) => { setTimeout(resolve, time || 1500) }) -} \ No newline at end of file +} + +async function skipNotices (app) { + while (true) { + const button = app.find('button') + if (button && button.html() === 'Accept') { + // still notices to accept + const termsPage = app.find('.markdown')[0] + if (!termsPage) { + break + } + termsPage.scrollTop = termsPage.scrollHeight + await timeout() + button.click() + await timeout() + } else { + console.log('No more notices...') + break + } + } +} diff --git a/test/unit/metamask-controller-test.js b/test/unit/metamask-controller-test.js index ef6cae758..fd420a70f 100644 --- a/test/unit/metamask-controller-test.js +++ b/test/unit/metamask-controller-test.js @@ -11,6 +11,15 @@ describe('MetaMaskController', function () { unlockAccountMessage: noop, showUnapprovedTx: noop, platform: {}, + encryptor: { + encrypt: function(password, object) { + this.object = object + return Promise.resolve() + }, + decrypt: function () { + return Promise.resolve(this.object) + } + }, // initial state initState: clone(firstTimeState), }) @@ -27,6 +36,30 @@ describe('MetaMaskController', function () { describe('Metamask Controller', function () { assert(metamaskController) + + beforeEach(function () { + sinon.spy(metamaskController.keyringController, 'createNewVaultAndKeychain') + }) + + afterEach(function () { + metamaskController.keyringController.createNewVaultAndKeychain.restore() + }) + + describe('#createNewVaultAndKeychain', function () { + it('can only create new vault on keyringController once', async function () { + + const selectStub = sinon.stub(metamaskController, 'selectFirstIdentity') + + const password = 'a-fake-password' + + const first = await metamaskController.createNewVaultAndKeychain(password) + const second = await metamaskController.createNewVaultAndKeychain(password) + + assert(metamaskController.keyringController.createNewVaultAndKeychain.calledOnce) + + selectStub.reset() + }) + }) }) }) -- cgit From 4acd48966edf2e6cf4ced6e3e0983a44dcb2ec13 Mon Sep 17 00:00:00 2001 From: Dan J Miller Date: Thu, 21 Dec 2017 23:33:01 -0330 Subject: [NewUI] Fixes tests and sends user to NewUI after registering. (#2788) * Fixes tests and sends user to NewUI after registering. * Karma config? * Empty commit * Remove unneeded json state mock file. --- test/base.conf.js | 4 +++- test/unit/actions/tx_test.js | 3 +-- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/base.conf.js b/test/base.conf.js index 122392822..82b9d8eec 100644 --- a/test/base.conf.js +++ b/test/base.conf.js @@ -54,6 +54,8 @@ module.exports = function(config) { // Concurrency level // how many browser should be started simultaneous - concurrency: Infinity + concurrency: 1, + + nocache: true, } } diff --git a/test/unit/actions/tx_test.js b/test/unit/actions/tx_test.js index ea6dfda6a..b6a691860 100644 --- a/test/unit/actions/tx_test.js +++ b/test/unit/actions/tx_test.js @@ -51,9 +51,8 @@ describe('tx confirmation screen', function () { actions.cancelTx({value: firstTxId})((action) => { result = reducers(initialState, action) - done() }) - + done() }) it('should transition to the account detail view', function () { -- cgit