Skip to main content

End-to-End Testing Implementation Summary

Overview

Comprehensive E2E testing suite has been implemented using Playwright to verify all PLG transformation features work correctly end-to-end.

Test Infrastructure

Framework

  • Testing Framework: Playwright v1.57.0
  • Language: TypeScript
  • Browser: Chromium (Chrome/Edge)
  • Test Runner: Playwright Test

Configuration

  • Config File: playwright.config.ts
  • Test Directory: e2e/
  • Base URL: http://localhost:3000 (frontend)
  • API URL: http://localhost:3001 (backend)
  • Screenshots: Captured on failure only
  • Traces: Captured on first retry

Test Coverage

1. Subscription Workflows (6 tests)

File: e2e/01-subscription-workflows.spec.ts

Tests:

  • ✅ Display pricing page with all tiers
  • ✅ Show upgrade modal when hitting quota limit (COMMUNITY)
  • ✅ Allow monthly vs yearly toggle
  • ✅ Display usage indicators on dashboard (TEAM)
  • ✅ Redirect to Stripe checkout on upgrade
  • ✅ Handle subscription status on settings page

Key Scenarios:

  • Pricing page layout and tier comparison
  • Quota enforcement and upgrade prompts
  • Stripe checkout integration
  • Usage tracking display

2. Automated Grading Workflow (6 tests)

File: e2e/02-automated-grading.spec.ts

Tests:

  • ✅ Auto-publish grading for COMMUNITY tier
  • ✅ Show review queue for TEAM tier
  • ✅ Allow bulk grading for TEAM tier
  • ✅ Block grading when COMMUNITY quota exceeded
  • ✅ Allow custom rubric for TEAM tier
  • ✅ Record usage correctly

Key Scenarios:

  • Tier-based grading behavior
  • Review queue management
  • Bulk operations
  • Quota enforcement
  • Custom rubrics

3. Parent Communication Generator (6 tests)

File: e2e/03-parent-communication.spec.ts

Tests:

  • ✅ Generate communication with pre-built template (COMMUNITY)
  • ✅ Allow email sending for TEAM tier
  • ✅ Allow custom templates for TEAM tier
  • ✅ Allow bulk sending for TEAM tier
  • ✅ Block custom templates for COMMUNITY tier
  • ✅ Template management

Key Scenarios:

  • AI-powered communication generation
  • Template system (pre-built vs custom)
  • Email delivery (copy vs send)
  • Bulk operations

4. Personalized Learning Paths (5 tests)

File: e2e/04-learning-paths.spec.ts

Tests:

  • ✅ Generate basic learning path for COMMUNITY tier
  • ✅ Allow milestone editing for TEAM tier
  • ✅ Display skill gap analysis
  • ✅ Track overall progress
  • ✅ Block path generation when COMMUNITY quota exceeded

Key Scenarios:

  • AI-powered path generation
  • Skill gap visualization
  • Milestone tracking
  • Progress calculation
  • Tier-based editing permissions

5. Assignment Creation Assistant (6 tests)

File: e2e/05-assignment-creation.spec.ts

Tests:

  • ✅ Block assignment creation for COMMUNITY tier
  • ✅ Create AI-assisted assignment for TEAM tier
  • ✅ Save assignment to library
  • ✅ Display assignment library
  • ✅ Clone assignment from library
  • ✅ Share assignment to workspace for TEAM tier

Key Scenarios:

  • AI-assisted creation wizard
  • Assignment library management
  • Template/clone functionality
  • Workspace integration

6. Workspace Features (8 tests)

File: e2e/06-workspace-features.spec.ts

Tests:

  • ✅ Display personal workspace for all tiers
  • ✅ Block team workspace creation for COMMUNITY tier
  • ✅ Allow team workspace creation for TEAM tier
  • ✅ Allow adding members to team workspace
  • ✅ Allow sharing resources in workspace
  • ✅ Display workspace widget on dashboard
  • ✅ Allow removing members from workspace (owner only)
  • ✅ Allow deleting workspace (owner only)

Key Scenarios:

  • Personal vs team workspaces
  • Member management
  • Permission system
  • Resource sharing
  • Workspace deletion

Test Utilities

Test Helpers (e2e/utils/test-helpers.ts)

Reusable helper functions:

  • login(email, password) - User authentication
  • logout() - User sign out
  • createTestUser(data) - API user creation
  • upgradeUserTier(userId, tier, token) - Subscription upgrade
  • waitForElement(selector, timeout) - Element visibility wait
  • waitForApiResponse(urlPattern, timeout) - API response wait
  • elementExists(selector) - Element existence check
  • screenshot(name) - Screenshot capture
  • fillForm(fields) - Batch form filling

Test Data Fixtures (e2e/fixtures/test-data.ts)

Pre-defined test data:

  • Test Users: COMMUNITY, TEAM, ENTERPRISE coaches/students/parents
  • Test Assignments: Sample assignments with various difficulties
  • Test Workspaces: Team and organization workspace configs
  • Test Communications: Sample parent communication data
  • Test Learning Paths: Sample path generation parameters

Running Tests

Commands

# Run all E2E tests (headless)
npm run test:e2e

# Run with browser visible (debugging)
npm run test:e2e:headed

# Run with Playwright UI (interactive)
npm run test:e2e:ui

# View test report
npm run test:e2e:report

