Skip to content

[EPIC][TESTING]: Frontend testing and code quality #2270

@crivetimihai

Description

@crivetimihai

🎨 Epic: Frontend Testing & Code Quality

Goal

Establish comprehensive testing, documentation, and code quality standards for the Admin UI frontend. This includes adding JavaScript unit testing, improving Playwright UI automation, documenting all frontend code, and refactoring the monolithic admin.js (31K lines) into maintainable modules.

Why Now?

The Admin UI has grown significantly with HTMX, Alpine.js, and custom visualizations (Gantt charts, flame graphs). Current gaps:

  1. No JS Unit Tests: admin.js, gantt-chart.js, flame-graph.js have zero unit test coverage
  2. Large Monolith: admin.js is 31,287 lines with 40+ logical sections—difficult to maintain and test
  3. No JSDoc: Functions lack parameter/return type documentation
  4. Playwright Gaps: UI automation tests need updates for new auth flow and broader CRUD coverage
  5. No Type Safety: Plain JavaScript without TypeScript or tsc --checkJs validation
  6. Performance Monitoring: No automated Lighthouse CI checks for regressions

📖 User Stories

US-1: Add JavaScript Unit Testing Framework

As a developer
I want a JS unit testing framework (Jest or Vitest) configured
So that I can write and run unit tests for frontend code

Acceptance Criteria:

Scenario: Run JavaScript unit tests
  Given Jest or Vitest is configured in package.json
  When I run "make test-js"
  Then all JavaScript unit tests should execute
  And test results should be displayed

Scenario: Test coverage reporting
  Given tests exist for utility functions
  When I run "make coverage-js"
  Then a coverage report should be generated in coverage/js/
  And coverage percentage should be displayed

Scenario: CI integration
  Given a PR is opened with JS changes
  When CI runs
  Then JavaScript tests should run alongside Python tests
  And CI should fail if tests fail

Technical Requirements:

  • Jest or Vitest configured in package.json
  • Test files use *.test.js or *.spec.js naming
  • make test-js target runs JavaScript tests
  • Initial tests cover utility functions in admin.js
US-2: Split admin.js into Modular Components

As a developer
I want admin.js (31K lines, 40+ sections) split into logical ES6 modules
So that the codebase is maintainable, testable, and easier to navigate

Acceptance Criteria:

Scenario: Modules are importable
  Given admin.js is split into modules
  When I import a specific module (e.g., auth.js)
  Then only that module's code should be loaded
  And the module should export its public functions

Scenario: No functionality regression
  Given the refactored modular code
  When all Playwright tests run
  Then all tests should pass
  And UI behavior should be identical to before

Scenario: Maintainable file sizes
  Given the modular structure
  Then no single file should exceed 1000 lines
  And each file should have a single responsibility

Technical Requirements:

  • Create modules: chart-registry.js, auth.js, crud-operations.js, metrics.js, modals.js, form-validation.js, team-management.js, a2a-agents.js, bulk-import.js, llm-settings.js, htmx-handlers.js, utilities.js
  • Main admin.js imports and initializes modules
  • No functionality regression after split
US-3: Fix Playwright Tests for Admin Auth Flow

As a QA engineer
I want Playwright tests updated to use the new Admin Email/Password login
So that UI automation runs successfully in CI

Acceptance Criteria:

Scenario: Playwright authenticates with new flow
  Given the new email/password login flow
  When Playwright tests run
  Then tests should authenticate using ADMIN_EMAIL/ADMIN_PASSWORD
  And login should succeed before test execution

Scenario: Session persistence
  Given a test that requires authentication
  When multiple tests run in sequence
  Then authentication should persist across tests
  And no re-login should be needed per test

Technical Requirements:

  • Playwright tests authenticate with ADMIN_EMAIL/ADMIN_PASSWORD
  • Login flow tests pass in CI
  • Tests handle JWT cookie authentication correctly
US-4: Increase Playwright Test Coverage

As a QA engineer
I want Playwright tests covering all Admin UI CRUD operations
So that UI regressions are caught automatically

Acceptance Criteria:

Scenario: Server CRUD tests
  Given the Servers page in Admin UI
  Then tests should cover: create, edit, toggle, delete server

Scenario: Tool CRUD tests
  Given the Tools page in Admin UI
  Then tests should cover: create, edit, test tool, delete tool

Scenario: All entities covered
  Given all entity types (servers, tools, resources, prompts, gateways, agents)
  Then each should have CRUD Playwright tests
  And tests should run in CI pipeline

Technical Requirements:

  • Tests for Servers: create, edit, toggle, delete
  • Tests for Tools: create, edit, test tool, delete
  • Tests for Resources, Prompts, Gateways, Agents
  • All tests run in CI pipeline
US-5: Add JSDoc Documentation

As a developer
I want comprehensive JSDoc documentation on all JS files
So that functions have documented parameters, return types, and examples

Acceptance Criteria:

Scenario: Functions have JSDoc
  Given any exported function in the codebase
  Then it should have a JSDoc comment with @param and @returns
  And complex functions should have @example blocks

Scenario: ESLint enforces JSDoc
  Given the ESLint configuration
  When linting runs on a function without JSDoc
  Then a warning should be generated

Technical Requirements:

  • All exported functions have JSDoc comments
  • Parameters documented with @param {type} name - description
  • Return values documented with @returns {type}
  • ESLint rule enforces JSDoc on public functions
