Skip to content

refactor: Consolidate web-ui test files to __tests__/ directory - #187

Merged
frankbria merged 1 commit into
mainfrom
claude/consolidate-test-files-DqgS7
Jan 5, 2026
Merged

refactor: Consolidate web-ui test files to __tests__/ directory#187
frankbria merged 1 commit into
mainfrom
claude/consolidate-test-files-DqgS7

Conversation

@frankbria

@frankbria frankbria commented Jan 5, 2026

Copy link
Copy Markdown
Owner

Migrate all test files from src/ to tests/ for single source of truth:

  • Merge AgentCard tests (28 comprehensive + 3 navigation tests)
  • Move component tests: DiscoveryProgress, PhaseIndicator, ProgressBar,
    ProjectCreationForm, Spinner, PRDModal, TaskTreeView
  • Move lib tests: api.test.ts
  • Remove duplicate HomePage/ProjectList tests (kept in tests/)
  • Update imports to use @/ alias pattern
  • Delete all test files from src/

Result: 50 test suites, 1300 tests (was 1546 with duplicates)

Summary by CodeRabbit

  • Tests

    • Rewrote component test suite with comprehensive coverage for rendering, state management, visual indicators, and edge cases.
    • Standardized test module import paths throughout the codebase for improved maintainability.
  • Chores

    • Reorganized test file structure and updated associated documentation.

✏️ Tip: You can customize this high-level summary in your review settings.

Migrate all test files from src/ to __tests__/ for single source of truth:

- Merge AgentCard tests (28 comprehensive + 3 navigation tests)
- Move component tests: DiscoveryProgress, PhaseIndicator, ProgressBar,
  ProjectCreationForm, Spinner, PRDModal, TaskTreeView
- Move lib tests: api.test.ts
- Remove duplicate HomePage/ProjectList tests (kept in __tests__/)
- Update imports to use @/ alias pattern
- Delete all test files from src/

Result: 50 test suites, 1300 tests (was 1546 with duplicates)
@coderabbitai

coderabbitai Bot commented Jan 5, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

This PR reorganizes and consolidates test files across the web-ui project. It expands the AgentCard test suite with comprehensive coverage for display, status, task management, and edge cases; migrates multiple test files to use path aliases (@/) for imports; and removes outdated test files from their original locations.

Changes

Cohort / File(s) Summary
AgentCard Test Consolidation
web-ui/__tests__/components/AgentCard.test.tsx
Rewrote test suite from minimal navigation-focused tests to comprehensive coverage. Added shared mock utilities and grouped assertions into nine categories: Display Agent Information, Status Colors, Current Task Display, Blocked Status Display, Agent Type Badges, Click Interaction, Status Indicator, Responsive Design, and Edge Cases. Includes validation of status visuals, task display logic, blocking behavior, badge icons, and handling of undefined/empty states.
Test File Migration – Import Alias Updates
web-ui/__tests__/components/DiscoveryProgress.test.tsx, web-ui/__tests__/components/PRDModal.test.tsx, web-ui/__tests__/components/PhaseIndicator.test.tsx, web-ui/__tests__/components/ProgressBar.test.tsx, web-ui/__tests__/components/ProjectCreationForm.test.tsx, web-ui/__tests__/components/Spinner.test.tsx, web-ui/__tests__/components/TaskTreeView.test.tsx, web-ui/__tests__/lib/api.test.ts
Updated import paths from relative paths to alias-based imports using @/ prefix. Updated file headers from TDD/Sprint notes to migration notes indicating source paths. No changes to test logic or control flow.
Deleted Test Files
web-ui/src/app/__tests__/page.test.tsx, web-ui/src/components/AgentCard.test.tsx, web-ui/src/components/__tests__/ProjectList.test.tsx
Removed three test files from original locations. HomePage test covered page structure and responsive layout. AgentCard test covered display, status colors, task display, badges, and interactions. ProjectList test covered loading states, card rendering, navigation, creation flow, error handling, and date formatting.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

Possibly related PRs

Poem

🐰 Hops of joy through test refrain,
AgentCard tests bloom again,
Aliases align the way,
Old tests rest, new ones play!

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately summarizes the main objective: consolidating test files from scattered src/ locations into a centralized tests/ directory, which is the primary change reflected in all file modifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch claude/consolidate-test-files-DqgS7

Comment @coderabbitai help to get the list of available commands and usage tips.

@claude

claude Bot commented Jan 5, 2026

Copy link
Copy Markdown

Code Review: Test Consolidation to __tests__/ Directory

Summary

