Skip to content

Commit

Permalink
improving redirect tests
Browse files Browse the repository at this point in the history
  • Loading branch information
caiokf committed Nov 18, 2019
1 parent 4a6ddc0 commit 861b216
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
4 changes: 3 additions & 1 deletion spec/route.landing.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ describe('Landing Route', () => {
auth0MockResult.isLoggedIn = jest.fn().mockReturnValue(true)

const wrapper = shallow(<LandingRoute path="http://landing-page.com" loggedInPath="/dashboard" />)
const redirect = wrapper.find(Redirect)

expect(window.ReactRouterAuth0Provider.isLoggedIn).toHaveBeenCalled()
expect(wrapper.find(Redirect)).toHaveLength(1)
expect(redirect).toHaveLength(1)
expect(redirect.prop('to').pathname).toEqual('/dashboard')
})

it('should redirect to the configured path when user is not logged in', () => {
Expand Down
7 changes: 5 additions & 2 deletions spec/route.login.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('Login Route', () => {
auth0MockResult = {
login: jest.fn(),
isLoggedIn: jest.fn(),
options: { rootRoute: '/' },
options: { rootRoute: '/redirect-here-when-logged-in' },
}

window.ReactRouterAuth0Provider = auth0MockResult
Expand All @@ -28,7 +28,10 @@ describe('Login Route', () => {
window.ReactRouterAuth0Provider.isLoggedIn = () => true

const wrapper = shallow(<LoginRoute />)
expect(wrapper.find(Redirect)).toHaveLength(1)
const redirect = wrapper.find(Redirect)

expect(redirect).toHaveLength(1)
expect(redirect.prop('to').pathname).toEqual(auth0MockResult.options.rootRoute)
})

it('should call auth0 login lock screen when user is not logged in', () => {
Expand Down
7 changes: 5 additions & 2 deletions spec/route.logout.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ describe('Logout Route', () => {
it('redirects when rendered', () => {
window.ReactRouterAuth0Provider.isLoggedIn = () => true

const wrapper = shallow(<LogoutRoute />)
expect(wrapper.find(Redirect)).toHaveLength(1)
const wrapper = shallow(<LogoutRoute redirect='/logged-out' />)
const redirect = wrapper.find(Redirect)

expect(redirect).toHaveLength(1)
expect(redirect.prop('to').pathname).toEqual('/logged-out')
})
})

0 comments on commit 861b216

Please sign in to comment.