-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #63 from psinha25/login-test
Login test
- Loading branch information
Showing
2 changed files
with
47 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,49 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import { fireEvent, render, screen } from '@testing-library/react'; | ||
import { MemoryRouter } from 'react-router-dom' | ||
import { Provider } from 'react-redux'; | ||
import { BrowserRouter } from 'react-router-dom'; | ||
import store from '../store'; | ||
import Login from '../components/auth/Login'; | ||
import configureStore from 'redux-mock-store'; | ||
|
||
import Login from '../components/auth/Login.js'; | ||
|
||
const mockStore = configureStore([]); | ||
|
||
const notAuthenticatedStore = mockStore({ | ||
auth: { | ||
token: localStorage.getItem('token'), | ||
isAuthenticated: null, | ||
user: null, | ||
loading: true, | ||
} | ||
}); | ||
|
||
const authenticatedStore = mockStore({ | ||
auth: { | ||
token: localStorage.getItem('token'), | ||
isAuthenticated: true, | ||
user: null, | ||
loading: false, | ||
}, | ||
}); | ||
|
||
describe('Login Component', () => { | ||
it('should be redered without crashing', () => { | ||
render( | ||
<Provider store={notAuthenticatedStore}> | ||
<Login/> | ||
</Provider>, { wrapper: MemoryRouter } | ||
); | ||
expect(screen.getByText('Account Login')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should redirect if the user is logged in', () => { | ||
const { | ||
container, | ||
} = render( | ||
<Provider store={authenticatedStore}> | ||
<Login/> | ||
</Provider>, { wrapper: MemoryRouter } | ||
); | ||
expect(container).toMatchInlineSnapshot(`<div />`); | ||
}); | ||
|
||
test('renders without crashing', () => { | ||
render( | ||
<Provider store={store}> | ||
<BrowserRouter> | ||
<Login /> | ||
</BrowserRouter> | ||
</Provider> | ||
); | ||
expect(screen.getByText('Account Login')).toBeInTheDocument(); | ||
}); |