Skip to content

Commit

Permalink
Merge a672f6b into 3e249d6
Browse files Browse the repository at this point in the history
  • Loading branch information
JackNeto committed Mar 5, 2019
2 parents 3e249d6 + a672f6b commit d6756f5
Show file tree
Hide file tree
Showing 13 changed files with 677 additions and 123 deletions.
172 changes: 172 additions & 0 deletions src/__tests__/__snapshots__/routes.test.jsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Routes snapshot matches with no accounts 1`] = `
<div>
<div
className="MuiGrid-container-8 LandingComponent-root-1"
>
<div
className="MuiGrid-item-9 MuiGrid-grid-xs-6-42 LandingComponent-left-2"
>
<div
className="LandingComponent-logo-3"
>
Entaxy
<div
className="LandingComponent-tagline-4"
>
Order from chaos
</div>
</div>
<div
className="LandingComponent-title-5"
>
Your Personal Finance Simple & Private
<div
className="LandingComponent-description-6"
>
Insights into your finances, without sacrificing your data
</div>
</div>
<div
className="MuiGrid-container-8"
>
<h5
className="MuiTypography-root-111 MuiTypography-h5-127 MuiTypography-colorSecondary-142"
>
Where do you want to store your data?
</h5>
<div
className="MuiGrid-item-9 MuiGrid-grid-xs-6-42"
>
<div
className="MuiPaper-root-147 MuiPaper-elevation1-150 MuiPaper-rounded-148 LandingCardComponent-loggedInContainer-106"
>
<h6
className="MuiTypography-root-111 MuiTypography-subtitle2-130 LandingCardComponent-blockstackTitle-109"
>
Anywhere with blockstack
</h6>
<span
className="MuiTypography-root-111 MuiTypography-caption-121 LandingCardComponent-signingDescription-107"
>
Keep your data encrypted and decentralized. Learn more about  
<a
href="https://blockstack.org/what-is-blockstack"
rel="noopener noreferrer"
target="_blank"
>
Blockstack
</a>
</span>
<button
className="MuiButtonBase-root-200 MuiButton-root-174 MuiButton-contained-185 MuiButton-containedSecondary-187 MuiButton-raised-188 MuiButton-raisedSecondary-190 LandingCardComponent-signinButton-108"
disabled={false}
onBlur={[Function]}
onClick={[Function]}
onContextMenu={[Function]}
onFocus={[Function]}
onKeyDown={[Function]}
onKeyUp={[Function]}
onMouseDown={[Function]}
onMouseLeave={[Function]}
onMouseUp={[Function]}
onTouchEnd={[Function]}
onTouchMove={[Function]}
onTouchStart={[Function]}
tabIndex="0"
type="button"
>
<span
className="MuiButton-label-175"
>
Sign in with Blockstack
</span>
<span
className="MuiTouchRipple-root-214"
/>
</button>
</div>
</div>
<div
className="MuiGrid-item-9 MuiGrid-grid-xs-6-42"
>
<div
className="MuiPaper-root-147 MuiPaper-elevation1-150 MuiPaper-rounded-148 LandingCardComponent-loggedInContainer-106"
>
<h6
className="MuiTypography-root-111 MuiTypography-subtitle2-130"
>
<svg
aria-hidden="true"
className="MuiSvgIcon-root-203 LandingCardComponent-browserIcon-110"
focusable="false"
role="presentation"
viewBox="0 0 24 24"
>
<defs>
<path
d="M0 0h24v24H0V0z"
id="a"
/>
</defs>
<path
d="M20 18c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2H4c-1.1 0-2 .9-2 2v10c0 1.1.9 2 2 2H0v2h24v-2h-4zM4 6h16v10H4V6z"
/>
</svg>
Locally in your browser
</h6>
<span
className="MuiTypography-root-111 MuiTypography-caption-121 LandingCardComponent-signingDescription-107"
>
Your data will be stored temporarily and it be removed once you close your browser
</span>
<button
className="MuiButtonBase-root-200 MuiButton-root-174 MuiButton-contained-185 MuiButton-containedSecondary-187 MuiButton-raised-188 MuiButton-raisedSecondary-190 LandingCardComponent-signinButton-108"
disabled={false}
onBlur={[Function]}
onClick={[Function]}
onContextMenu={[Function]}
onFocus={[Function]}
onKeyDown={[Function]}
onKeyUp={[Function]}
onMouseDown={[Function]}
onMouseLeave={[Function]}
onMouseUp={[Function]}
onTouchEnd={[Function]}
onTouchMove={[Function]}
onTouchStart={[Function]}
tabIndex="0"
type="button"
>
<span
className="MuiButton-label-175"
>
Take it for a test drive
</span>
<span
className="MuiTouchRipple-root-214"
/>
</button>
</div>
</div>
</div>
<div>
<p
className="MuiTypography-root-111 MuiTypography-body2-119"
>
Entaxy is free and you get to keep your data.
</p>
<p
className="MuiTypography-root-111 MuiTypography-body2-119"
>
That's right, we don't store your data in a big database so we don't need to convince you to trust us.
</p>
</div>
</div>
<div
className="MuiGrid-item-9 MuiGrid-grid-xs-6-42 LandingComponent-right-7"
/>
</div>
</div>
`;
107 changes: 107 additions & 0 deletions src/__tests__/routes.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import React from 'react'
import renderer from 'react-test-renderer'
import { shallow } from 'enzyme'
import { Provider } from 'react-redux'
import { BrowserRouter, Redirect } from 'react-router-dom'
import store from '../store'
import ThemeProvider from '../core/ThemeProvider'
import { initialState as userInitialState } from '../store/user/reducer'
import { initialState as settingsInitialState } from '../store/settings/reducer'
import { initialState as accountsInitialState } from '../store/accounts/reducer'
import { RoutesComponent } from '../routes'
import Header from '../common/Header'

jest.mock('../common/InstitutionIcon', () => 'InstitutionIcon')

const FakeComponent = () => (<div />)

describe('Routes', () => {
describe('snapshot', () => {
it('matches with no accounts', () => {
const component = renderer.create((
<Provider store={store}>
<ThemeProvider>
<BrowserRouter>
<RoutesComponent
user={userInitialState}
settings={settingsInitialState}
accounts={accountsInitialState}
classes={{ }}
/>
</BrowserRouter>
</ThemeProvider>
</Provider>
))
expect(component.toJSON()).toMatchSnapshot()
})
})

describe('Component methods', () => {
let wrapper
it('Should redirect if user is not authenticated', () => {
wrapper = shallow((
<RoutesComponent
user={userInitialState}
settings={settingsInitialState}
accounts={accountsInitialState}
classes={{ }}
/>
))
const instance = wrapper.instance()

expect(instance.props.user.isAuthenticatedWith).toBeNull()
expect(instance.loginRequired(FakeComponent)()).toEqual(<Redirect to="/" />)
})

it('Should render component with no options', () => {
wrapper = shallow((
<RoutesComponent
user={{ isAuthenticatedWith: true }}
settings={settingsInitialState}
accounts={accountsInitialState}
classes={{ }}
/>
))
const instance = wrapper.instance()

expect(instance.props.user.isAuthenticatedWith).toBeTruthy()
expect(instance.loginRequired(FakeComponent)()).toEqual((
<Header><FakeComponent /></Header>
))
})

it('Should redirect if there are no accounts', () => {
wrapper = shallow((
<RoutesComponent
user={{ isAuthenticatedWith: true }}
settings={settingsInitialState}
accounts={accountsInitialState}
classes={{ }}
/>
))
const instance = wrapper.instance()

expect(instance.props.user.isAuthenticatedWith).toBeTruthy()
expect(instance.loginRequired(FakeComponent, { accountRequired: true })()).toEqual((
<Redirect to="/" />
))
})

it('Should render component when accounts required', () => {
wrapper = shallow((
<RoutesComponent
user={{ isAuthenticatedWith: true }}
settings={settingsInitialState}
accounts={{ byId: [{ id: 1 }] }}
classes={{ }}
/>
))
const instance = wrapper.instance()

expect(instance.props.user.isAuthenticatedWith).toBeTruthy()
expect(instance.loginRequired(FakeComponent, { accountRequired: true })()).toEqual((
<Header><FakeComponent /></Header>
))
})
})
})
7 changes: 3 additions & 4 deletions src/core/Accounts/ImportTransactions/ImportedResults.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ const styles = {
}

export class ImportedResultsComponent extends React.Component {
filterTransactionsWithErrors = transaction => (
filterByErrors = transaction => (
Object.keys(transaction).includes('errors') && transaction.errors.length > 0
)

toolbarProps = () => {
const { transactions, classes } = this.props
const transactionsWithErrors = transactions.filter(this.filterTransactionsWithErrors)
const transactionsWithErrors = transactions.filter(this.filterByErrors)
let subTitle = 'No errors'

if (transactionsWithErrors.length > 0) {
Expand All @@ -58,8 +58,7 @@ export class ImportedResultsComponent extends React.Component {

return {
title: `Found ${transactions.length} transactions`,
subTitle,
filterTransactionsWithErrors: this.filterTransactionsWithErrors
subTitle
}
}

Expand Down
14 changes: 3 additions & 11 deletions src/core/Accounts/ImportTransactions/ResultsToolbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,15 @@ const styles = {
}

export class ResultsToolbarComponent extends React.Component {
state = {
showOnlyErrors: false
}

onChange = ({ target }) => {
if (target.checked) {
this.props.filterProps.setFilter({
attr: 'errors',
value: this.props.filterTransactionsWithErrors
value: true
})
} else {
this.props.filterProps.unsetFilter({ attr: 'errors' })
}
this.setState({
showOnlyErrors: target.checked
})
}

render() {
Expand All @@ -48,7 +41,7 @@ export class ResultsToolbarComponent extends React.Component {
className={classes.chekbox}
control={(
<Switch
checked={this.state.showOnlyErrors}
checked={Object.keys(this.props.filterProps.filters).includes('errors')}
onChange={this.onChange}
value="showOnlyErrors"
/>
Expand All @@ -64,8 +57,7 @@ ResultsToolbarComponent.propTypes = {
title: PropTypes.string.isRequired,
subTitle: PropTypes.node.isRequired,
selectedTransactions: PropTypes.array.isRequired,
filterProps: PropTypes.object.isRequired,
filterTransactionsWithErrors: PropTypes.func.isRequired
filterProps: PropTypes.object.isRequired
}

export default withStyles(styles)(ResultsToolbarComponent)
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe('ImportedResults', () => {
})

describe('Component methods', () => {
describe('filterTransactionsWithErrors', () => {
describe('filterByErrors', () => {
const wrapper = shallow((
<ImportedResultsComponent
classes={{ }}
Expand All @@ -90,9 +90,9 @@ describe('ImportedResults', () => {
const instance = wrapper.instance()

it('should filter transactions with errors', () => {
expect(instance.filterTransactionsWithErrors({})).toBeFalsy()
expect(instance.filterTransactionsWithErrors({ errors: [] })).toBeFalsy()
expect(instance.filterTransactionsWithErrors({ errors: ['some error'] })).toBeTruthy()
expect(instance.filterByErrors({})).toBeFalsy()
expect(instance.filterByErrors({ errors: [] })).toBeFalsy()
expect(instance.filterByErrors({ errors: ['some error'] })).toBeTruthy()
})
})

Expand All @@ -119,8 +119,7 @@ describe('ImportedResults', () => {

expect(instance.toolbarProps({})).toEqual({
title: `Found ${transactions.length} transactions`,
subTitle: 'No errors',
filterTransactionsWithErrors: instance.filterTransactionsWithErrors
subTitle: 'No errors'
})
})

Expand Down Expand Up @@ -151,10 +150,9 @@ describe('ImportedResults', () => {
const instance = wrapper.instance()

const props = instance.toolbarProps({})
expect(Object.keys(props)).toEqual(['title', 'subTitle', 'filterTransactionsWithErrors'])
expect(Object.keys(props)).toEqual(['title', 'subTitle'])
expect(props.title).toEqual(`Found ${transactions.length} transactions`)
expect(props.subTitle).not.toEqual('No errors')
expect(props.filterTransactionsWithErrors).toEqual(instance.filterTransactionsWithErrors)
})
})

Expand Down
Loading

0 comments on commit d6756f5

Please sign in to comment.