aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorThomas <tmashuang@gmail.com>2018-04-24 02:22:24 +0800
committerThomas <tmashuang@gmail.com>2018-04-24 02:22:24 +0800
commit010092312998e90688e1bfb004eb55c67a337429 (patch)
tree93a174b2eb7074283d6e43bcc98bc1f2c7925d57 /test
parentddece0cc11215b323df96287f39e6758aa559f77 (diff)
parent74c419f9b65841c2966d1fe3b7414bf11e09e0d8 (diff)
downloadtangerine-wallet-browser-010092312998e90688e1bfb004eb55c67a337429.tar
tangerine-wallet-browser-010092312998e90688e1bfb004eb55c67a337429.tar.gz
tangerine-wallet-browser-010092312998e90688e1bfb004eb55c67a337429.tar.bz2
tangerine-wallet-browser-010092312998e90688e1bfb004eb55c67a337429.tar.lz
tangerine-wallet-browser-010092312998e90688e1bfb004eb55c67a337429.tar.xz
tangerine-wallet-browser-010092312998e90688e1bfb004eb55c67a337429.tar.zst
tangerine-wallet-browser-010092312998e90688e1bfb004eb55c67a337429.zip
Merge branch 'master' into testing
Diffstat (limited to 'test')
-rw-r--r--test/integration/lib/currency-localization.js28
-rw-r--r--test/integration/lib/send-new-ui.js8
-rw-r--r--test/integration/lib/tx-list-items.js2
-rw-r--r--test/setup.js5
-rw-r--r--test/unit/ComposableObservableStore.js35
-rw-r--r--test/unit/balance-formatter-test.js27
-rw-r--r--test/unit/token-rates-controller.js29
7 files changed, 129 insertions, 5 deletions
diff --git a/test/integration/lib/currency-localization.js b/test/integration/lib/currency-localization.js
new file mode 100644
index 000000000..7705c9720
--- /dev/null
+++ b/test/integration/lib/currency-localization.js
@@ -0,0 +1,28 @@
+const reactTriggerChange = require('../../lib/react-trigger-change')
+const {
+ timeout,
+ queryAsync,
+ findAsync,
+} = require('../../lib/util')
+
+QUnit.module('currency localization')
+
+QUnit.test('renders localized currency', (assert) => {
+ const done = assert.async()
+ runCurrencyLocalizationTest(assert).then(done).catch((err) => {
+ assert.notOk(err, `Error was thrown: ${err.stack}`)
+ done()
+ })
+})
+
+async function runCurrencyLocalizationTest(assert, done) {
+ console.log('*** start runCurrencyLocalizationTest')
+ const selectState = await queryAsync($, 'select')
+ selectState.val('currency localization')
+ reactTriggerChange(selectState[0])
+ await timeout(1000)
+ const txView = await queryAsync($, '.tx-view')
+ const heroBalance = await findAsync($(txView), '.hero-balance')
+ const fiatAmount = await findAsync($(heroBalance), '.fiat-amount')
+ assert.equal(fiatAmount[0].textContent, '₱102,707.97')
+}
diff --git a/test/integration/lib/send-new-ui.js b/test/integration/lib/send-new-ui.js
index 4731117d7..09a074750 100644
--- a/test/integration/lib/send-new-ui.js
+++ b/test/integration/lib/send-new-ui.js
@@ -91,7 +91,7 @@ async function runSendFlowTest(assert, done) {
)
assert.equal(
sendGasField.find('.currency-display__converted-value')[0].textContent,
- '0.24 USD',
+ '$0.24 USD',
'send gas field should show estimated gas total converted to USD'
)
@@ -118,7 +118,7 @@ async function runSendFlowTest(assert, done) {
)
assert.equal(
(await findAsync(sendGasField, '.currency-display__converted-value'))[0].textContent,
- '3.60 USD',
+ '$3.60 USD',
'send gas field should show customized gas total converted to USD'
)
@@ -138,9 +138,9 @@ async function runSendFlowTest(assert, done) {
const confirmScreenRows = await queryAsync($, '.confirm-screen-rows')
const confirmScreenGas = confirmScreenRows.find('.currency-display__converted-value')[0]
- assert.equal(confirmScreenGas.textContent, '3.60 USD', 'confirm screen should show correct gas')
+ assert.equal(confirmScreenGas.textContent, '$3.60 USD', 'confirm screen should show correct gas')
const confirmScreenTotal = confirmScreenRows.find('.confirm-screen-row-info')[2]
- assert.equal(confirmScreenTotal.textContent, '2405.36 USD', 'confirm screen should show correct total')
+ assert.equal(confirmScreenTotal.textContent, '$2,405.36 USD', 'confirm screen should show correct total')
const confirmScreenBackButton = await queryAsync($, '.page-container__back-button')
confirmScreenBackButton[0].click()
diff --git a/test/integration/lib/tx-list-items.js b/test/integration/lib/tx-list-items.js
index d0056eb94..0c0c5a77f 100644
--- a/test/integration/lib/tx-list-items.js
+++ b/test/integration/lib/tx-list-items.js
@@ -53,7 +53,7 @@ async function runTxListItemsTest(assert, done) {
const confirmedTokenTx = txListItems[6]
const confirmedTokenTxAddress = await findAsync($(confirmedTokenTx), '.tx-list-account')
- assert.equal(confirmedTokenTxAddress[0].textContent, '0xe7884118...81a9', 'confirmedTokenTx has correct address')
+ assert.equal(confirmedTokenTxAddress[0].textContent, '0xE7884118...81a9', 'confirmedTokenTx has correct address')
const rejectedTx = txListItems[7]
const rejectedTxRenderedStatus = await findAsync($(rejectedTx), '.tx-list-status')
diff --git a/test/setup.js b/test/setup.js
new file mode 100644
index 000000000..8e7965a37
--- /dev/null
+++ b/test/setup.js
@@ -0,0 +1,5 @@
+require('babel-register')({
+ ignore: name => name.includes('node_modules') && !name.includes('obs-store'),
+})
+
+require('./helper')
diff --git a/test/unit/ComposableObservableStore.js b/test/unit/ComposableObservableStore.js
new file mode 100644
index 000000000..3fba200c1
--- /dev/null
+++ b/test/unit/ComposableObservableStore.js
@@ -0,0 +1,35 @@
+const assert = require('assert')
+const ComposableObservableStore = require('../../app/scripts/lib/ComposableObservableStore')
+const ObservableStore = require('obs-store')
+
+describe('ComposableObservableStore', () => {
+ it('should register initial state', () => {
+ const store = new ComposableObservableStore('state')
+ assert.strictEqual(store.getState(), 'state')
+ })
+
+ it('should register initial structure', () => {
+ const testStore = new ObservableStore()
+ const store = new ComposableObservableStore(null, { TestStore: testStore })
+ testStore.putState('state')
+ assert.deepEqual(store.getState(), { TestStore: 'state' })
+ })
+
+ it('should update structure', () => {
+ const testStore = new ObservableStore()
+ const store = new ComposableObservableStore()
+ store.updateStructure({ TestStore: testStore })
+ testStore.putState('state')
+ assert.deepEqual(store.getState(), { TestStore: 'state' })
+ })
+
+ it('should return flattened state', () => {
+ const fooStore = new ObservableStore({ foo: 'foo' })
+ const barStore = new ObservableStore({ bar: 'bar' })
+ const store = new ComposableObservableStore(null, {
+ FooStore: fooStore,
+ BarStore: barStore,
+ })
+ assert.deepEqual(store.getFlatState(), { foo: 'foo', bar: 'bar' })
+ })
+})
diff --git a/test/unit/balance-formatter-test.js b/test/unit/balance-formatter-test.js
new file mode 100644
index 000000000..ab6daa19c
--- /dev/null
+++ b/test/unit/balance-formatter-test.js
@@ -0,0 +1,27 @@
+const assert = require('assert')
+const currencyFormatter = require('currency-formatter')
+const infuraConversion = require('../../ui/app/infura-conversion.json')
+
+describe('currencyFormatting', function () {
+ it('be able to format any infura currency', function (done) {
+ const number = 10000
+
+ infuraConversion.objects.forEach((conversion) => {
+ const code = conversion.quote.code.toUpperCase()
+ const result = currencyFormatter.format(number, { code })
+
+ switch (code) {
+ case 'USD':
+ assert.equal(result, '$10,000.00')
+ break
+ case 'JPY':
+ assert.equal(result, '¥10,000')
+ break
+ default:
+ assert.ok(result, `Currency ${code} formatted as ${result}`)
+ }
+ })
+
+ done()
+ })
+})
diff --git a/test/unit/token-rates-controller.js b/test/unit/token-rates-controller.js
new file mode 100644
index 000000000..a49547313
--- /dev/null
+++ b/test/unit/token-rates-controller.js
@@ -0,0 +1,29 @@
+const assert = require('assert')
+const sinon = require('sinon')
+const TokenRatesController = require('../../app/scripts/controllers/token-rates')
+const ObservableStore = require('obs-store')
+
+describe('TokenRatesController', () => {
+ it('should listen for preferences store updates', () => {
+ const preferences = new ObservableStore({ tokens: [] })
+ const controller = new TokenRatesController({ preferences })
+ preferences.putState({ tokens: ['foo'] })
+ assert.deepEqual(controller._tokens, ['foo'])
+ })
+
+ it('should poll on correct interval', async () => {
+ const stub = sinon.stub(global, 'setInterval')
+ new TokenRatesController({ interval: 1337 }) // eslint-disable-line no-new
+ assert.strictEqual(stub.getCall(0).args[1], 1337)
+ stub.restore()
+ })
+
+ it('should fetch each token rate based on address', async () => {
+ const controller = new TokenRatesController()
+ controller.isActive = true
+ controller.fetchExchangeRate = address => address
+ controller.tokens = [{ address: 'foo' }, { address: 'bar' }]
+ await controller.updateExchangeRates()
+ assert.deepEqual(controller.store.getState().contractExchangeRates, { foo: 'foo', bar: 'bar' })
+ })
+})