This PR successfully consolidates test files from src/ to __tests__/ establishing a single source of truth for tests. The migration is clean and well-executed with proper import updates and documentation.

✅ Strengths

  1. Clear Documentation: Each migrated file includes clear comments indicating source files (e.g., "Consolidated from:" or "Migrated from:")

  2. Consistent Import Pattern: All files correctly use the @/ alias pattern for imports:

    • @/components/AgentCard
    • @/lib/api
    • @/types/api
  3. Proper Deduplication:

    • Removed duplicate HomePage/ProjectList tests
    • Merged AgentCard tests (28 comprehensive + 3 navigation tests)
    • Reduced from 1546 to 1300 tests by eliminating duplicates
  4. Complete Migration: No test files remain in src/ directory (verified)

  5. Test Quality: Merged AgentCard tests maintain comprehensive coverage across:

    • Display logic
    • Status colors
    • Click interactions
    • Edge cases
    • Responsive design

🔍 Code Quality Observations

AgentCard.test.tsx (line 297-326):
The consolidated file includes two similar tests within the "Click Interaction" describe block:

  • it('shows cursor-pointer when onAgentClick provided') (line 297)
  • it('renders without onClick callback') (line 313)

Both tests use identical agent data (agent-001, backend, busy, 5 tasks). While they test different scenarios, the naming could be clearer:

  • Consider renaming to emphasize the distinction: "applies cursor-pointer class when clickable" vs "applies cursor-pointer even without onAgentClick prop"
  • The comment on line 324 ("Should still have cursor-pointer since AgentCard is always clickable") clarifies the behavior but could be reflected in the test name

This is a minor clarity issue, not a functional problem.

✅ Best Practices Adherence

  1. CLAUDE.md Compliance: Follows project structure guidelines for test organization
  2. Import Consistency: Uses Next.js @/ alias pattern throughout
  3. Test Organization: Maintains clear describe blocks and logical grouping
  4. Documentation: Includes feature/phase references in file headers

🎯 Performance & Impact

  • Test Count: 1546 → 1300 tests (246 duplicate tests removed)
  • File Count: 50 test suites (consolidated structure)
  • No Breaking Changes: All imports updated correctly

Security & Test Coverage

  • No security concerns
  • Test coverage remains comprehensive after deduplication
  • All migrated tests maintain their original assertions

Recommendation

APPROVE

This is a clean refactoring that improves project organization without introducing regressions. The minor naming clarity issue in AgentCard tests is not blocking and can be addressed in future refactoring if needed.

The PR achieves its stated goal: establishing __tests__/ as the single source of truth for frontend tests.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
web-ui/__tests__/components/AgentCard.test.tsx (2)

63-77: Consider updating comments to match theme-based styling.

The test comments reference literal colors ("green for idle", "yellow for busy", "red for blocked"), but the assertions verify theme tokens (bg-secondary, bg-primary/20, bg-destructive/10). While semantically equivalent in the default theme, this could be misleading if the theme changes.

Consider updating comments to reflect the actual theme tokens being tested, e.g., "should apply secondary styling for idle status".


329-348: Test may produce false positives due to DOM accumulation.

The forEach loop calls render() multiple times without cleanup between iterations. RTL's render appends to the DOM, so by the third iteration, there are three components rendered. The querySelector('.animate-pulse') finds the first match, potentially masking failures in later statuses.

Consider using test.each for proper test isolation:

🔎 Proposed fix using test.each
-  describe('Status Indicator', () => {
-    it('should show animated pulse dot for all statuses', () => {
-      const statuses: Array<'idle' | 'busy' | 'blocked'> = ['idle', 'busy', 'blocked'];
-
-      statuses.forEach((status) => {
-        const agent: Agent = {
-          id: `agent-${status}`,
-          type: 'backend',
-          status,
-          tasksCompleted: 0,
-        };
-
-        const { container } = render(<AgentCard agent={agent} />);
-
-        const dot = container.querySelector('.animate-pulse');
-        expect(dot).toBeInTheDocument();
-        expect(dot).toHaveClass('w-3', 'h-3', 'rounded-full');
-      });
-    });
-  });
+  describe('Status Indicator', () => {
+    it.each<'idle' | 'busy' | 'blocked'>(['idle', 'busy', 'blocked'])(
+      'should show animated pulse dot for %s status',
+      (status) => {
+        const agent: Agent = {
+          id: `agent-${status}`,
+          type: 'backend',
+          status,
+          tasksCompleted: 0,
+        };
+
+        const { container } = render(<AgentCard agent={agent} />);
+
+        const dot = container.querySelector('.animate-pulse');
+        expect(dot).toBeInTheDocument();
+        expect(dot).toHaveClass('w-3', 'h-3', 'rounded-full');
+      }
+    );
+  });
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 15071e9 and 7427a73.