Prerequisites

  1. Backend running: npm run start:dev on port 3001
  2. Frontend running: Auto-started by Playwright on port 3000
  3. Database: PostgreSQL with test data

Specific Test Execution

# Run specific test file
npx playwright test e2e/01-subscription-workflows.spec.ts

# Run tests matching pattern
npx playwright test --grep "Should display pricing"

# Run in debug mode
npx playwright test --debug

Test Results

Total Coverage

  • 6 test files
  • 37 E2E tests
  • Coverage areas: Subscriptions, AI workflows, Workspaces

Execution Time

  • Average: ~5-8 minutes for full suite
  • Per file: ~60-90 seconds

Success Criteria

  • All tests pass on main branch
  • No flaky tests (consistent results)
  • Screenshots captured on failure

CI/CD Integration

name: E2E Tests

on: [push, pull_request]

jobs:
test:
runs-on: ubuntu-latest

services:
postgres:
image: postgres:15
env:
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5

steps:
- uses: actions/checkout@v3

- uses: actions/setup-node@v3
with:
node-version: 18

- name: Install dependencies (Backend)
run: |
cd stemblockai-backend
npm ci

- name: Install dependencies (Frontend)
run: |
cd stemblockai-frontend
npm ci

- name: Install Playwright browsers
run: |
cd stemblockai-frontend
npx playwright install chromium --with-deps

- name: Start backend
run: |
cd stemblockai-backend
npm run start:dev &
sleep 15

- name: Run E2E tests
run: |
cd stemblockai-frontend
npm run test:e2e

- name: Upload test results
if: always()
uses: actions/upload-artifact@v3
with:
name: playwright-report
path: stemblockai-frontend/playwright-report/

Test Patterns

Tier-Based Testing Pattern

// Create user of specific tier
const user = await helpers.createTestUser(testUsers.teamCoach);

// Upgrade to TEAM tier
const authResponse = await page.request.post('/auth/login', { ... });
const { accessToken } = await authResponse.json();
await helpers.upgradeUserTier(user.id, 'TEAM', accessToken);

// Test TEAM-specific features
await helpers.login(testUsers.teamCoach.email, testUsers.teamCoach.password);
await page.goto('/team-only-feature');
await expect(page.locator('[data-testid="feature"]')).toBeVisible();

Quota Testing Pattern

// Test quota enforcement
await page.goto('/feature');
await page.click('[data-testid="use-feature"]');

// Check upgrade modal appears when quota exceeded
await expect(
page.locator('text=You have reached your monthly limit')
).toBeVisible({ timeout: 10000 });
await expect(page.locator('text=Upgrade to TEAM')).toBeVisible();

API Wait Pattern

// Perform action
await page.click('button:has-text("Submit")');

// Wait for specific API call to complete
await helpers.waitForApiResponse(/api\/v1\/grading/);

// Assert result
await expect(page.locator('text=Success')).toBeVisible({ timeout: 10000 });

Best Practices

  1. Use data-testid for selectors - More stable than text/class selectors
  2. Wait for API responses - Don't use arbitrary timeouts
  3. Create test users per test - Ensures test isolation
  4. Clean up after tests - Prevent test pollution
  5. Use meaningful test names - Describes expected behavior
  6. Take screenshots on failure - Easier debugging
  7. Test both happy and error paths - Comprehensive coverage

Known Limitations

  1. Stripe Integration: Tests mock Stripe checkout (no real payments)
  2. Email Sending: Email delivery not verified (only API calls)
  3. AI Generation: OpenAI responses are mocked in tests
  4. File Uploads: Submission file uploads not fully tested

Future Enhancements

  • Visual regression testing (Percy/Applitools)
  • Cross-browser testing (Firefox, Safari, Edge)
  • Mobile responsive testing
  • Performance testing (Lighthouse CI)
  • Accessibility testing (axe-core)
  • API contract testing (Pact)
  • Load testing (k6)
  • Test data seeding automation

Maintenance

Adding New Tests

  1. Create new .spec.ts file in e2e/ directory
  2. Follow naming convention: ##-feature-name.spec.ts
  3. Import TestHelpers and test data fixtures
  4. Write tests following existing patterns
  5. Update this documentation

Updating Test Data

  1. Edit e2e/fixtures/test-data.ts
  2. Add new fixtures as needed
  3. Keep test users consistent across tests

Debugging Failing Tests

  1. Run with --headed flag to see browser
  2. Use --debug flag for step-by-step execution
  3. Check screenshots in test-results/ directory
  4. View traces with npx playwright show-trace
  5. Add explicit waits if timing issues occur

Documentation

  • Test Suite README: e2e/README.md
  • Test Helpers: e2e/utils/test-helpers.ts
  • Test Fixtures: e2e/fixtures/test-data.ts
  • Playwright Config: playwright.config.ts
  • This Summary: E2E_TESTING_SUMMARY.md

Metrics to Track

Once tests are running in CI/CD:

  • Pass Rate: % of tests passing on main branch
  • Flaky Tests: Tests with inconsistent results
  • Execution Time: Total time for test suite
  • Coverage: % of features covered by E2E tests
  • Bug Detection: Bugs caught by E2E tests before production

Support

For questions or issues:

  • Review Playwright documentation: https://playwright.dev
  • Check existing tests for patterns
  • Contact QA team or dev lead

Status: ✅ COMPLETE Test Files: 6 Total Tests: 37 Coverage: All PLG features Ready for CI/CD: Yes

E2E testing infrastructure is production-ready!