2020-01-09 04:34:58 +01:00
|
|
|
import assert from 'assert'
|
|
|
|
import sinon from 'sinon'
|
|
|
|
import ObservableStore from 'obs-store'
|
2020-08-18 21:18:25 +02:00
|
|
|
import TokenRatesController from '../../../../app/scripts/controllers/token-rates'
|
2018-04-16 17:21:06 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('TokenRatesController', function () {
|
|
|
|
it('should listen for preferences store updates', function () {
|
2018-04-16 17:21:06 +02:00
|
|
|
const preferences = new ObservableStore({ tokens: [] })
|
|
|
|
preferences.putState({ tokens: ['foo'] })
|
2020-06-10 21:53:37 +02:00
|
|
|
const controller = new TokenRatesController({ preferences })
|
2018-04-16 17:21:06 +02:00
|
|
|
assert.deepEqual(controller._tokens, ['foo'])
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should poll on correct interval', async function () {
|
2018-04-16 17:21:06 +02:00
|
|
|
const stub = sinon.stub(global, 'setInterval')
|
2020-06-10 21:53:37 +02:00
|
|
|
const preferences = new ObservableStore({ tokens: [] })
|
|
|
|
preferences.putState({ tokens: ['foo'] })
|
|
|
|
const controller = new TokenRatesController({ preferences })
|
|
|
|
controller.start(1337)
|
2020-06-05 20:36:55 +02:00
|
|
|
|
2018-04-16 17:21:06 +02:00
|
|
|
assert.strictEqual(stub.getCall(0).args[1], 1337)
|
|
|
|
stub.restore()
|
2020-06-10 21:53:37 +02:00
|
|
|
controller.stop()
|
2018-04-16 17:21:06 +02:00
|
|
|
})
|
|
|
|
})
|