📒 Files selected for processing (12)
  • web-ui/__tests__/components/AgentCard.test.tsx
  • web-ui/__tests__/components/DiscoveryProgress.test.tsx
  • web-ui/__tests__/components/PRDModal.test.tsx
  • web-ui/__tests__/components/PhaseIndicator.test.tsx
  • web-ui/__tests__/components/ProgressBar.test.tsx
  • web-ui/__tests__/components/ProjectCreationForm.test.tsx
  • web-ui/__tests__/components/Spinner.test.tsx
  • web-ui/__tests__/components/TaskTreeView.test.tsx
  • web-ui/__tests__/lib/api.test.ts
  • web-ui/src/app/__tests__/page.test.tsx
  • web-ui/src/components/AgentCard.test.tsx
  • web-ui/src/components/__tests__/ProjectList.test.tsx
💤 Files with no reviewable changes (3)
  • web-ui/src/components/tests/ProjectList.test.tsx
  • web-ui/src/app/tests/page.test.tsx
  • web-ui/src/components/AgentCard.test.tsx
🧰 Additional context used
🧠 Learnings (17)
📓 Common learnings
Learnt from: CR
Repo: frankbria/codeframe PR: 0
File: docs/CLAUDE.md:0-0
Timestamp: 2025-11-25T19:08:37.203Z
Learning: Applies to docs/web-ui/**/__tests__/**/*.test.{ts,tsx} : Create JavaScript test files colocated or in __tests__/ as *.test.ts
📚 Learning: 2025-11-25T19:08:37.203Z
Learnt from: CR
Repo: frankbria/codeframe PR: 0
File: docs/CLAUDE.md:0-0
Timestamp: 2025-11-25T19:08:37.203Z
Learning: Applies to docs/web-ui/**/__tests__/**/*.test.{ts,tsx} : Create JavaScript test files colocated or in __tests__/ as *.test.ts

Applied to files:

  • web-ui/__tests__/components/ProgressBar.test.tsx
  • web-ui/__tests__/components/ProjectCreationForm.test.tsx
  • web-ui/__tests__/components/TaskTreeView.test.tsx
  • web-ui/__tests__/components/Spinner.test.tsx
  • web-ui/__tests__/components/DiscoveryProgress.test.tsx
  • web-ui/__tests__/lib/api.test.ts
  • web-ui/__tests__/components/PhaseIndicator.test.tsx
  • web-ui/__tests__/components/PRDModal.test.tsx
  • web-ui/__tests__/components/AgentCard.test.tsx
📚 Learning: 2026-01-04T06:26:12.870Z
Learnt from: CR
Repo: frankbria/codeframe PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-04T06:26:12.870Z
Learning: Applies to web-ui/src/**/*.{ts,tsx} : Use TypeScript 5.3+ for frontend development with React 18, Next.js 14, Tailwind CSS, and Hugeicons for icons

Applied to files:

  • web-ui/__tests__/components/ProjectCreationForm.test.tsx
  • web-ui/__tests__/components/Spinner.test.tsx
  • web-ui/__tests__/components/DiscoveryProgress.test.tsx
  • web-ui/__tests__/lib/api.test.ts
  • web-ui/__tests__/components/PhaseIndicator.test.tsx
📚 Learning: 2026-01-04T06:26:12.870Z
Learnt from: CR
Repo: frankbria/codeframe PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-04T06:26:12.870Z
Learning: Applies to web-ui/src/**/*.{ts,tsx} : Use TypeScript strict mode and ensure 100% type safety with no hardcoded types or any usage in frontend code

Applied to files:

  • web-ui/__tests__/components/ProjectCreationForm.test.tsx
  • web-ui/__tests__/components/PhaseIndicator.test.tsx
📚 Learning: 2025-11-25T19:08:37.203Z
Learnt from: CR
Repo: frankbria/codeframe PR: 0
File: docs/CLAUDE.md:0-0
Timestamp: 2025-11-25T19:08:37.203Z
Learning: Applies to docs/web-ui/src/components/**/*.{ts,tsx} : Use PascalCase for React component names

Applied to files:

  • web-ui/__tests__/components/ProjectCreationForm.test.tsx
  • web-ui/__tests__/components/PhaseIndicator.test.tsx
