diff options
author | tmashuang <thomas.b.huang@gmail.com> | 2018-05-21 20:59:26 +0800 |
---|---|---|
committer | tmashuang <thomas.b.huang@gmail.com> | 2018-05-21 20:59:26 +0800 |
commit | 13ebb0b455bc775a53b6bb30e675a39d02d8f6f5 (patch) | |
tree | 8e746281051ff1f75b948d89e1053c8da2ffc2cd /test/unit/app/controllers/network-contoller-test.js | |
parent | f279a8e61a3f50326fe9f26b0b860af47cd662fb (diff) | |
download | tangerine-wallet-browser-13ebb0b455bc775a53b6bb30e675a39d02d8f6f5.tar.gz tangerine-wallet-browser-13ebb0b455bc775a53b6bb30e675a39d02d8f6f5.tar.zst tangerine-wallet-browser-13ebb0b455bc775a53b6bb30e675a39d02d8f6f5.zip |
Moved loose some loose test files to sub folders
Diffstat (limited to 'test/unit/app/controllers/network-contoller-test.js')
-rw-r--r-- | test/unit/app/controllers/network-contoller-test.js | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/test/unit/app/controllers/network-contoller-test.js b/test/unit/app/controllers/network-contoller-test.js new file mode 100644 index 000000000..789850ef3 --- /dev/null +++ b/test/unit/app/controllers/network-contoller-test.js @@ -0,0 +1,102 @@ +const assert = require('assert') +const nock = require('nock') +const NetworkController = require('../../../../app/scripts/controllers/network') +const { + getNetworkDisplayName, +} = require('../../../../app/scripts/controllers/network/util') + +const { createTestProviderTools } = require('../../../stub/provider') +const providerResultStub = {} + +describe('# Network Controller', function () { + let networkController + const noop = () => {} + const networkControllerProviderConfig = { + getAccounts: noop, + } + + beforeEach(function () { + + nock('https://rinkeby.infura.io') + .persist() + .post('/metamask') + .reply(200) + + networkController = new NetworkController() + + networkController.initializeProvider(networkControllerProviderConfig) + }) + + afterEach(function () { + nock.cleanAll() + }) + + describe('network', function () { + describe('#provider', function () { + it('provider should be updatable without reassignment', function () { + networkController.initializeProvider(networkControllerProviderConfig) + const proxy = networkController._proxy + proxy.setTarget({ test: true, on: () => {} }) + assert.ok(proxy.test) + }) + }) + describe('#getNetworkState', function () { + it('should return loading when new', function () { + const networkState = networkController.getNetworkState() + assert.equal(networkState, 'loading', 'network is loading') + }) + }) + + describe('#setNetworkState', function () { + it('should update the network', function () { + networkController.setNetworkState(1) + const networkState = networkController.getNetworkState() + assert.equal(networkState, 1, 'network is 1') + }) + }) + + describe('#setProviderType', function () { + it('should update provider.type', function () { + networkController.setProviderType('mainnet') + const type = networkController.getProviderConfig().type + assert.equal(type, 'mainnet', 'provider type is updated') + }) + it('should set the network to loading', function () { + networkController.setProviderType('mainnet') + const loading = networkController.isNetworkLoading() + assert.ok(loading, 'network is loading') + }) + }) + }) +}) + +describe('Network utils', () => { + it('getNetworkDisplayName should return the correct network name', () => { + const tests = [ + { + input: 3, + expected: 'Ropsten', + }, { + input: 4, + expected: 'Rinkeby', + }, { + input: 42, + expected: 'Kovan', + }, { + input: 'ropsten', + expected: 'Ropsten', + }, { + input: 'rinkeby', + expected: 'Rinkeby', + }, { + input: 'kovan', + expected: 'Kovan', + }, { + input: 'mainnet', + expected: 'Main Ethereum Network', + }, + ] + + tests.forEach(({ input, expected }) => assert.equal(getNetworkDisplayName(input), expected)) + }) +}) |