WA-238 Adding tests for safesByOwnerSelector
This commit is contained in:
parent
e3c4c7661d
commit
e25ccbeb6d
|
@ -25,7 +25,7 @@ const balanceReducerTests = () => {
|
|||
expect(balances.get(address)).toBe('0')
|
||||
})
|
||||
|
||||
it('reducer should return 1.3456 ETH as funds to safe with 1 ETH', async () => {
|
||||
it('reducer should return 1.3456 ETH as funds to safe with 1.3456 ETH', async () => {
|
||||
// GIVEN
|
||||
const address = await aDeployedSafe(store)
|
||||
|
||||
|
|
|
@ -44,21 +44,21 @@ class SafeBuilder {
|
|||
const aSafe = () => new SafeBuilder()
|
||||
|
||||
export class SafeFactory {
|
||||
static oneOwnerSafe = aSafe()
|
||||
static oneOwnerSafe = (ownerAddress: string = '0x03db1a8b26d08df23337e9276a36b474510f0023') => aSafe()
|
||||
.withAddress('0x03db1a8b26d08df23337e9276a36b474510f0025')
|
||||
.withName('Adol ICO Safe')
|
||||
.withConfirmations(1)
|
||||
.withDailyLimit(10)
|
||||
.withOwner(['Adol Metamask'], ['0x03db1a8b26d08df23337e9276a36b474510f0023'])
|
||||
.withOwner(['Adol Metamask'], [ownerAddress])
|
||||
.get()
|
||||
|
||||
static twoOwnersSafe = aSafe()
|
||||
static twoOwnersSafe = (firstOwner: string = '0x03db1a8b26d08df23337e9276a36b474510f0023', secondOwner: string = '0x03db1a8b26d08df23337e9276a36b474510f0024') => aSafe()
|
||||
.withAddress('0x03db1a8b26d08df23337e9276a36b474510f0026')
|
||||
.withName('Adol & Tobias Safe')
|
||||
.withConfirmations(2)
|
||||
.withOwner(
|
||||
['Adol Metamask', 'Tobias Metamask'],
|
||||
['0x03db1a8b26d08df23337e9276a36b474510f0023', '0x03db1a8b26d08df23337e9276a36b474510f0024'],
|
||||
[firstOwner, secondOwner],
|
||||
)
|
||||
.withDailyLimit(10, 1.34)
|
||||
.get()
|
||||
|
|
|
@ -54,7 +54,7 @@ const providerReducerTests = () => {
|
|||
const safes = store.getState()[SAFE_REDUCER_ID]
|
||||
|
||||
// THEN
|
||||
expect(safes.get(address)).toEqual(SafeFactory.oneOwnerSafe)
|
||||
expect(safes.get(address)).toEqual(SafeFactory.oneOwnerSafe())
|
||||
})
|
||||
|
||||
it('reducer loads information from localStorage', async () => {
|
||||
|
|
|
@ -28,8 +28,8 @@ const safeSelectorTests = () => {
|
|||
it('should return a list of size 2 when 2 safes are created', () => {
|
||||
// GIVEN
|
||||
let map: Map<string, Safe> = Map()
|
||||
map = map.set('fooAddress', SafeFactory.oneOwnerSafe)
|
||||
map = map.set('barAddress', SafeFactory.twoOwnersSafe)
|
||||
map = map.set('fooAddress', SafeFactory.oneOwnerSafe())
|
||||
map = map.set('barAddress', SafeFactory.twoOwnersSafe())
|
||||
|
||||
const match: Match = buildMathPropsFrom('fooAddress')
|
||||
const undefMatch: Match = buildMathPropsFrom('inventedAddress')
|
||||
|
@ -45,7 +45,7 @@ const safeSelectorTests = () => {
|
|||
const undefinedSafe = safeSelector(reduxStore, { match: undefMatch })
|
||||
|
||||
// THEN
|
||||
expect(oneOwnerSafe).toEqual(SafeFactory.oneOwnerSafe)
|
||||
expect(oneOwnerSafe).toEqual(SafeFactory.oneOwnerSafe())
|
||||
expect(undefinedSafe).toBe(undefined)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -22,7 +22,7 @@ storiesOf('Routes /safes', module)
|
|||
<Component provider="" safes={List([])} />
|
||||
))
|
||||
.add('Safe List whith 2 safes', () => {
|
||||
const safes = List([SafeFactory.oneOwnerSafe, SafeFactory.twoOwnersSafe])
|
||||
const safes = List([SafeFactory.oneOwnerSafe(), SafeFactory.twoOwnersSafe()])
|
||||
return (
|
||||
<Component provider="METAMASK" safes={safes} />
|
||||
)
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
// @flow
|
||||
import { createStructuredSelector } from 'reselect'
|
||||
import { safesListSelector } from '~/routes/safeList/store/selectors'
|
||||
import { safesByOwnerSelector } from '~/routes/safeList/store/selectors'
|
||||
import { providerNameSelector } from '~/wallets/store/selectors/index'
|
||||
|
||||
export default createStructuredSelector({
|
||||
safes: safesListSelector,
|
||||
safes: safesByOwnerSelector,
|
||||
provider: providerNameSelector,
|
||||
})
|
||||
|
|
|
@ -1,7 +1,20 @@
|
|||
// @flow
|
||||
import { List, Map } from 'immutable'
|
||||
import { createSelector, type Selector } from 'reselect'
|
||||
import { type GlobalState } from '~/store/index'
|
||||
import { type Safe } from '~/routes/safe/store/model/safe'
|
||||
import { userAccountSelector } from '~/wallets/store/selectors/index'
|
||||
|
||||
export const safesMapSelector = (state: GlobalState): Map<string, Safe> => state.safes
|
||||
export const safesListSelector = (state: GlobalState): List<Safe> => state.safes.toList()
|
||||
const safesListSelector: Selector<GlobalState, {}, List<Safe>> = createSelector(
|
||||
safesMapSelector,
|
||||
(safes: Map<string, Safe>): List<Safe> => safes.toList(),
|
||||
)
|
||||
|
||||
export const safesByOwnerSelector: Selector<GlobalState, {}, List<Safe>> = createSelector(
|
||||
userAccountSelector,
|
||||
safesListSelector,
|
||||
(userAddress: string, safes: List<Safe>): List<Safe> =>
|
||||
safes.filter((safe: Safe) =>
|
||||
safe.owners.filter(owner => owner.get('address') === userAddress).count() > 0),
|
||||
)
|
||||
|
|
|
@ -2,41 +2,89 @@
|
|||
import { List, Map } from 'immutable'
|
||||
import { SAFE_REDUCER_ID } from '~/routes/safe/store/reducer/safe'
|
||||
import { type Safe } from '~/routes/safe/store/model/safe'
|
||||
import { getProviderInfo } from '~/wallets/getWeb3'
|
||||
import { SafeFactory } from '~/routes/safe/store/test/builder/safe.builder'
|
||||
import { safesListSelector } from '../selectors'
|
||||
import { PROVIDER_REDUCER_ID } from '~/wallets/store/reducer/provider'
|
||||
import { makeProvider, type Provider } from '~/wallets/store/model/provider'
|
||||
import { safesByOwnerSelector } from '../selectors'
|
||||
|
||||
const safesListSelectorTests = () => {
|
||||
describe('Safes Selector[safesSelector]', () => {
|
||||
let walletRecord: Provider
|
||||
beforeEach(async () => {
|
||||
const provider = await getProviderInfo()
|
||||
walletRecord = makeProvider(provider)
|
||||
})
|
||||
|
||||
describe('Safes Selector[safesByOwnerSelector]', () => {
|
||||
it('should return empty list when no safes', () => {
|
||||
// GIVEN
|
||||
const reduxStore = {
|
||||
[PROVIDER_REDUCER_ID]: walletRecord,
|
||||
[SAFE_REDUCER_ID]: Map(),
|
||||
providers: undefined,
|
||||
balances: undefined,
|
||||
}
|
||||
const emptyList = List([])
|
||||
|
||||
// WHEN
|
||||
const safes = safesListSelector(reduxStore)
|
||||
const safes = safesByOwnerSelector(reduxStore, {})
|
||||
|
||||
// THEN
|
||||
expect(safes).toEqual(emptyList)
|
||||
})
|
||||
|
||||
it('should return a list of size 2 when 2 safes are created', () => {
|
||||
it('should return a list of size 0 when 0 of 2 safes contains the user as owner', () => {
|
||||
// GIVEN
|
||||
let map: Map<string, Safe> = Map()
|
||||
map = map.set('fooAddress', SafeFactory.oneOwnerSafe)
|
||||
map = map.set('barAddress', SafeFactory.twoOwnersSafe)
|
||||
map = map.set('fooAddress', SafeFactory.oneOwnerSafe('foo'))
|
||||
map = map.set('barAddress', SafeFactory.twoOwnersSafe('foo', 'bar'))
|
||||
|
||||
const reduxStore = {
|
||||
[PROVIDER_REDUCER_ID]: walletRecord,
|
||||
[SAFE_REDUCER_ID]: map,
|
||||
providers: undefined,
|
||||
balances: undefined,
|
||||
}
|
||||
|
||||
// WHEN
|
||||
const safes = safesListSelector(reduxStore)
|
||||
const safes = safesByOwnerSelector(reduxStore, {})
|
||||
|
||||
// THEN
|
||||
expect(safes.count()).toEqual(0)
|
||||
})
|
||||
|
||||
it('should return a list of size 1 when 1 of 2 safes contains the user as owner', () => {
|
||||
// GIVEN
|
||||
let map: Map<string, Safe> = Map()
|
||||
map = map.set('fooAddress', SafeFactory.oneOwnerSafe(walletRecord.account))
|
||||
map = map.set('barAddress', SafeFactory.twoOwnersSafe('foo', 'bar'))
|
||||
|
||||
const reduxStore = {
|
||||
[PROVIDER_REDUCER_ID]: walletRecord,
|
||||
[SAFE_REDUCER_ID]: map,
|
||||
balances: undefined,
|
||||
}
|
||||
|
||||
// WHEN
|
||||
const safes = safesByOwnerSelector(reduxStore, {})
|
||||
|
||||
// THEN
|
||||
expect(safes.count()).toEqual(1)
|
||||
})
|
||||
|
||||
it('should return a list of size 2 when 2 of 2 safes contains the user as owner', () => {
|
||||
// GIVEN
|
||||
let map: Map<string, Safe> = Map()
|
||||
const userAccount = walletRecord.account
|
||||
map = map.set('fooAddress', SafeFactory.oneOwnerSafe(userAccount))
|
||||
map = map.set('barAddress', SafeFactory.twoOwnersSafe('foo', userAccount))
|
||||
|
||||
const reduxStore = {
|
||||
[SAFE_REDUCER_ID]: map,
|
||||
[PROVIDER_REDUCER_ID]: walletRecord,
|
||||
balances: undefined,
|
||||
}
|
||||
|
||||
// WHEN
|
||||
const safes = safesByOwnerSelector(reduxStore, {})
|
||||
|
||||
// THEN
|
||||
expect(safes.count()).toEqual(2)
|
||||
|
|
Loading…
Reference in New Issue