📚 Learning: 2025-11-25T19:08:54.154Z
Learnt from: CR
Repo: frankbria/codeframe PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T19:08:54.154Z
Learning: Applies to specs/*/tasks.md : Feature task files (tasks.md) must include phase-by-phase task breakdown with unique task identifiers (T001, T002, etc.), acceptance criteria per task, beads issue references, and estimated effort

Applied to files:

  • web-ui/__tests__/components/TaskTreeView.test.tsx
📚 Learning: 2025-11-25T19:08:37.203Z
Learnt from: CR
Repo: frankbria/codeframe PR: 0
File: docs/CLAUDE.md:0-0
Timestamp: 2025-11-25T19:08:37.203Z
Learning: Applies to docs/web-ui/**/*.{ts,tsx} : Use Next.js 14 with React 18 App Router for the frontend

Applied to files:

  • web-ui/__tests__/components/Spinner.test.tsx
📚 Learning: 2025-11-25T19:08:37.203Z
Learnt from: CR
Repo: frankbria/codeframe PR: 0
File: docs/CLAUDE.md:0-0
Timestamp: 2025-11-25T19:08:37.203Z
Learning: Applies to docs/web-ui/src/**/*.{ts,tsx} : Use Tailwind utility classes for styling instead of CSS modules

Applied to files:

  • web-ui/__tests__/components/Spinner.test.tsx
  • web-ui/__tests__/components/DiscoveryProgress.test.tsx
📚 Learning: 2026-01-04T06:26:12.870Z
Learnt from: CR
Repo: frankbria/codeframe PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-04T06:26:12.870Z
Learning: Applies to web-ui/src/**/*.tsx : Replace all icon usage with Hugeicons (hugeicons/react) and do not mix with lucide-react

Applied to files:

  • web-ui/__tests__/components/Spinner.test.tsx
  • web-ui/__tests__/components/DiscoveryProgress.test.tsx
📚 Learning: 2025-11-25T19:08:37.203Z
Learnt from: CR
Repo: frankbria/codeframe PR: 0
File: docs/CLAUDE.md:0-0
Timestamp: 2025-11-25T19:08:37.203Z
Learning: Applies to docs/web-ui/src/components/**/*.{ts,tsx} : Use functional React components with TypeScript interfaces

Applied to files:

  • web-ui/__tests__/components/Spinner.test.tsx
  • web-ui/__tests__/components/DiscoveryProgress.test.tsx
📚 Learning: 2026-01-04T06:26:12.870Z
Learnt from: CR
Repo: frankbria/codeframe PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-04T06:26:12.870Z
Learning: Applies to web-ui/src/app/page.tsx : Implement automatic project discovery start after project creation with loading state transitions and 'Start Discovery' button for idle projects

Applied to files:

  • web-ui/__tests__/components/DiscoveryProgress.test.tsx
📚 Learning: 2026-01-04T06:26:12.870Z
Learnt from: CR
Repo: frankbria/codeframe PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-04T06:26:12.870Z
Learning: Applies to web-ui/src/lib/**/*.ts : Frontend API files must use const API_BASE_URL = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:8080' pattern without hardcoded production URLs or different fallback ports

Applied to files:

  • web-ui/__tests__/lib/api.test.ts
📚 Learning: 2026-01-04T06:26:12.870Z
Learnt from: CR
Repo: frankbria/codeframe PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-04T06:26:12.870Z
Learning: Applies to tests/e2e/**/*.ts : Implement E2E tests using Playwright + TestSprite with loginUser() helper from tests/e2e/test-utils.ts for authentication

Applied to files:

  • web-ui/__tests__/lib/api.test.ts
📚 Learning: 2026-01-04T06:26:12.870Z
Learnt from: CR
Repo: frankbria/codeframe PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-04T06:26:12.870Z
Learning: Applies to web-ui/src/reducers/agentReducer.ts : Use Context + Reducer pattern for multi-agent support handling up to 10 concurrent agents with independent state tracking and timestamp conflict resolution using last-write-wins

Applied to files:

  • web-ui/__tests__/components/AgentCard.test.tsx
📚 Learning: 2026-01-04T06:26:12.870Z
Learnt from: CR
Repo: frankbria/codeframe PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-04T06:26:12.870Z
Learning: Applies to web-ui/src/contexts/AgentStateContext.ts : Use context-based state management with React Context + useReducer pattern for Dashboard with AgentStateContext, agentReducer, and useAgentState hook

Applied to files:

  • web-ui/__tests__/components/AgentCard.test.tsx
