-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
316 additions
and
115 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import React from 'react'; | ||
import { Route, Redirect } from 'react-router-dom'; | ||
import PropTypes from 'prop-types'; | ||
import { connect } from 'react-redux'; | ||
|
||
export class PrivateRoute extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { }; | ||
} | ||
|
||
render() { | ||
const { component: Component, isAuthenticated, ...rest } = this.props; | ||
return ( | ||
<Route | ||
{...rest} | ||
render={props => (isAuthenticated ? <Component {...props} /> | ||
: <Redirect to={{ pathname: '/login', state: { referrer: props.location } }} />)} | ||
/> | ||
); | ||
} | ||
} | ||
|
||
|
||
PrivateRoute.propTypes = { | ||
component: PropTypes.elementType, | ||
isAuthenticated: PropTypes.bool, | ||
}; | ||
const mapStateToProps = state => ({ | ||
isAuthenticated: state.auth.isAuthenticated, | ||
}); | ||
|
||
export default connect(mapStateToProps)(PrivateRoute); |
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import React from 'react'; | ||
import { Route, Redirect } from 'react-router-dom'; | ||
import PropTypes from 'prop-types'; | ||
import { connect } from 'react-redux'; | ||
|
||
export class PublicRoute extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { }; | ||
} | ||
|
||
render() { | ||
const { component: Component, isAuthenticated, ...rest } = this.props; | ||
return ( | ||
<Route | ||
{...rest} | ||
render={props => (!isAuthenticated ? <Component {...props} /> | ||
: <Redirect to="/dashboard" />)} | ||
/> | ||
); | ||
} | ||
} | ||
|
||
|
||
PublicRoute.propTypes = { | ||
component: PropTypes.elementType, | ||
isAuthenticated: PropTypes.bool, | ||
}; | ||
const mapStateToProps = state => ({ | ||
isAuthenticated: state.auth.isAuthenticated, | ||
}); | ||
|
||
export default connect(mapStateToProps)(PublicRoute); |
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
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 |
---|---|---|
|
@@ -23,3 +23,11 @@ Array [ | |
}, | ||
] | ||
`; | ||
|
||
exports[`authAction test lougout action 1`] = ` | ||
Array [ | ||
Object { | ||
"type": "LOGOUT", | ||
}, | ||
] | ||
`; |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import { PrivateRoute } from '../../components/PrivateRoute/PrivateRoute'; | ||
import { Dashboard } from '../../views/Dashboard/Dashboard'; | ||
|
||
const props = { | ||
component: Dashboard, | ||
isAuthenticated: true, | ||
}; | ||
describe('component: PrivateRoute', () => { | ||
it('should render correctly', (done) => { | ||
const wrapper = shallow(<PrivateRoute />); | ||
expect(wrapper).toMatchSnapshot(); | ||
done(); | ||
}); | ||
it('should render when user is Authenticated', (done) => { | ||
const wrapper = shallow(<PrivateRoute {...props} />); | ||
expect(wrapper).toMatchSnapshot(); | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import { PublicRoute } from '../../components/PublicRoute/PublicRoute'; | ||
import { Dashboard } from '../../views/Dashboard/Dashboard'; | ||
|
||
const props = { | ||
component: Dashboard, | ||
isAuthenticated: false, | ||
}; | ||
describe('component: PublicRoute', () => { | ||
it('should render correctly', (done) => { | ||
const wrapper = shallow(<PublicRoute />); | ||
expect(wrapper).toMatchSnapshot(); | ||
done(); | ||
}); | ||
it('should render correctly when isAuthenticated is false', (done) => { | ||
const wrapper = shallow(<PublicRoute {...props} />); | ||
expect(wrapper).toMatchSnapshot(); | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`component: PrivateRoute should render correctly 1`] = `ShallowWrapper {}`; | ||
|
||
exports[`component: PrivateRoute should render when user is Authenticated 1`] = `ShallowWrapper {}`; |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`component: PublicRoute should render correctly 1`] = `ShallowWrapper {}`; | ||
|
||
exports[`component: PublicRoute should render correctly when isAuthenticated is false 1`] = `ShallowWrapper {}`; |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Auth Reducers should handle logout 1`] = ` | ||
Object { | ||
"errors": Object {}, | ||
"isAuthenticated": false, | ||
"isLoading": false, | ||
"passwordChangeError": "", | ||
"passwordChangeSuccess": "", | ||
"passwordResetError": "", | ||
"passwordResetSuccess": "", | ||
"user": Object {}, | ||
"verified": "", | ||
} | ||
`; |
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
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
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.