-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
67 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,107 +1,111 @@ | ||
import { WalletState } from 'decentraland-dapps/dist/modules/wallet/reducer' | ||
import { RootState } from 'modules/common/types' | ||
import { getExternalNames, getExternalNamesForConnectedWallet } from './selectors' | ||
import { getExternalNames, getExternalNamesForConnectedWallet, getExternalNamesForWallet } from './selectors' | ||
import { ENSState } from './reducer' | ||
|
||
let state: RootState | ||
let wallet: string | ||
let wallet1: string | ||
let wallet2: string | ||
let externalNames: ENSState['externalNames'] | ||
|
||
beforeEach(() => { | ||
state = {} as RootState | ||
wallet = '0x123' | ||
wallet1 = '0x123' | ||
wallet2 = '0x456' | ||
externalNames = { | ||
'name1.eth': { | ||
domain: 'name1.eth', | ||
nftOwnerAddress: wallet | ||
nftOwnerAddress: wallet1 | ||
}, | ||
'name2.eth': { | ||
domain: 'name2.eth', | ||
nftOwnerAddress: wallet | ||
nftOwnerAddress: wallet1 | ||
}, | ||
'name3.eth': { | ||
domain: 'name2.eth', | ||
nftOwnerAddress: '0xOtherWallet' | ||
domain: 'name3.eth', | ||
nftOwnerAddress: wallet2 | ||
} | ||
} as unknown as ENSState['externalNames'] | ||
|
||
state = { | ||
ens: { | ||
externalNames | ||
}, | ||
wallet: { | ||
data: { | ||
address: wallet1 | ||
} | ||
} | ||
} as RootState | ||
}) | ||
|
||
describe('when getting the external names', () => { | ||
beforeEach(() => { | ||
state = { | ||
ens: { | ||
externalNames | ||
} as ENSState | ||
} as RootState | ||
}) | ||
|
||
it('should return a record of external names by domain', () => { | ||
expect(getExternalNames(state)).toEqual(externalNames) | ||
}) | ||
}) | ||
|
||
describe('when getting the external names by wallet', () => { | ||
describe('when the external names has an entry for the wallet', () => { | ||
beforeEach(() => { | ||
state = { | ||
ens: { | ||
externalNames | ||
} as ENSState, | ||
wallet: { | ||
data: { | ||
address: wallet | ||
describe('when getting the external names for the connected wallet', () => { | ||
describe('when there is a connected wallet', () => { | ||
describe('when the external names has an entry for the connected wallet', () => { | ||
it('should return the names of the wallet', () => { | ||
expect(getExternalNamesForConnectedWallet(state)).toEqual([ | ||
{ | ||
domain: 'name1.eth', | ||
nftOwnerAddress: wallet1 | ||
}, | ||
{ | ||
domain: 'name2.eth', | ||
nftOwnerAddress: wallet1 | ||
} | ||
} as WalletState | ||
} as RootState | ||
]) | ||
}) | ||
}) | ||
|
||
it('should return the names of the wallet', () => { | ||
expect(getExternalNamesForConnectedWallet(state)).toEqual([ | ||
{ | ||
domain: 'name1.eth', | ||
nftOwnerAddress: wallet | ||
}, | ||
{ | ||
domain: 'name2.eth', | ||
nftOwnerAddress: wallet | ||
} | ||
]) | ||
describe('when the external names does not have an entry for the connected wallet', () => { | ||
beforeEach(() => { | ||
state.ens.externalNames = {} | ||
}) | ||
|
||
it('should return an empty array', () => { | ||
expect(getExternalNamesForConnectedWallet(state)).toEqual([]) | ||
}) | ||
}) | ||
}) | ||
|
||
describe('when the external names does not have an entry for the wallet', () => { | ||
describe('when there is no connected wallet', () => { | ||
beforeEach(() => { | ||
state = { | ||
ens: { | ||
externalNames: {} | ||
} as ENSState, | ||
wallet: { | ||
data: { | ||
address: wallet | ||
} | ||
} as WalletState | ||
} as RootState | ||
state.wallet.data && (state.wallet.data = null) | ||
}) | ||
|
||
it('should return an empty array', () => { | ||
expect(getExternalNamesForConnectedWallet(state)).toEqual([]) | ||
}) | ||
}) | ||
}) | ||
|
||
describe('when there is no wallet', () => { | ||
beforeEach(() => { | ||
state = { | ||
ens: { | ||
externalNames | ||
} as ENSState, | ||
wallet: { | ||
data: null | ||
} as WalletState | ||
} as RootState | ||
describe('when getting the external names for a provided wallet', () => { | ||
describe('when getting the names for wallet1', () => { | ||
it('should return the external names of wallet1', () => { | ||
expect(getExternalNamesForWallet(wallet1)(state)).toEqual([ | ||
{ | ||
domain: 'name1.eth', | ||
nftOwnerAddress: wallet1 | ||
}, | ||
{ | ||
domain: 'name2.eth', | ||
nftOwnerAddress: wallet1 | ||
} | ||
]) | ||
}) | ||
}) | ||
|
||
it('should return an empty array', () => { | ||
expect(getExternalNamesForConnectedWallet(state)).toEqual([]) | ||
describe('when getting the names for wallet2', () => { | ||
it('should return the external names of wallet2', () => { | ||
expect(getExternalNamesForWallet(wallet2)(state)).toEqual([ | ||
{ | ||
domain: 'name3.eth', | ||
nftOwnerAddress: wallet2 | ||
} | ||
]) | ||
}) | ||
}) | ||
}) |