generated from nimblehq/git-template
-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
3ea12fc
commit e73941c
Showing
4 changed files
with
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,4 +37,4 @@ function PrivateRoute() { | |
); | ||
} | ||
|
||
export default PrivateRoutes; | ||
export default 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 |
---|---|---|
|
@@ -8,14 +8,22 @@ import AuthAdapter from 'adapters/authAdapter'; | |
import { User } from 'types/User'; | ||
|
||
import Sidebar from '.'; | ||
// import * as localStorage from '../../helpers/localStorage'; | ||
import * as myStorage from '../../helpers/localStorage'; | ||
|
||
const mockUserProfileData = { | ||
email: '[email protected]', | ||
name: 'TestName', | ||
avatar_url: 'https://secure.gravatar.com/avatar/6733d09432e89459dba795de8312ac2d', | ||
}; | ||
|
||
const mockTokenData = { | ||
access_token: 'test_access_token', | ||
refresh_token: 'test_refresh_token', | ||
token_type: 'Bearer', | ||
expires_in: 7200, | ||
created_at: 1677045997, | ||
}; | ||
|
||
describe('Sidebar', () => { | ||
const user: User = { name: 'Test User', email: '[email protected]', avatarUrl: mockUserProfileData.avatar_url }; | ||
|
||
|
@@ -31,11 +39,13 @@ describe('Sidebar', () => { | |
test('renders a sidebar on the page with a logout button that when clicked, calls Logout adapter and removes storage', async () => { | ||
const mockLogout = jest.spyOn(AuthAdapter, 'logout'); | ||
|
||
// jest.spyOn(localStorage, 'getItem').mockImplementation(() => { | ||
// return { auth: 'mockTokenData', user: mockUserProfileData }; | ||
// }); | ||
// const mockClearToken = jest.spyOn(myStorage, 'clearItem'); | ||
|
||
// const mockStorageClear = jest.spyOn(localStorage, 'clearItem'); | ||
const storageMock = jest.spyOn(myStorage, 'getItem').mockImplementationOnce(() => { | ||
return { auth: mockTokenData, user: mockUserProfileData }; | ||
}); | ||
|
||
expect(myStorage.getItem('UserProfile')).not.toBeNull(); | ||
|
||
render(<Sidebar user={user} />, { wrapper: BrowserRouter }); | ||
|
||
|
@@ -45,8 +55,11 @@ describe('Sidebar', () => { | |
|
||
expect(mockLogout).toBeCalledTimes(1); | ||
|
||
// expect(mockStorageClear).toBeCalled(); | ||
expect(myStorage.getItem('UserProfile')).toBeNull(); | ||
|
||
// navigates to LOGIN URL | ||
// useNavigate is not called because redirect is handled in axios interceptor? Mock window.location.href instead? | ||
|
||
storageMock.mockRestore(); | ||
}); | ||
}); |