-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(logout): implement logout functionality
- add logout component to Nav - implement logic to log user out and cleanup cart using redux - modify login action to get cart items upon authentication - adequatly test all new functionality [Finishes #163503750]
- Loading branch information
Showing
13 changed files
with
144 additions
and
11 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
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,32 @@ | ||
import React, { Component } from 'react'; | ||
import { connect } from 'react-redux'; | ||
import PropTypes from 'prop-types'; | ||
import { withRouter } from 'react-router-dom'; | ||
import { logout } from '../actions'; | ||
|
||
export class Logout extends Component { | ||
onLogoutClick = async (e) => { | ||
e.preventDefault(); | ||
const { logout: logoutUser, history } = this.props; | ||
await logoutUser(); | ||
return history.push('/login'); | ||
}; | ||
|
||
render() { | ||
return ( | ||
<a onClick={this.onLogoutClick} href="!#"> | ||
logout | ||
</a> | ||
); | ||
} | ||
} | ||
|
||
Logout.propTypes = { | ||
logout: PropTypes.func.isRequired, | ||
history: PropTypes.instanceOf(Object).isRequired, | ||
}; | ||
|
||
export default connect( | ||
null, | ||
{ logout }, | ||
)(withRouter(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
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,10 @@ | ||
import { logout } from '../../actions'; | ||
|
||
describe('logout()', () => { | ||
const dispatch = jest.fn(); | ||
it('should successfully log out user', () => { | ||
logout()(dispatch); | ||
expect(dispatch).toHaveBeenCalledTimes(2); | ||
expect(dispatch).toHaveBeenLastCalledWith({ 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
import { Logout } from '../../components/Logout'; | ||
|
||
describe('<Logout />', () => { | ||
const props = { | ||
logout: jest.fn(), | ||
history: { push: jest.fn() }, | ||
}; | ||
|
||
it('should successfully logout the user', () => { | ||
const wrapper = mount(<Logout {...props} />); | ||
wrapper.find('a').simulate('click'); | ||
expect(props.logout).toHaveBeenCalled(); | ||
wrapper.unmount(); | ||
}); | ||
}); |
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,45 @@ | ||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
import { Nav } from '../../components/Nav'; | ||
import { routerWrap, reduxWrap } from '../helpers'; | ||
|
||
describe('<Nav />', () => { | ||
const adminProps = { | ||
role: 'admin', | ||
isLoggedIn: true, | ||
}; | ||
|
||
const customerProps = { | ||
role: 'customer', | ||
isLoggedIn: true, | ||
}; | ||
|
||
const noAuthProps = { | ||
role: 'admin', | ||
isLoggedIn: false, | ||
}; | ||
|
||
it('should render correctly for admin', () => { | ||
const wrapper = mount(routerWrap(<Nav {...adminProps} />)); | ||
const links = wrapper.find('li'); | ||
expect(links.length).toEqual(2); | ||
wrapper.unmount(); | ||
}); | ||
|
||
it('should render correctly for customer', () => { | ||
const connectedComponent = reduxWrap(<Nav {...customerProps} />); | ||
const wrapper = mount(routerWrap(connectedComponent)); | ||
const links = wrapper.find('li'); | ||
expect(links.length).toEqual(3); | ||
wrapper.unmount(); | ||
}); | ||
|
||
it('should render correctly for unauthenticated user', () => { | ||
const wrapper = mount(routerWrap(<Nav {...noAuthProps} />)); | ||
const links = wrapper.find('li a'); | ||
expect(links.length).toEqual(2); | ||
expect(links.first().text()).toEqual('Log In'); | ||
expect(links.last().text()).toEqual('Sign Up'); | ||
wrapper.unmount(); | ||
}); | ||
}); |
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