-
Notifications
You must be signed in to change notification settings - Fork 312
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replaced balance, claim, & transaction history actions/reducers with …
…new actions architecture (#611) * Added actions for fetching asset & token balances * Removed unused prop mapping from app store * Added balance actions and HOC's to replaced most of loadWalletData function * Reset stores on logout * Renamed accountActions to authActions * Removed unused deprecated functions * Fixed fetching state from action that has not been fetched * Added claims actions and account actions * Replaced load wallet claim sync with new action data * Replaced load wallet transactions sync with new action data * Fixed tokens argument being passed to account request action
- Loading branch information
1 parent
737f3cd
commit bcb8a4c
Showing
53 changed files
with
1,004 additions
and
1,050 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,170 +1,110 @@ | ||
import React from 'react' | ||
import * as neonjs from 'neon-js' | ||
import { cloneDeep } from 'lodash' | ||
import { Provider } from 'react-redux' | ||
import configureStore from 'redux-mock-store' | ||
import thunk from 'redux-thunk' | ||
import { shallow, mount } from 'enzyme' | ||
import { merge } from 'lodash' | ||
import { mount } from 'enzyme' | ||
|
||
import { createStore, provideStore } from '../testHelpers' | ||
import Claim from '../../app/containers/Claim' | ||
import { setClaimRequest, disableClaim } from '../../app/modules/claim' | ||
import { SHOW_NOTIFICATION, HIDE_NOTIFICATIONS, DEFAULT_POSITION } from '../../app/modules/notifications' | ||
import { SHOW_NOTIFICATION } from '../../app/modules/notifications' | ||
import { NOTIFICATION_LEVELS, MAIN_NETWORK_ID } from '../../app/core/constants' | ||
import { LOADED } from '../../app/values/state' | ||
|
||
jest.useFakeTimers() | ||
|
||
const initialState = { | ||
api: { | ||
NETWORK: { | ||
batch: false, | ||
state: LOADED, | ||
data: MAIN_NETWORK_ID | ||
}, | ||
SETTINGS: { | ||
CLAIMS: { | ||
batch: false, | ||
state: LOADED, | ||
data: {} | ||
data: { | ||
total: '0.01490723' | ||
} | ||
}, | ||
BALANCES: { | ||
batch: false, | ||
state: LOADED, | ||
data: { | ||
NEO: '10', | ||
GAS: '10.00000000' | ||
} | ||
} | ||
}, | ||
claim: { | ||
claimAmount: 10, | ||
claimRequest: false, | ||
claimWasUpdated: false, | ||
disableClaimButton: false | ||
}, | ||
account: { | ||
wif: 'wif', | ||
address: 'address' | ||
}, | ||
wallet: { | ||
NEO: '1' | ||
} | ||
} | ||
|
||
const setup = (state = initialState, shallowRender = true) => { | ||
const store = configureStore([thunk])(state) | ||
|
||
let wrapper | ||
if (shallowRender) { | ||
wrapper = shallow(<Claim store={store} />) | ||
} else { | ||
wrapper = mount( | ||
<Provider store={store}> | ||
<Claim /> | ||
</Provider> | ||
) | ||
} | ||
|
||
return { | ||
store, | ||
wrapper | ||
} | ||
const simulateSendAsset = (result) => { | ||
return jest.fn(() => { | ||
return new Promise((resolve, reject) => { | ||
resolve({ result }) | ||
}) | ||
}) | ||
} | ||
|
||
describe('Claim', () => { | ||
test('should render without crashing', () => { | ||
const { wrapper } = setup() | ||
const store = createStore(initialState) | ||
const wrapper = mount(provideStore(<Claim />, store)) | ||
expect(wrapper).toMatchSnapshot() | ||
}) | ||
|
||
test('should render claim GAS button when claim button is not disabled', () => { | ||
const { wrapper } = setup() | ||
expect(wrapper.dive()).toMatchSnapshot() | ||
test('should render claim GAS button as enabled', () => { | ||
const store = createStore(initialState) | ||
const wrapper = mount(provideStore(<Claim />, store)) | ||
expect(wrapper).toMatchSnapshot() | ||
}) | ||
|
||
test('should not render claim GAS button when claim button is disabled', () => { | ||
const newState = cloneDeep(initialState) | ||
newState.claim.disableClaimButton = true | ||
const { wrapper } = setup(newState) | ||
expect(wrapper.dive()).toMatchSnapshot() | ||
test('should render claim GAS button as disabled', () => { | ||
const state = merge({}, initialState, { claim: { disableClaimButton: true } }) | ||
const store = createStore(state) | ||
const wrapper = mount(provideStore(<Claim />, store)) | ||
expect(wrapper).toMatchSnapshot() | ||
}) | ||
|
||
describe('when do GAS claim button is clicked', () => { | ||
test('should dispatch transaction failure event', async () => { | ||
const { wrapper, store } = setup() | ||
neonjs.api.neonDB.doSendAsset = jest.fn(() => { | ||
return new Promise((resolve, reject) => { | ||
resolve({ result: undefined }) | ||
}) | ||
}) | ||
wrapper.dive().find('#claim').simulate('click') | ||
describe('when claim GAS button is clicked', () => { | ||
test('should dispatch transaction failure event', async (done) => { | ||
const store = createStore(initialState) | ||
const wrapper = mount(provideStore(<Claim />, store)) | ||
neonjs.api.neonDB.doSendAsset = simulateSendAsset(false) | ||
|
||
wrapper.find('button#claim').simulate('click') | ||
jest.runAllTimers() | ||
await Promise.resolve().then().then().then() | ||
|
||
const actions = store.getActions() | ||
expect(actions.length).toEqual(4) | ||
expect(actions[0]).toEqual({ | ||
type: HIDE_NOTIFICATIONS, | ||
payload: expect.objectContaining({ | ||
dismissible: true, | ||
position: DEFAULT_POSITION | ||
}) | ||
}) | ||
expect(actions[1]).toEqual({ | ||
type: SHOW_NOTIFICATION, | ||
payload: expect.objectContaining({ | ||
message: 'Sending NEO to Yourself...', | ||
level: NOTIFICATION_LEVELS.INFO | ||
}) | ||
}) | ||
expect(actions[2]).toEqual({ | ||
type: HIDE_NOTIFICATIONS, | ||
payload: expect.objectContaining({ | ||
dismissible: true, | ||
position: DEFAULT_POSITION | ||
}) | ||
}) | ||
expect(actions[3]).toEqual({ | ||
|
||
expect(actions).toContainEqual(expect.objectContaining({ | ||
type: SHOW_NOTIFICATION, | ||
payload: expect.objectContaining({ | ||
message: 'Transaction failed!', | ||
level: NOTIFICATION_LEVELS.ERROR | ||
level: NOTIFICATION_LEVELS.ERROR, | ||
message: 'Transaction failed!' | ||
}) | ||
}) | ||
})) | ||
done() | ||
}) | ||
|
||
test('should dispatch transaction waiting, set claim request and disable claim event', async () => { | ||
const { wrapper, store } = setup() | ||
neonjs.api.neonDB.doSendAsset = jest.fn(() => { | ||
return new Promise((resolve, reject) => { | ||
resolve({ result: true }) | ||
}) | ||
}) | ||
|
||
wrapper.dive().find('#claim').simulate('click') | ||
test('should dispatch transaction waiting, set claim request, and disable claim events', async (done) => { | ||
const store = createStore(initialState) | ||
const wrapper = mount(provideStore(<Claim />, store)) | ||
neonjs.api.neonDB.doSendAsset = simulateSendAsset(true) | ||
|
||
wrapper.find('button#claim').simulate('click') | ||
jest.runAllTimers() | ||
await Promise.resolve().then().then().then() | ||
|
||
const actions = store.getActions() | ||
expect(actions.length).toEqual(6) | ||
expect(actions[0]).toEqual({ | ||
type: HIDE_NOTIFICATIONS, | ||
payload: expect.objectContaining({ | ||
dismissible: true, | ||
position: DEFAULT_POSITION | ||
}) | ||
}) | ||
expect(actions[1]).toEqual({ | ||
type: SHOW_NOTIFICATION, | ||
payload: expect.objectContaining({ | ||
message: 'Sending NEO to Yourself...', | ||
level: NOTIFICATION_LEVELS.INFO | ||
}) | ||
}) | ||
|
||
expect(actions[2]).toEqual({ | ||
type: HIDE_NOTIFICATIONS, | ||
payload: expect.objectContaining({ | ||
dismissible: true, | ||
position: DEFAULT_POSITION | ||
}) | ||
}) | ||
expect(actions[3]).toEqual({ | ||
type: SHOW_NOTIFICATION, | ||
payload: expect.objectContaining({ | ||
message: 'Waiting for transaction to clear...', | ||
level: NOTIFICATION_LEVELS.INFO | ||
}) | ||
}) | ||
expect(actions[4]).toEqual(setClaimRequest(true)) | ||
expect(actions[5]).toEqual(disableClaim(true)) | ||
expect(actions).toContainEqual(setClaimRequest(true)) | ||
expect(actions).toContainEqual(disableClaim(true)) | ||
done() | ||
}) | ||
}) | ||
}) |
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
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
Oops, something went wrong.