Skip to content

Commit

Permalink
Replaced metadata actions/reducers with new app actions architecture (C…
Browse files Browse the repository at this point in the history
…ityOfZion#575)

* Updated HOC's to accept options, and fixed progress prop for batches

* Replaced getBlockHeight/setBlockHeight/syncBlockHeight with new action creator

* Added alreadyLoaded progress strategy

* Replaced settings module with actions and HOC's

* Fixed storage functions to behave as promises

* Add error logging when a request or batch fails

* Fixed withData to pass props to mapping function

* Fixed unintended component insantiation on each render

* Fixed token modal with new action data
  • Loading branch information
mhuggins committed Feb 22, 2018
1 parent ef7c49a commit 80a5cc7
Show file tree
Hide file tree
Showing 46 changed files with 381 additions and 582 deletions.
27 changes: 14 additions & 13 deletions __tests__/components/App.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,29 @@ import { LOADED } from '../../app/values/state'

const initialState = {
api: {
APP: {
batch: true,
mapping: ['NETWORK', 'SETTINGS']
},
NETWORK: {
batch: false,
state: LOADED,
data: MAIN_NETWORK_ID
data: MAIN_NETWORK_ID,
loadedCount: 1
},
SETTINGS: {
batch: false,
state: LOADED,
data: {},
loadedCount: 1
}
},
account: {
},
metadata: {
},
wallet: {
transactions: []
},
modal: {

},
price: {
NEO: 40.5,
Expand All @@ -52,15 +60,8 @@ const setup = (state, shallowRender = true) => {
describe('App', () => {
test('app initializes settings', (done) => {
storage.get = jest.fn((key, callback) => {
const receivedKeys = []
receivedKeys[key] = true

storage.get = jest.fn((key, callback) => {
receivedKeys[key] = true
expect(receivedKeys['settings']).toEqual(true)
expect(receivedKeys['userWallet']).toEqual(true)
done()
})
expect(key).toEqual('userWallet')
done()
})
setup(initialState, false)
})
Expand Down
5 changes: 5 additions & 0 deletions __tests__/components/Claim.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ const initialState = {
batch: false,
state: LOADED,
data: MAIN_NETWORK_ID
},
SETTINGS: {
batch: false,
state: LOADED,
data: {}
}
},
claim: {
Expand Down
7 changes: 5 additions & 2 deletions __tests__/components/TransactionHistory.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,18 @@ const initialState = {
batch: false,
state: LOADED,
data: MAIN_NETWORK_ID
},
SETTINGS: {
batch: false,
state: LOADED,
data: {}
}
},
account: {
loggedIn: true,
wif: 'L4SLRcPgqNMAMwM3nFSxnh36f1v5omjPg3Ewy1tg2PnEon8AcHou',
address: 'AWy7RNBVr9vDadRMK9p7i7Z1tL7GrLAxoh'
},
metadata: {
},
wallet: {
transactions: []
},
Expand Down
30 changes: 15 additions & 15 deletions __tests__/components/WalletInfo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as neonjs from 'neon-js'
import { Provider } from 'react-redux'
import configureStore from 'redux-mock-store'
import thunk from 'redux-thunk'
import { merge } from 'lodash'
import { mount, shallow } from 'enzyme'

import {
Expand All @@ -11,7 +12,6 @@ import {
} from '../../app/modules/wallet'
import { SHOW_NOTIFICATION } from '../../app/modules/notifications'
import { LOADING_TRANSACTIONS } from '../../app/modules/transactions'
import { SET_HEIGHT } from '../../app/modules/metadata'

import { DEFAULT_CURRENCY_CODE, MAIN_NETWORK_ID } from '../../app/core/constants'
import { LOADED } from '../../app/values/state'
Expand Down Expand Up @@ -53,6 +53,13 @@ const initialState = {
batch: false,
state: LOADED,
data: MAIN_NETWORK_ID
},
SETTINGS: {
batch: false,
state: LOADED,
data: {
currency: DEFAULT_CURRENCY_CODE
}
}
},
account: {
Expand All @@ -67,8 +74,7 @@ const initialState = {
},
price: {
NEO: 25.48,
GAS: 18.1,
currency: DEFAULT_CURRENCY_CODE
GAS: 18.1
},
claim: {
claimAmount: 0.5
Expand Down Expand Up @@ -141,24 +147,18 @@ describe('WalletInfo', () => {
isLoadingTransactions: true
}
})
expect(actions[1]).toEqual({
expect(actions[2]).toEqual({
type: LOADING_TRANSACTIONS,
payload: {
isLoadingTransactions: false
}
})
expect(actions[2]).toEqual({
expect(actions[3]).toEqual({
type: SET_TRANSACTION_HISTORY,
payload: {
transactions: []
}
})
expect(actions[3]).toEqual({
type: SET_HEIGHT,
payload: {
blockHeight: 586435
}
})
expect(actions[4]).toEqual({
type: SET_BALANCE,
payload: {
Expand All @@ -183,10 +183,10 @@ describe('WalletInfo', () => {
// })
})
test('correctly renders data from state with non-default currency', done => {
const testState = {
...initialState,
price: { NEO: 1.11, GAS: 0.55, currency: 'eur' }
}
const testState = merge(initialState, {
api: { SETTINGS: { data: { currency: 'eur' } } },
price: { NEO: 1.11, GAS: 0.55 }
})
const { wrapper } = setup(testState, false)

const neoWalletValue = wrapper.find('.neoWalletValue')
Expand Down
4 changes: 1 addition & 3 deletions __tests__/components/__snapshots__/WalletInfo.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`WalletInfo renders without crashing 1`] = `
<Connect(withData(mapProps(WalletInfo)))
<Connect(withData(mapProps(Connect(withData(Connect(withActions(WalletInfo)))))))
GAS="1000.0001601"
NEO="100001"
address="ANqUrhv99rwCiFTL6N1An9NH5UVkPYxTuw"
currencyCode="usd"
gasPrice={18.1}
loadWalletData={[Function]}
neoPrice={25.48}
Expand All @@ -25,7 +24,6 @@ exports[`WalletInfo renders without crashing 1`] = `
}
oldParticipateInSale={[Function]}
participateInSale={[Function]}
setUserGeneratedTokens={[Function]}
showErrorNotification={[Function]}
showModal={[Function]}
showSuccessNotification={[Function]}
Expand Down
103 changes: 0 additions & 103 deletions __tests__/modules/metadata.test.js

This file was deleted.

29 changes: 2 additions & 27 deletions __tests__/modules/price.test.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import walletReducer, { setNEOPrice, setGASPrice, setCurrency, resetPrice, SET_CURRENCY, SET_GAS_PRICE, SET_NEO_PRICE, RESET_PRICE } from '../../app/modules/price'
import walletReducer, { setNEOPrice, setGASPrice, resetPrice, SET_GAS_PRICE, SET_NEO_PRICE, RESET_PRICE } from '../../app/modules/price'

describe('wallet module tests', () => {
const NEO = 28.10
const GAS = 18.20
const currency = 'eur'

const initialState = {
NEO: 0,
GAS: 0,
currency: 'usd'
GAS: 0
}

describe('setNEOPrice tests', () => {
Expand Down Expand Up @@ -57,29 +55,6 @@ describe('wallet module tests', () => {
})
})

describe('setCurrency tests', () => {
const expectedAction = {
type: SET_CURRENCY,
payload: { currency }
}

test('setCurrency action works', () => {
expect(setCurrency(currency)).toEqual(expect.any(Function))
})

test('setCurrency reducer should return the initial state', () => {
expect(walletReducer(undefined, {})).toEqual(initialState)
})

test('wallet reducer should handle SET_CURRENCY', () => {
const expectedState = {
...initialState,
currency
}
expect(walletReducer(undefined, expectedAction)).toEqual(expectedState)
})
})

describe('resetPrice tests', () => {
const expectedAction = {
type: RESET_PRICE
Expand Down
3 changes: 1 addition & 2 deletions __tests__/store/reducers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ describe('root reducer', () => {
price: expect.any(Object),
transactions: expect.any(Object),
dashboard: expect.any(Object),
metadata: expect.any(Object),
notifications: expect.any(Array),
notifications: expect.any(Object),
claim: expect.any(Object),
modal: expect.any(Object),
sale: expect.any(Object)
Expand Down
2 changes: 1 addition & 1 deletion app/actions/appActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ import settingsActions from './settingsActions'
export const ID = 'APP'

export default createBatchActions(ID, {
height: blockHeightActions,
blockHeight: blockHeightActions,
settings: settingsActions
})
Loading

0 comments on commit 80a5cc7

Please sign in to comment.