diff --git a/src/components/PrivateRoutes/index.test.tsx b/src/components/PrivateRoutes/index.test.tsx new file mode 100644 index 0000000..5071eff --- /dev/null +++ b/src/components/PrivateRoutes/index.test.tsx @@ -0,0 +1,39 @@ +/* eslint-disable camelcase */ +import { MemoryRouter } from 'react-router-dom'; + +import { render, screen } from '@testing-library/react'; + +import PrivateRoutes from '.'; +import { setItem } from '../../helpers/localStorage'; + +const mockTokenData = { + access_token: 'test_access_token', + refresh_token: 'test_refresh_token', + token_type: 'Bearer', + expires_in: 7200, + created_at: 1677045997, +}; + +const mockUserProfileData = { + email: 'testemail@gmail.com', + name: 'TestName', + avatar_url: 'https://secure.gravatar.com/avatar/6733d09432e89459dba795de8312ac2d', +}; + +describe('PrivateRoutes', () => { + test('renders a PrivateRoute given authenticated user', async () => { + setItem('UserProfile', { auth: mockTokenData, user: mockUserProfileData }); + + render(, { wrapper: MemoryRouter }); + + expect(localStorage.getItem).toBeCalledWith('UserProfile'); + + // expect(screen.getByTestId('app-main-heading')); + }); + + test.skip('renders a PrivateRoute', async () => { + render(, { wrapper: MemoryRouter }); + + expect(screen.getByTestId('loading')); + }); +}); diff --git a/src/components/PrivateRoutes/index.tsx b/src/components/PrivateRoutes/index.tsx index ce3c46d..de16f10 100644 --- a/src/components/PrivateRoutes/index.tsx +++ b/src/components/PrivateRoutes/index.tsx @@ -24,7 +24,7 @@ function PrivateRoutes() { }, []); if (loading) { - return

Loading...

; + return

Loading...

; } return user ? (