US-6: Add TypeScript Type Checking

As a developer
I want JSDoc + TypeScript type checking enabled
So that I get type safety without a full TypeScript migration

Acceptance Criteria:

Scenario: Type errors caught at build time
  Given a function with incorrect types
  When "make typecheck-js" runs
  Then type errors should be reported
  And CI should fail on type errors

Scenario: IDE type hints
  Given VSCode with TypeScript support
  When editing JavaScript files
  Then type hints should appear from JSDoc annotations

Technical Requirements:

  • tsconfig.json with allowJs: true, checkJs: true
  • tsc --noEmit reports type errors
  • make typecheck-js target runs type checking
  • CI fails on type errors

🏗 Architecture

Proposed Module Structure

mcpgateway/static/
├── admin.js              # Main entry point (imports modules)
├── modules/
│   ├── auth.js           # Authentication handling
│   ├── chart-registry.js # Chart.js instance management
│   ├── crud-operations.js# CRUD with validation
│   ├── metrics.js        # Metrics display and loading
│   ├── modals.js         # Modal functions
│   ├── form-validation.js# Form validation
│   ├── team-management.js# Team functions
│   ├── a2a-agents.js     # A2A agent functionality
│   ├── bulk-import.js    # Bulk import tools
│   ├── llm-settings.js   # LLM configuration
│   ├── htmx-handlers.js  # HTMX event handlers
│   └── utilities.js      # Shared utilities
├── gantt-chart.js        # Gantt chart component
└── flame-graph.js        # Flame graph component

Testing Architecture

flowchart TD
    A[JavaScript Source] --> B[Jest/Vitest]
    B --> C[Unit Tests]
    C --> D[Coverage Report]
    
    A --> E[Playwright]
    E --> F[E2E Tests]
    F --> G[Screenshots]
    
    A --> H[tsc --checkJs]
    H --> I[Type Errors]
    
    A --> J[ESLint + Biome]
    J --> K[Lint Errors]
Loading

📋 Implementation Tasks

Phase 1: Unit Testing Setup

  • Add make test-js target
  • Add make coverage-js target
  • Write initial tests for utility functions
  • Add CI workflow step for JS tests

Phase 2: Playwright Auth Fix

  • Update Playwright auth to use ADMIN_EMAIL/ADMIN_PASSWORD
  • Create auth fixture for test reuse
  • Verify login flow tests pass
  • Handle JWT cookie authentication

Phase 3: Playwright CRUD Coverage

  • Add Server CRUD tests
  • Add Tool CRUD tests
  • Add Resource CRUD tests
  • Add Prompt CRUD tests
  • Add Gateway CRUD tests
  • Add Agent CRUD tests

Phase 4: Module Split

  • Extract chart-registry.js module
  • Extract auth.js module
  • Extract crud-operations.js module
  • Extract metrics.js module
  • Extract modals.js module
  • Extract remaining modules
  • Update admin.js to import modules
  • Verify all Playwright tests pass

Phase 5: JSDoc Documentation

  • Add JSDoc to utility functions
  • Add JSDoc to all module exports
  • Configure ESLint JSDoc rules
  • Add @example blocks to complex functions

Phase 6: TypeScript Type Checking

  • Create tsconfig.json with checkJs
  • Add make typecheck-js target
  • Add CI step for type checking
  • Fix initial type errors

Phase 7: Additional Linting

  • Configure Biome as additional linter
  • Add make biome target
  • Add Lighthouse CI configuration
  • Add visual regression testing with Playwright screenshots

⚙️ Configuration Example

jest.config.js

module.exports = {
  testEnvironment: 'jsdom',
  testMatch: ['**/*.test.js', '**/*.spec.js'],
  collectCoverageFrom: ['mcpgateway/static/**/*.js'],
  coverageDirectory: 'coverage/js',
  coverageThreshold: {
    global: { branches: 50, functions: 50, lines: 50 }
  }
};

tsconfig.json

{
  "compilerOptions": {
    "allowJs": true,
    "checkJs": true,
    "noEmit": true,
    "target": "ES2020",
    "moduleResolution": "node"
  },
  "include": ["mcpgateway/static/**/*.js"]
}

✅ Success Criteria

  • Jest/Vitest configured and running
  • make test-js runs JavaScript unit tests
  • JS test coverage > 50% for utility functions
  • Playwright tests pass with new auth flow
  • CRUD tests exist for all entity types
  • admin.js split into < 1000 line modules
  • All exported functions have JSDoc
  • tsc --checkJs reports no errors
  • CI runs JS tests, type checking, and linting

🏁 Definition of Done

  • Unit testing framework configured
  • Initial unit tests written and passing
  • Playwright auth updated and working
  • CRUD Playwright tests for all entities
  • admin.js modularized
  • JSDoc added to all modules
  • TypeScript type checking enabled
  • CI updated with all JS quality checks
  • Code passes make verify
  • PR reviewed and approved

🔗 Related Issues

Metadata

Metadata

Assignees

Labels

SHOULDP2: Important but not vital; high-value items that are not crucial for the immediate releaseenhancementNew feature or requestepicLarge feature spanning multiple issuesfrontendFrontend development (HTML, CSS, JavaScript)testingTesting (unit, e2e, manual, automated, etc)uiUser Interface

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions