Skip to content

Commit

Permalink
Fixed all tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JackNeto committed Jul 2, 2019
1 parent 9153919 commit 227f573
Show file tree
Hide file tree
Showing 30 changed files with 847 additions and 561 deletions.
4 changes: 2 additions & 2 deletions src/__tests__/__snapshots__/routes.test.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ exports[`Routes snapshot matches with no accounts 1`] = `
Sign in with Blockstack
</span>
<span
className="MuiTouchRipple-root-214"
className="MuiTouchRipple-root-224"
/>
</button>
</div>
Expand Down Expand Up @@ -145,7 +145,7 @@ exports[`Routes snapshot matches with no accounts 1`] = `
Take it for a test drive
</span>
<span
className="MuiTouchRipple-root-214"
className="MuiTouchRipple-root-224"
/>
</button>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`SnackbarMessage matches snapshot 1`] = `null`;
16 changes: 16 additions & 0 deletions src/common/SnackbarMessage/__tests__/index.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react'
import renderer from 'react-test-renderer'
import { Provider } from 'react-redux'
import store from '../../../store'
import SnackbarMessage from '..'

describe('SnackbarMessage', () => {
it('matches snapshot', () => {
const component = renderer.create((
<Provider store={store}>
<SnackbarMessage />
</Provider>
))
expect(component.toJSON()).toMatchSnapshot()
})
})
60 changes: 60 additions & 0 deletions src/common/SnackbarMessage/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import React from 'react'
import PropTypes from 'prop-types'
import { compose } from 'recompose'
import { connect } from 'react-redux'
import { withStyles } from '@material-ui/core/styles'
import Snackbar from '@material-ui/core/Snackbar'
import CheckCircleIcon from '@material-ui/icons/CheckCircle'
import { green } from '@material-ui/core/colors'
import { hideSnackbar } from '../../store/settings/actions'

const styles = theme => ({
message: {
display: 'flex',
alignItems: 'center'
},
icon: {
fontSize: 20,
opacity: 0.9,
marginRight: theme.spacing.unit * 2
},
success: {
color: green[600]
}
})

const mapStateToProps = ({ settings }) => {
return { settings }
}

const mapDispatchToProps = dispatch => ({
handleCloseSnackbar: () => { dispatch(hideSnackbar()) }
})

const SnackbarMessage = ({ classes, settings, handleCloseSnackbar }) => (
<Snackbar
anchorOrigin={{ vertical: 'bottom', horizontal: 'left' }}
open={settings.snackbarMessage !== null}
onClose={handleCloseSnackbar}
autoHideDuration={4000}
ContentProps={{ 'aria-describedby': 'message-id' }}
message={(
<span id="message-id" className={classes.message}>
{settings.snackbarMessage && settings.snackbarMessage.status === 'success' && (
<CheckCircleIcon className={[classes.icon, classes.success].join(' ')} />
)}
{settings.snackbarMessage && settings.snackbarMessage.text}
</span>
)}
/>
)
SnackbarMessage.propTypes = {
classes: PropTypes.object.isRequired,
settings: PropTypes.object.isRequired,
handleCloseSnackbar: PropTypes.func.isRequired
}

export default compose(
connect(mapStateToProps, mapDispatchToProps),
withStyles(styles)
)(SnackbarMessage)
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ const account = {
description: 'Checking',
currency: 'CAD',
openingBalance: 10,
currentBalance: 10
currentBalance: {
accountCurrency: 10,
localCurrency: null
}
}

describe('Import Transactions', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/core/Accounts/Transactions/TransactionsTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export class TransactionsTableComponent extends React.Component {
</div>
)
}
return formatCurrency(amount)
return formatDecimal(amount)
}

renderCellAmount = ({ cellData }) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,11 @@ describe('TransactionsTable', () => {
})

