Skip to content

Commit fef0ae8

Browse files
feat: all the tests
1 parent f44a3e0 commit fef0ae8

File tree

3 files changed

+55
-3
lines changed

3 files changed

+55
-3
lines changed

src/ConnectionManager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,10 @@ export class ConnectionManager {
9494
chainId: ChainId
9595
): AbstractConnector {
9696
switch (providerType) {
97-
case ProviderType.INJECTED:
98-
return new InjectedConnector(chainId)
9997
case ProviderType.FORTMATIC:
10098
return new FortmaticConnector(chainId)
99+
case ProviderType.INJECTED:
100+
return new InjectedConnector(chainId)
101101
case ProviderType.WALLET_CONNECT:
102102
return new WalletConnectConnector(chainId)
103103
default:

test/ConnectionManager.spec.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ import chaiAsPromised from 'chai-as-promised'
33
import sinon from 'sinon'
44
import { getConfiguration } from '../src/configuration'
55
import { ConnectionManager, connection } from '../src/ConnectionManager'
6+
import {
7+
FortmaticConnector,
8+
InjectedConnector,
9+
WalletConnectConnector
10+
} from '../src/connectors'
611
import { LocalStorage } from '../src/storage'
712
import { ChainId, ClosableConnector, ProviderType } from '../src/types'
813
import { StubClosableConnector, StubConnector, StubStorage } from './utils'
@@ -238,6 +243,7 @@ describe('ConnectionManager', () => {
238243
})
239244

240245
it('should throw if no successful connect occurred', () => {
246+
connectionManager.connector = undefined
241247
expect(connectionManager.getProvider()).to.eventually.throw(
242248
new Error('No valid connector found. Please .connect() first')
243249
)
@@ -265,4 +271,40 @@ describe('ConnectionManager', () => {
265271
browser.window = undefined
266272
})
267273
})
274+
275+
describe('#getConnector', () => {
276+
it('should throw if an invalid provider type is supplied', () => {
277+
const providerType = 'Invalid Provider Type' as any
278+
expect(() =>
279+
connectionManager.getConnector(providerType, ChainId.MAINNET)
280+
).to.throw(`Invalid provider ${providerType}`)
281+
})
282+
283+
it('should return an instance of FortmaticConnector for the supplied chain', () => {
284+
const connector = connectionManager.getConnector(
285+
ProviderType.FORTMATIC,
286+
ChainId.KOVAN
287+
)
288+
expect(connector).to.be.instanceOf(FortmaticConnector)
289+
expect(connector.getChainId()).to.eventually.eq(ChainId.KOVAN)
290+
})
291+
292+
it('should return an instance of InjectedConnector for the supplied chain', () => {
293+
const connector = connectionManager.getConnector(
294+
ProviderType.INJECTED,
295+
ChainId.KOVAN
296+
)
297+
expect(connector).to.be.instanceOf(InjectedConnector)
298+
expect(connector.getChainId()).to.eventually.eq(ChainId.KOVAN)
299+
})
300+
301+
it('should return an instance of WalletConnectConnector for the supplied chain', () => {
302+
const connector = connectionManager.getConnector(
303+
ProviderType.WALLET_CONNECT,
304+
ChainId.KOVAN
305+
)
306+
expect(connector).to.be.instanceOf(WalletConnectConnector)
307+
expect(connector.getChainId()).to.eventually.eq(ChainId.KOVAN)
308+
})
309+
})
268310
})

test/storage.spec.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ describe('LocalStorage', () => {
77
const browser: any = global
88
const windowLocalStorage = {
99
getItem: (_key: string) => {},
10-
setItem: (_key: string, _value: any) => {}
10+
setItem: (_key: string, _value: any) => {},
11+
clear: () => {}
1112
}
1213
let mockStorage: Sinon.SinonMock
1314

@@ -67,4 +68,13 @@ describe('LocalStorage', () => {
6768
localStorage.set(key, value)
6869
})
6970
})
71+
72+
describe('#clear', () => {
73+
it('should call the window localStorage clear method', () => {
74+
mockStorage.expects('clear').once()
75+
76+
const localStorage = new LocalStorage()
77+
localStorage.clear()
78+
})
79+
})
7080
})

0 commit comments

Comments
 (0)