This document outlines key integration tests for the public view system, including the PublicHome page and routing behaviors. These tests would typically be implemented using a framework like Cypress or Playwright, combined with React Testing Library for component interactions where appropriate.
Setup:
- Ensure the backend server is running and accessible.
- Mock or seed the database with a known set of public and private snippets. Include snippets with various languages and tags.
- Use a testing utility or direct API calls to
/api/public/snippetsto verify data setup.
Test Scenarios:
-
Initial Load and Display:
- Description: Verify that
PublicHomefetches and displays public snippets correctly on initial load. - Steps:
- Navigate to the
/route as an unauthenticated user. - Observe that the
PublicHomecomponent renders. - Check that a list/grid of snippets is displayed.
- Verify that only snippets marked
isPublic: truein the database are shown. - Confirm that elements like the header, tagline, and "Sign In" button are present.
- Check for loading states while data is being fetched.
- Navigate to the
- Assertions:
- Correct number of public snippets displayed.
- Snippet cards show appropriate information (title, description snippet, language, "Public" badge).
- No private snippets are visible.
- Header and sign-in elements are visible.
- Description: Verify that
-
Search Functionality:
- Description: Test if searching filters the displayed public snippets.
- Steps:
- On
PublicHome, type a search term (e.g., a keyword from a known public snippet's title or description) into the search bar. - Observe the list of snippets updating.
- On
- Assertions:
- Only snippets matching the search term are displayed.
- If the search term matches no public snippets, an appropriate "No public snippets found" message is shown.
- The filtering should be reasonably fast (client-side or server-side depending on implementation).
-
Filter Functionality (Language/Tags):
- Description: Test if filtering by language (and tags, if implemented) works correctly.
- Steps:
- On
PublicHome, select a language from the language filter dropdown. - Observe the list of snippets updating.
- (If applicable) Select a tag from a tag filter dropdown and observe further filtering.
- On
- Assertions:
- Only snippets matching the selected language (and/or tag) are displayed.
- Combining search and filters works as expected.
- If no snippets match the filter criteria, an appropriate message is shown.
-
Empty State:
- Description: Verify the behavior when no public snippets are available or match filters.
- Steps:
- Ensure the database has no snippets marked
isPublic: true. - Navigate to
PublicHome. - OR: Apply filters that result in no matches.
- Ensure the database has no snippets marked
- Assertions:
- The correct "No public snippets found" (or similar) message is displayed.
- The layout remains intact.
-
Sign-In Button Navigation:
- Description: Ensure the "Sign In" button navigates to the login flow.
- Steps:
- On
PublicHome, click the "Sign In / Sign Up" button.
- On
- Assertions:
- The user is redirected to the application's login page/mechanism (e.g.,
/loginor triggers the Firebase auth flow).
- The user is redirected to the application's login page/mechanism (e.g.,
Setup:
- As above, backend running with mixed public/private data.
- Ability to simulate user login/logout within the test environment.
Test Scenarios:
-
Unauthenticated User Access:
- Description: Verify routes accessible to unauthenticated users.
- Steps:
- As an unauthenticated user, navigate to
/. - Navigate to
/shared/:shareId(using a share ID of a public snippet). - Navigate to
/shared/:shareId(using a share ID of a private snippet). - Attempt to navigate to an authenticated route (e.g.,
/snippetsor/settings).
- As an unauthenticated user, navigate to
- Assertions:
/loadsPublicHome./shared/:shareIdfor a public snippet loads theSharedSnippetpage and displays the snippet./shared/:shareIdfor a private snippet either shows a "not found/access denied" message withinSharedSnippetor redirects (behavior depends onSharedSnippetimplementation).- Access to
/snippetsor/settingsredirects toPublicHome(or the login page).
-
Authenticated User Access:
- Description: Verify routes and UI changes for authenticated users.
- Steps:
- Log in as a user.
- Navigate to
/. - Navigate to other authenticated routes like
/snippets,/collections. - Navigate to
/shared/:shareId(using a share ID of a snippet they own, and one they don't but is public).
- Assertions:
/loads the authenticated dashboard (e.g.,Home.tsxfor authenticated users, notPublicHome).- Authenticated routes are accessible and render correctly.
- Layout for authenticated users includes the sidebar and full header.
- Snippet cards on authenticated pages show owner controls for owned snippets.
SharedSnippetpage works correctly for owned and public shared snippets.
-
Navigation from Public to Authenticated:
- Description: Test the transition when a user signs in from
PublicHome. - Steps:
- Start on
PublicHomeas an unauthenticated user. - Click "Sign In" and complete the login process.
- Start on
- Assertions:
- After successful login, the user is redirected to the authenticated dashboard (e.g.,
/). - The UI updates to the authenticated layout (sidebar appears, etc.).
- After successful login, the user is redirected to the authenticated dashboard (e.g.,
- Description: Test the transition when a user signs in from
Note: These depend heavily on SharedSnippet.tsx's internal logic, which also needs to be context-aware.
- Public Shared Snippet (Unauthenticated User):
- Description: An unauthenticated user views a publicly shared snippet.
- Assertions: Snippet content is visible. No owner controls.
- Private Shared Snippet (Unauthenticated User):
- Description: An unauthenticated user attempts to view a private shared snippet.
- Assertions: Snippet content is NOT visible. A "not found" or "access denied" message is shown.
- Private Shared Snippet (Authenticated Owner):
- Description: The owner views their own private shared snippet.
- Assertions: Snippet content is visible. Owner controls might be visible (depends on design).
- Private Shared Snippet (Authenticated Non-Owner):
- Description: An authenticated user (not the owner) attempts to view a private shared snippet.
- Assertions: Snippet content is NOT visible. A "not found" or "access denied" message.
- Public Shared Snippet (Authenticated User):
- Description: An authenticated user views a public snippet (owned by someone else).
- Assertions: Snippet content is visible. No owner controls.