aboutsummaryrefslogtreecommitdiffstats
path: root/test/unit
diff options
context:
space:
mode:
authorDan Finlay <542863+danfinlay@users.noreply.github.com>2018-04-18 04:36:21 +0800
committerGitHub <noreply@github.com>2018-04-18 04:36:21 +0800
commit6ee57dcad70057b1f71b9abe53d9d4965cbbe3e8 (patch)
tree096c6a8f7e12c5ece8bb64af1466bb2d94b6e5d3 /test/unit
parentf15b81089e86dc095983faeba4a97209ddd670ce (diff)
parent7b70804aa0d74120098a4bcb2c375d29080e8368 (diff)
downloadtangerine-wallet-browser-6ee57dcad70057b1f71b9abe53d9d4965cbbe3e8.tar
tangerine-wallet-browser-6ee57dcad70057b1f71b9abe53d9d4965cbbe3e8.tar.gz
tangerine-wallet-browser-6ee57dcad70057b1f71b9abe53d9d4965cbbe3e8.tar.bz2
tangerine-wallet-browser-6ee57dcad70057b1f71b9abe53d9d4965cbbe3e8.tar.lz
tangerine-wallet-browser-6ee57dcad70057b1f71b9abe53d9d4965cbbe3e8.tar.xz
tangerine-wallet-browser-6ee57dcad70057b1f71b9abe53d9d4965cbbe3e8.tar.zst
tangerine-wallet-browser-6ee57dcad70057b1f71b9abe53d9d4965cbbe3e8.zip
Merge branch 'master' into i3580-InternationalizeCurrency
Diffstat (limited to 'test/unit')
-rw-r--r--test/unit/ComposableObservableStore.js35
-rw-r--r--test/unit/token-rates-controller.js29
2 files changed, 64 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/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' })
+ })
+})