Skip to content

Commit

Permalink
Update SecuredRouteForUser.test.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
duplixx authored Nov 11, 2023
1 parent be1fb7b commit 09a9bf0
Showing 1 changed file with 14 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,40 +1,38 @@
import React from "react";
import { MemoryRouter, Route } from "react-router-dom";
import { render, screen, waitFor } from "@testing-library/react";
import SecuredRouteForUser from "./SecuredRouteForUser";
import React from 'react';
import { MemoryRouter, 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", () => {
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");
localStorage.setItem('IsLoggedIn', 'TRUE');

render(
<MemoryRouter initialEntries={["/user/organizations"]}>
<MemoryRouter initialEntries={['/user/organizations']}>
<Route
path="/user/organizations"
render={() => (
<SecuredRouteForUser
path="/user/organizations"
component={() => (
<div data-testid="organizations-content">
Organizations Component
</div>
<div data-testid="organizations-content">Organizations Component</div>
)}
/>
)}
/>
</MemoryRouter>,
);

expect(screen.getByTestId("organizations-content")).toBeInTheDocument();
expect(screen.getByTestId('organizations-content')).toBeInTheDocument();
});

test("redirects to /user when the user is not logged in", async () => {
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");
localStorage.setItem('IsLoggedIn', 'FALSE');

render(
<MemoryRouter initialEntries={["/secured"]}>
<MemoryRouter initialEntries={['/secured']}>
<Route
path="/secured"
exact
Expand All @@ -48,7 +46,7 @@ describe("SecuredRouteForUser", () => {
);

await waitFor(() => {
expect(window.location.pathname).toBe("/");
expect(window.location.pathname).toBe('/');
});
});
});

0 comments on commit 09a9bf0

Please sign in to comment.