File tree Expand file tree Collapse file tree 3 files changed +23
-12
lines changed
Expand file tree Collapse file tree 3 files changed +23
-12
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ export class Homepage extends Component {
1111 < HomepageModal key = { id } modal = { modal } />
1212 )
1313 } )
14- } ;
14+ }
1515
1616 render ( ) {
1717 return (
Original file line number Diff line number Diff line change 11import React , { Component , Fragment } from 'react'
2- import { Menu , Container , Image } from 'semantic-ui-react'
2+ import { Menu , Container , Image , Icon } from 'semantic-ui-react'
33import { Link } from 'react-router-dom'
44import { withRouter } from 'react-router'
55import logo from '../../images/av-logo.svg'
66import './Navbar.css'
7-
87export class Navbar extends Component {
98 currentPath ( ) {
109 // this.props.location.split("/") returns ["", ""] when on homepage
@@ -14,9 +13,13 @@ export class Navbar extends Component {
1413 return pathArray [ 1 ]
1514 }
1615
16+ handleRemoveCookies = ( ) => {
17+ this . props . cookies . remove ( '_WebsiteOne_session' )
18+ }
19+
1720 render ( ) {
18- const activeItem = this . currentPath ( )
1921 const { cookies } = this . props
22+ const activeItem = this . currentPath ( )
2023 return (
2124 < Menu stackable borderless inverted as = 'div' className = 'navbar' >
2225 < Container >
@@ -81,7 +84,15 @@ export class Navbar extends Component {
8184 < Link to = '/signup' > Sign up</ Link >
8285 </ Menu . Item >
8386 </ Fragment >
84- : null }
87+ : < Menu . Item
88+ name = 'signout'
89+ active = { activeItem === 'signout' }
90+ >
91+ < Link to = '/' onClick = { this . handleRemoveCookies } >
92+ < Icon name = 'sign-out' />
93+ Log out
94+ </ Link >
95+ </ Menu . Item > }
8596 </ Menu . Menu >
8697 </ Container >
8798 </ Menu >
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ describe('Navbar', () => {
77 let wrapper
88 const props = {
99 location : { pathname : '/users' } ,
10- cookies : { get : jest . fn ( ) }
10+ cookies : { get : jest . fn ( ) , remove : jest . fn ( ) }
1111 }
1212
1313 beforeEach ( ( ) => {
@@ -53,18 +53,18 @@ describe('Navbar', () => {
5353 expect ( loginLink . text ( ) ) . toEqual ( 'Sign up' )
5454 } )
5555
56- it ( 'renders 9 menu items if a user is not signed in' , ( ) => {
57- expect ( wrapper . find ( 'MenuItem' ) . length ) . toEqual ( 9 )
58- } )
59-
60- it ( 'renders 7 menu items if a user is signed in' , ( ) => {
56+ it ( 'renders a log out link when a user is signed in, which calls handleRemoveCookies function when clicked' , ( ) => {
6157 props . cookies . get . mockReturnValue ( true )
6258 const wrapper = mount (
6359 < Router >
6460 < Navbar { ...props } />
6561 </ Router >
6662 )
67- expect ( wrapper . find ( 'MenuItem' ) . length ) . toEqual ( 7 )
63+ const logOutLink = wrapper . find ( 'a' ) . filterWhere ( item => {
64+ return item . text ( ) === 'Log out'
65+ } )
66+ logOutLink . simulate ( 'click' )
67+ expect ( props . cookies . remove ) . toHaveBeenCalledTimes ( 1 )
6868 } )
6969 } )
7070} )
You can’t perform that action at this time.
0 commit comments