describe('displayCurrency', () => {
it('should displayCurrency for fiat account', () => {
expect(instance.props.account.type).toEqual()
it('should formatDecimal for fiat account', () => {
expect(instance.props.account.type).toEqual(undefined)
instance.displayCurrency({ amount: 10, nativeAmount: 12 })
expect(mochFormatCurrency).toHaveBeenCalledWith(10)
expect(mochFormatDecimal).not.toHaveBeenCalledWith(10)
expect(mochFormatCurrency).not.toHaveBeenCalledWith(10)
expect(mochFormatDecimal).toHaveBeenCalledWith(10)
})

it('should displayCurrency for wallet account', () => {
Expand Down
12 changes: 6 additions & 6 deletions src/core/Accounts/__tests__/__snapshots__/index.test.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ exports[`Accounts index (Left Nav) snapshot matches snapshot with a few account
<p
className="MuiTypography-root-38 MuiTypography-body1-47 MuiTypography-colorTextSecondary-71 MuiListItemText-secondary-98 MuiListItemText-textDense-99"
>
CA$10.00
CA$NaN
</p>
</div>
<span
Expand Down Expand Up @@ -203,7 +203,7 @@ exports[`Accounts index (Left Nav) snapshot matches snapshot with a few account
<p
className="MuiTypography-root-38 MuiTypography-body1-47 MuiTypography-colorTextSecondary-71 MuiListItemText-secondary-98 MuiListItemText-textDense-99"
>
CA$10.00
CA$NaN
</p>
</div>
<span
Expand Down Expand Up @@ -318,7 +318,7 @@ exports[`Accounts index (Left Nav) snapshot matches snapshot with a few account
<p
className="MuiTypography-root-38 MuiTypography-body1-47 MuiTypography-colorTextSecondary-71 MuiListItemText-secondary-98 MuiListItemText-textDense-99"
>
$10.00
$NaN
</p>
</div>
<span
Expand Down Expand Up @@ -616,7 +616,7 @@ exports[`Accounts index (Left Nav) snapshot matches with a few accounts but none
<p
className="MuiTypography-root-38 MuiTypography-body1-47 MuiTypography-colorTextSecondary-71 MuiListItemText-secondary-98 MuiListItemText-textDense-99"
>
CA$10.00
CA$NaN
</p>
</div>
<span
Expand Down Expand Up @@ -702,7 +702,7 @@ exports[`Accounts index (Left Nav) snapshot matches with a few accounts but none
<p
className="MuiTypography-root-38 MuiTypography-body1-47 MuiTypography-colorTextSecondary-71 MuiListItemText-secondary-98 MuiListItemText-textDense-99"
>
CA$10.00
CA$NaN
</p>
</div>
<span
Expand Down Expand Up @@ -817,7 +817,7 @@ exports[`Accounts index (Left Nav) snapshot matches with a few accounts but none
<p
className="MuiTypography-root-38 MuiTypography-body1-47 MuiTypography-colorTextSecondary-71 MuiListItemText-secondary-98 MuiListItemText-textDense-99"
>
$10.00
$NaN
</p>
</div>
<span
Expand Down
2 changes: 1 addition & 1 deletion src/core/Accounts/__tests__/edit.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe('New Account', () => {

instance.onDelete(account)
await expect(confirm).toHaveBeenCalledWith('Delete selected account?', 'Are you sure?')
expect(mochHandleDelete).toHaveBeenCalledWith(account)
await expect(mochHandleDelete).toHaveBeenCalledWith(account)
expect(mochHistoryPush).toHaveBeenCalledWith('/dashboard')
})
})
Expand Down
4 changes: 2 additions & 2 deletions src/core/Accounts/edit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export class EditAccountComponent extends React.Component {
}

onDelete = (account) => {
confirm('Delete selected account?', 'Are you sure?').then(() => {
this.props.handleDelete(account)
confirm('Delete selected account?', 'Are you sure?').then(async () => {
await this.props.handleDelete(account)
this.props.history.push('/dashboard')
})
}
Expand Down
25 changes: 19 additions & 6 deletions src/core/Accounts/form.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -283,15 +283,28 @@ export default compose(
mapPropsToValues: ({ account, settings }) => {
if (account === undefined) {
return {
name: '',
institution: null,
openingBalance: 0,
name: 'checking',
institution: {
label: 'TD',
value: 'TD'
},
openingBalance: 10,
openingBalanceDate: format(Date.now(), 'YYYY-MM-DD'),
currency: settings.currency === undefined ? '' : {
label: `(${settings.currency}) ${currencies[settings.currency]}`,
value: settings.currency
currency: settings.currency === undefined ? {} : {
label: `(GBP) ${currencies.GBP}`,
value: 'GBP'
}
}
// return {
// name: '',
// institution: null,
// openingBalance: 0,
// openingBalanceDate: format(Date.now(), 'YYYY-MM-DD'),
// currency: settings.currency === undefined ? '' : {
// label: `(${settings.currency}) ${currencies[settings.currency]}`,
// value: settings.currency
// }
// }
}
return {
...account,
Expand Down
2 changes: 1 addition & 1 deletion src/core/Accounts/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export const AccountsComponent = ({
if (account.type === 'wallet') {
return `${decimalFormatter(settings.locale, account.type)(account.currentBalance)} ${account.symbol}`
}
return currencyFormatter(settings.locale, account.currency)(account.currentBalance)
return currencyFormatter(settings.locale, account.currency)(account.currentBalance.accountCurrency)
}

return (
Expand Down
22 changes: 11 additions & 11 deletions src/core/Dashboard/__tests__/__snapshots__/index.test.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ exports[`Dashboard matches snapshot with no accounts 1`] = `
exports[`Dashboard matches snapshot with one account 1`] = `
"<Provider store={{...}}>
<Connect(WithStyles(DashboardComponent))>
<WithStyles(DashboardComponent) settings={{...}} accounts={{...}} exchangeRates={{...}} formatCurrency={[Function]} formatDate={[Function]} totalBalance={10} dispatch={[Function]}>
<DashboardComponent settings={{...}} accounts={{...}} exchangeRates={{...}} formatCurrency={[Function]} formatDate={[Function]} totalBalance={10} dispatch={[Function]} classes={{...}}>
<WithStyles(DashboardComponent) settings={{...}} accounts={{...}} exchangeRates={{...}} formatCurrency={[Function]} formatDate={[Function]} totalBalance={0} dispatch={[Function]}>
<DashboardComponent settings={{...}} accounts={{...}} exchangeRates={{...}} formatCurrency={[Function]} formatDate={[Function]} totalBalance={0} dispatch={[Function]} classes={{...}}>
<WithStyles(Grid) container={true}>
<Grid container={true} classes={{...}} alignContent=\\"stretch\\" alignItems=\\"stretch\\" component=\\"div\\" direction=\\"row\\" item={false} justify=\\"flex-start\\" lg={false} md={false} sm={false} spacing={0} wrap=\\"wrap\\" xl={false} xs={false} zeroMinWidth={false}>
<div className=\\"MuiGrid-container-10\\">
Expand All @@ -104,7 +104,7 @@ exports[`Dashboard matches snapshot with one account 1`] = `
<WithStyles(Typography) variant=\\"h5\\" align=\\"right\\" className=\\"DashboardComponent-balanceAmount-2\\">
<Typography variant=\\"h5\\" align=\\"right\\" className=\\"DashboardComponent-balanceAmount-2\\" theme={{...}} classes={{...}} color=\\"default\\" gutterBottom={false} headlineMapping={{...}} inline={false} noWrap={false} paragraph={false}>
<h5 className=\\"MuiTypography-root-134 MuiTypography-h5-150 MuiTypography-alignRight-158 DashboardComponent-balanceAmount-2\\">
$10.00
$0.00
</h5>
</Typography>
</WithStyles(Typography)>
Expand Down Expand Up @@ -220,7 +220,7 @@ exports[`Dashboard matches snapshot with one account 1`] = `
<WithStyles(Typography) variant=\\"subtitle2\\">
<Typography variant=\\"subtitle2\\" theme={{...}} classes={{...}} align=\\"inherit\\" color=\\"default\\" gutterBottom={false} headlineMapping={{...}} inline={false} noWrap={false} paragraph={false}>
<h6 className=\\"MuiTypography-root-134 MuiTypography-subtitle2-153\\">
$10.00
$0.00
</h6>
</Typography>
</WithStyles(Typography)>
Expand Down Expand Up @@ -254,7 +254,7 @@ exports[`Dashboard matches snapshot with one account 1`] = `
<WithStyles(TableCell) align=\\"right\\">
<TableCell align=\\"right\\" classes={{...}}>
<td className=\\"MuiTableCell-root-186 MuiTableCell-body-188 MuiTableCell-alignRight-196\\" aria-sort={{...}} scope={[undefined]}>
$NaN
0
</td>
</TableCell>
</WithStyles(TableCell)>
Expand Down Expand Up @@ -285,8 +285,8 @@ exports[`Dashboard matches snapshot with one account 1`] = `
exports[`Dashboard matches snapshot with two accounts in a different currency 1`] = `
"<Provider store={{...}}>
<Connect(WithStyles(DashboardComponent))>
<WithStyles(DashboardComponent) settings={{...}} accounts={{...}} exchangeRates={{...}} formatCurrency={[Function]} formatDate={[Function]} totalBalance={20} dispatch={[Function]}>
<DashboardComponent settings={{...}} accounts={{...}} exchangeRates={{...}} formatCurrency={[Function]} formatDate={[Function]} totalBalance={20} dispatch={[Function]} classes={{...}}>
<WithStyles(DashboardComponent) settings={{...}} accounts={{...}} exchangeRates={{...}} formatCurrency={[Function]} formatDate={[Function]} totalBalance={10} dispatch={[Function]}>
<DashboardComponent settings={{...}} accounts={{...}} exchangeRates={{...}} formatCurrency={[Function]} formatDate={[Function]} totalBalance={10} dispatch={[Function]} classes={{...}}>
<WithStyles(Grid) container={true}>
<Grid container={true} classes={{...}} alignContent=\\"stretch\\" alignItems=\\"stretch\\" component=\\"div\\" direction=\\"row\\" item={false} justify=\\"flex-start\\" lg={false} md={false} sm={false} spacing={0} wrap=\\"wrap\\" xl={false} xs={false} zeroMinWidth={false}>
<div className=\\"MuiGrid-container-10\\">
Expand All @@ -306,7 +306,7 @@ exports[`Dashboard matches snapshot with two accounts in a different currency 1`
<WithStyles(Typography) variant=\\"h5\\" align=\\"right\\" className=\\"DashboardComponent-balanceAmount-2\\">
<Typography variant=\\"h5\\" align=\\"right\\" className=\\"DashboardComponent-balanceAmount-2\\" theme={{...}} classes={{...}} color=\\"default\\" gutterBottom={false} headlineMapping={{...}} inline={false} noWrap={false} paragraph={false}>
<h5 className=\\"MuiTypography-root-134 MuiTypography-h5-150 MuiTypography-alignRight-158 DashboardComponent-balanceAmount-2\\">
20.00
10.00
</h5>
</Typography>
</WithStyles(Typography)>
Expand Down Expand Up @@ -422,7 +422,7 @@ exports[`Dashboard matches snapshot with two accounts in a different currency 1`
<WithStyles(Typography) variant=\\"subtitle2\\">
<Typography variant=\\"subtitle2\\" theme={{...}} classes={{...}} align=\\"inherit\\" color=\\"default\\" gutterBottom={false} headlineMapping={{...}} inline={false} noWrap={false} paragraph={false}>
<h6 className=\\"MuiTypography-root-134 MuiTypography-subtitle2-153\\">
20.00
10.00
</h6>
</Typography>
</WithStyles(Typography)>
Expand Down Expand Up @@ -456,7 +456,7 @@ exports[`Dashboard matches snapshot with two accounts in a different currency 1`
<WithStyles(TableCell) align=\\"right\\">
<TableCell align=\\"right\\" classes={{...}}>
<td className=\\"MuiTableCell-root-186 MuiTableCell-body-188 MuiTableCell-alignRight-196\\" aria-sort={{...}} scope={[undefined]}>
€NaN
0
</td>
</TableCell>
</WithStyles(TableCell)>
Expand Down Expand Up @@ -487,7 +487,7 @@ exports[`Dashboard matches snapshot with two accounts in a different currency 1`
<WithStyles(TableCell) align=\\"right\\">
<TableCell align=\\"right\\" classes={{...}}>
<td className=\\"MuiTableCell-root-186 MuiTableCell-body-188 MuiTableCell-alignRight-196\\" aria-sort={{...}} scope={[undefined]}>
10.00
NaN
</td>
</TableCell>
</WithStyles(TableCell)>
Expand Down
9 changes: 6 additions & 3 deletions src/core/Dashboard/__tests__/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,12 @@ describe('Dashboard', () => {
expect(wrapper.debug()).toMatchSnapshot()

const component = wrapper.findWhere(node => node.name() === 'DashboardComponent')
expect(component.props().settings).toEqual(settingsInitialState)
expect(component.props().settings).toEqual({
...settingsInitialState,
snackbarMessage: { text: 'Account created', status: 'success' }
})
expect(component.props().accounts).toEqual(store.getState().accounts)
expect(component.props().totalBalance).toEqual(10)
expect(component.props().totalBalance).toEqual(0)

expect(store.getState().settings.locale).toBe('en-US')
expect(component.props().formatCurrency(10000)).toEqual('$10,000.00')
Expand All @@ -87,7 +90,7 @@ describe('Dashboard', () => {
const component = wrapper.findWhere(node => node.name() === 'DashboardComponent')
expect(component.props().settings).toEqual(store.getState().settings)
expect(component.props().accounts).toEqual(store.getState().accounts)
expect(component.props().totalBalance).toEqual(20)
expect(component.props().totalBalance).toEqual(accounts[1].openingBalance)
expect(component.props().formatCurrency(10000)).toEqual('€10,000.00')
})
})
6 changes: 5 additions & 1 deletion src/core/Dashboard/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,11 @@ export class DashboardComponent extends React.Component {
<TableRow>
<TableCell>
<span className={classes.institutionWrapper}>
<InstitutionIcon institution={institution} size="small" className={classes.institutionIcon} />
<InstitutionIcon
institution={institution}
size="small"
className={classes.institutionIcon}
/>
<Typography variant="subtitle2">{institution}</Typography>
</span>
</TableCell>
Expand Down
Loading

0 comments on commit 227f573

Please sign in to comment.