frontend/docs/testing/GUIDELINES.md
This document defines the rules and requirements for writing test scenarios and documentation for the Rivet Inspector frontend.
Test documentation should:
✅ Good: "User is informed about connection failure" ❌ Bad: "Display error message: 'Connection failed. Please check your server is running at http://localhost:6420'"
Why: We care that users are informed, not the exact wording or format.
✅ Good: "Error details are shown"
❌ Bad: "Error message format: Error: {message}"
Why: UI text changes frequently. Test the presence of information, not exact formatting.
Every test should verify:
Include:
Exclude:
When information is shared across multiple scenarios:
references/Example: Instead of repeating all Rivet Actor states in every test, reference actor-states.md.
# [Feature] Testing Scenarios
## Quick Reference
- Links to reference documents
## Testing Environment
- URLs, endpoints, prerequisites
## Critical User Flows
### Flow N: [Flow Name]
**Scenario**: Brief description
**Prerequisites** (if needed): What must be true before testing
**Verify**:
- Point 1
- Point 2
OR
**Test Cases**:
#### TCN.N: [Test Case Name]
**Given**: Initial conditions
**When**: User action
**Then**: Expected outcome (high-level)
# [Topic] Reference
## [Category]
### [Item Name]
**When**: Condition when this applies
**User is informed about**:
- Information point 1
- Information point 2
**Available actions**:
- Action 1
- Action 2
**Displays** (optional):
- UI element 1
- UI element 2
Use "Verify" sections for bullet-point checks:
**Verify**:
- Feature works as expected
- Data is displayed
- Actions are available
Use "User is informed about" for error/information states:
**User is informed about**:
- What went wrong
- How to fix it
Use "Available actions" for what users can do:
**Available actions**:
- Retry connection
- Modify settings
Use Scenario for:
Use Test Case for:
Format: TC[Flow].[Case]
Examples:
TC1.1 - Flow 1, Test Case 1TC5.14 - Flow 5, Test Case 14Format: I[Number]
Examples:
I1 - Integration Test 1I4 - Integration Test 4Format: E[Number]
Examples:
E1 - Edge Case 1E3 - Edge Case 3Use lowercase with hyphens:
connection-states.mdactor-states.mderror-states.mdui-components.md✅ Good:
**Verify**:
- Rivet Actor state updates when changed
- Events appear in real-time
❌ Bad:
**Verify**:
- When actor state changes from {old} to {new}, the UI updates within 100ms showing the new state in JSON format
✅ Good:
**When**: Connection fails
**User is informed about**:
- Connection failure
- Possible reasons
**Available actions**:
- Retry connection
❌ Bad:
**When**: Connection fails
**Then**: Show red error banner with text "Connection failed: ERR_CONNECTION_REFUSED. Please check that your server is running." and a "Retry" button in blue
✅ Good:
**Verify**:
- Rivet Actor can be created
- Rivet Actor appears in list after creation
❌ Bad:
**Steps**:
1. Click the "+" button next to "Game Session"
2. Fill in the form fields: name, region, max_players
3. Click "Create" button
4. Wait for success toast message
5. Verify actor appears in sidebar with green dot
### Flow 1: First-Time Visit
**Scenario**: User visits inspector URL without a running RivetKit server
**Verify**:
- Getting started card is displayed
- Connection form is shown with default endpoint
- User can enter custom endpoint
- Connect button is available
### Flow 1: First-Time Visit Without Server Running on Default Port
**Scenario**: When a user who has never used the inspector before opens the URL http://localhost:5173 in their Chrome browser and there is no RivetKit server running on port 6420
**Expected Behavior**:
- The page should render with a white background
- A card titled "Getting Started with Rivet Inspector" should appear centered on the screen
- Below that, a form with a single input field labeled "Endpoint" containing the placeholder text "http://localhost:6420" should be visible
- A blue button labeled "Connect" should be displayed below the input
- When hovering over the button, it should turn a darker shade of blue
Before submitting test documentation, verify:
When updating test documentation:
When writing or updating test documentation:
When implementing e2e tests with Playwright:
Prefer test IDs over other selectors: Use data-testid attributes for stable element selection
page.getByTestId("onboarding-path-agent")page.getByText("Use Coding Agent")Add test IDs to components when needed: If a component lacks a test ID, add one manually
data-testid="onboarding-path-agent"Fallback hierarchy (when test IDs are not available):
getByRole() - for accessible elements (buttons, links, headings)getByLabel() - for form inputsgetByPlaceholder() - for inputs with placeholdersgetByText() - last resort, avoid exact matchingFormat: {feature}-{element}-{variant?}
Examples:
onboarding-path-agent - Agent path option in onboardingonboarding-path-template - Template path option in onboardingonboarding-back-button - Back button in onboardingtemplate-card-chat-room - Chat room template cardWhen adding a test ID to a React component:
// In the component
<Button data-testid="onboarding-submit">Continue</Button>
// In the test
await page.getByTestId("onboarding-submit").click();
Use visual regression testing as much as possible to catch unintended UI changes:
Capture full page screenshots for key states:
await expect(page).toHaveScreenshot("onboarding-path-selection.png");
Capture component screenshots for specific elements:
const card = page.getByTestId("onboarding-path-agent");
await expect(card).toHaveScreenshot("agent-card.png");
When to use screenshots:
Screenshot naming convention: {feature}-{state}.png
onboarding-path-selection.pngonboarding-provider-step.pngonboarding-error-invalid-endpoint.pngUpdate baselines when intentional UI changes are made:
pnpm test:e2e --update-snapshots