aboutsummaryrefslogtreecommitdiffstats
path: root/test/unit
diff options
context:
space:
mode:
authorfrankiebee <frankie.diamond@gmail.com>2018-04-20 02:49:11 +0800
committerfrankiebee <frankie.diamond@gmail.com>2018-04-20 02:49:11 +0800
commitc20c97ce625207c7afcd48a12f6e7891d582ae99 (patch)
treeb5e063ee7cfd0d0e99fcdb0409fe3106c010bf79 /test/unit
parenteeb9390de81ce6fc92247d5c499e991dce8330bd (diff)
parent00efcf9e8ba34d448b628c98d32ad12d5be2ffc9 (diff)
downloadtangerine-wallet-browser-c20c97ce625207c7afcd48a12f6e7891d582ae99.tar
tangerine-wallet-browser-c20c97ce625207c7afcd48a12f6e7891d582ae99.tar.gz
tangerine-wallet-browser-c20c97ce625207c7afcd48a12f6e7891d582ae99.tar.bz2
tangerine-wallet-browser-c20c97ce625207c7afcd48a12f6e7891d582ae99.tar.lz
tangerine-wallet-browser-c20c97ce625207c7afcd48a12f6e7891d582ae99.tar.xz
tangerine-wallet-browser-c20c97ce625207c7afcd48a12f6e7891d582ae99.tar.zst
tangerine-wallet-browser-c20c97ce625207c7afcd48a12f6e7891d582ae99.zip
Merge branch 'master' into tx-controller-rewrite-v3
Diffstat (limited to 'test/unit')
-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
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' })
+ })
+})