diff options
Merge branch 'master' into testing
Diffstat (limited to 'test/unit')
-rw-r--r-- | test/unit/ComposableObservableStore.js | 35 | ||||
-rw-r--r-- | test/unit/balance-formatter-test.js | 27 | ||||
-rw-r--r-- | test/unit/token-rates-controller.js | 29 |
3 files changed, 91 insertions, 0 deletions
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' }) + }) +}) |