diff --git a/src/components/UserPortal/SecuredRouteForUser/SecuredRouteForUser.test.tsx b/src/components/UserPortal/SecuredRouteForUser/SecuredRouteForUser.test.tsx new file mode 100644 index 0000000000..d5aa053fbd --- /dev/null +++ b/src/components/UserPortal/SecuredRouteForUser/SecuredRouteForUser.test.tsx @@ -0,0 +1,53 @@ +import React from 'react'; +import { MemoryRouter, Redirect, Route } from 'react-router-dom'; +import { render, screen, waitFor } from '@testing-library/react'; +import SecuredRouteForUser from './SecuredRouteForUser'; + +describe('SecuredRouteForUser', () => { + test('renders the route when the user is logged in', () => { + // Set the 'IsLoggedIn' value to 'TRUE' in localStorage to simulate a logged-in user + localStorage.setItem('IsLoggedIn', 'TRUE'); + + const { container } = render( + + ( +
+ Organizations Component +
+ )} + /> +
+ ); + + expect(screen.getByTestId('organizations-content')).toBeInTheDocument(); + }); + + test('redirects to /user when the user is not logged in', async () => { + // Set the user as not logged in in local storage + localStorage.setItem('IsLoggedIn', 'FALSE'); + + const { container } = render( + + ( + +
Secured Content
+
+ )} + /> +
+ ); + + // Ensure that the redirect to / occurred + // waitFor(() => { + // expect(window.location.pathname).toBe('/user'); + // } + await waitFor(() => { + expect(window.location.pathname).toBe('/'); + }); + }); +});