aboutsummaryrefslogtreecommitdiffstats
path: root/test/unit
diff options
context:
space:
mode:
authorChi Kei Chan <chikeichan@gmail.com>2018-01-20 07:29:36 +0800
committerChi Kei Chan <chikeichan@gmail.com>2018-01-20 07:29:36 +0800
commit77c545336b38aefc6105cde1799b18066df8bef9 (patch)
tree121a140131c8cb1f4b746d8f37d4a403b0910aad /test/unit
parent98b5a62fa74aa6730a25df28dfe5032cfb487697 (diff)
parent4e63924e607a07f94ff0a741a036ab352b0b7a3f (diff)
downloadtangerine-wallet-browser-77c545336b38aefc6105cde1799b18066df8bef9.tar
tangerine-wallet-browser-77c545336b38aefc6105cde1799b18066df8bef9.tar.gz
tangerine-wallet-browser-77c545336b38aefc6105cde1799b18066df8bef9.tar.bz2
tangerine-wallet-browser-77c545336b38aefc6105cde1799b18066df8bef9.tar.lz
tangerine-wallet-browser-77c545336b38aefc6105cde1799b18066df8bef9.tar.xz
tangerine-wallet-browser-77c545336b38aefc6105cde1799b18066df8bef9.tar.zst
tangerine-wallet-browser-77c545336b38aefc6105cde1799b18066df8bef9.zip
Merge branch 'uat' into newmaster
Diffstat (limited to 'test/unit')
-rw-r--r--test/unit/actions/tx_test.js3
-rw-r--r--test/unit/components/balance-component-test.js45
-rw-r--r--test/unit/components/pending-tx-test.js92
-rw-r--r--test/unit/pending-tx-test.js1
-rw-r--r--test/unit/responsive/components/dropdown-test.js116
5 files changed, 126 insertions, 131 deletions
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 () {
diff --git a/test/unit/components/balance-component-test.js b/test/unit/components/balance-component-test.js
new file mode 100644
index 000000000..9b1e82acf
--- /dev/null
+++ b/test/unit/components/balance-component-test.js
@@ -0,0 +1,45 @@
+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 () {
+ 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.instance().getTokenBalance(formattedBalance, false)
+ const fiatDisplayNumber = balanceComponent.instance().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.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..c6c588e1c 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 cb29ddafd..f0b4e3bfc 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..982d8c6ec 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 { mountWithStore } = 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 = mountWithStore(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
+ })
- 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);
});
});