Skip to main content

ProtectedRoute

Test: User is authenticated

  • Description: Verifies the behavior of the ProtectedRoute component when the user is authenticated.
  • Setup: Mock the useAuth hook to return a mock user object with authentication data.
  • Expectation: The protected route should render successfully, displaying the main content and navigation bar.
  • Assertion 1: Asserts that the main content area (shell-main) is present in the rendered component.
  • Assertion 2: Asserts that the navigation bar (shell-navbar) is present in the rendered component.
  • Assertion 3: Asserts that the logo (navbar-logo) is present in the rendered navigation bar.

Test: User without authenticated session

  • Description: Ensures the behavior of the ProtectedRoute component when the user does not have an authenticated session.
  • Setup: Mock the useAuth hook to return undefined, simulating an unauthenticated user session.
  • Expectation: The protected route should not render any content.
  • Assertion: Asserts that the shell component (shell) is not present in the rendered component.

Additional Considerations

  • Mocking the useAuth hook allows us to control the authentication state in our test cases, enabling us to test both authenticated and unauthenticated scenarios.
  • Ensure that the useAuth hook is properly mocked to simulate different authentication states.