📚 Learning: 2026-01-04T06:26:12.870Z
Learnt from: CR
Repo: frankbria/codeframe PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-04T06:26:12.870Z
Learning: Applies to web-ui/src/components/Dashboard.tsx : Use React.memo on all Dashboard sub-components and useMemo for derived state to optimize performance with multi-agent support

Applied to files:

  • web-ui/__tests__/components/AgentCard.test.tsx
📚 Learning: 2026-01-04T06:26:12.870Z
Learnt from: CR
Repo: frankbria/codeframe PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-04T06:26:12.870Z
Learning: Applies to web-ui/src/components/AgentStateProvider.tsx : Wrap AgentStateProvider with ErrorBoundary component for graceful error handling in Dashboard

Applied to files:

  • web-ui/__tests__/components/AgentCard.test.tsx
🧬 Code graph analysis (1)
web-ui/__tests__/components/AgentCard.test.tsx (2)
web-ui/src/components/ErrorBoundary.tsx (1)
  • render (63-118)
web-ui/src/components/AgentCard.tsx (1)
  • AgentCard (212-226)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Backend Unit Tests
  • GitHub Check: Frontend Unit Tests
  • GitHub Check: claude-review
  • GitHub Check: E2E Smoke Tests (Chromium)
🔇 Additional comments (15)
web-ui/__tests__/components/PhaseIndicator.test.tsx (1)

3-3: LGTM! Clean migration to consolidated test directory.

The migration comment clearly documents the source location, and the import path has been correctly updated to use the @/ alias pattern.

Also applies to: 7-7

web-ui/__tests__/lib/api.test.ts (1)

4-4: LGTM! Import path correctly updated for lib module.

The migration header and alias import path are both correctly applied, maintaining consistency with the broader test consolidation effort.

Also applies to: 44-44

web-ui/__tests__/components/ProgressBar.test.tsx (1)

3-3: LGTM! Migration executed correctly.

The header comment and import alias are both properly updated, consistent with the test consolidation pattern across the PR.

Also applies to: 7-7

web-ui/__tests__/components/Spinner.test.tsx (1)

4-4: LGTM! Named import properly migrated.

Both the migration header and the alias import (with named export) are correctly applied.

Also applies to: 9-9

web-ui/__tests__/components/PRDModal.test.tsx (1)

3-3: LGTM! Final test file migration looks good.

The migration documentation and import path update are both correct, completing the consistent pattern across all test files in this PR.

Also applies to: 8-8

web-ui/__tests__/components/ProjectCreationForm.test.tsx (1)

4-4: LGTM! Clean migration with improved mocking.

The import path has been correctly updated to use the @/ alias, and the enhanced axios mock with interceptor support makes the tests more realistic and robust.

Also applies to: 10-10, 16-42

web-ui/__tests__/components/TaskTreeView.test.tsx (1)

3-3: LGTM! Clean import path migration.

All imports and mock paths have been correctly updated to use the @/ alias pattern, maintaining consistency with the project's module resolution strategy.

Also applies to: 8-12

web-ui/__tests__/components/DiscoveryProgress.test.tsx (1)

3-3: LGTM! Clean migration with consistent import paths.

All imports and mock paths have been successfully updated to use the @/ alias pattern. The comprehensive test suite logic remains intact, ensuring continued coverage for this critical component.

Also applies to: 7-7, 36-51

web-ui/__tests__/components/AgentCard.test.tsx (7)

1-18: LGTM - Well-structured test setup.

Good consolidation with clear provenance comments. The beforeEach mock reset ensures test isolation. Import using @/ alias aligns with the PR objectives.


20-61: LGTM - Good display coverage.

Tests verify the core rendering of agent ID, formatted type name, and task counter with clear assertions.


112-155: LGTM - Proper conditional rendering tests.

Good use of queryByText for asserting element absence. Tests correctly verify task display logic across all three status states.


157-200: LGTM - Comprehensive blocked status tests.

Tests cover single task blocking, multiple tasks with count display, and absence of blocked section when not applicable.


202-262: LGTM - Complete badge type coverage.

Tests all documented agent types plus the fallback for unknown types, verifying both styling classes and icon emojis.


264-327: LGTM - Thorough click interaction tests.

Good coverage of callback invocation, optional callback handling, and cursor styling. The two tests without onAgentClick (lines 282-295 and 313-326) test complementary aspects: exception safety vs. DOM presence with cursor class.


350-439: LGTM - Solid responsive and edge case coverage.

Tests appropriately verify responsive styling classes, truncation behavior with title attribute for accessibility, and boundary conditions including zero/large values and undefined/empty states.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants