refactor: consolidate createMockTab test factories (Phase 03D)#814
Conversation
Consolidate 19 local createMockTab/createMockAITab/createMockFileTab factory definitions across test files into shared helpers at src/__tests__/helpers/mockTab.ts. - New shared createMockAITab(overrides) and createMockFileTab(overrides) helpers accept Partial<AITab>/Partial<FilePreviewTab> with sensible defaults for all required fields - Files with unique defaults (saveToHistory, non-null agentSessionId, pre-seeded logs) retain thin local wrappers that delegate to the shared factory with the file-specific overrides layered in - Positional-signature wrappers in useMergeSession, useSendToAgent, and MergeSessionModal tests are preserved as thin wrappers to keep call sites unchanged - broadcastService.test.ts is excluded because it uses the AITabData type (a different shape) rather than AITab - tabHelpers.test.ts migrates to the shared factory directly (no local wrapper needed) Test-only change. Zero production impact.
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 7 minutes and 29 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (21)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…t test Imports should precede type alias declarations per ES module conventions.
Greptile SummaryThis PR is a test-only refactoring (Phase 03D) that introduces shared The factories are well-designed: all required interface fields are covered, optional fields are correctly omitted, and files needing unique IDs or extra defaults use local wrapper functions rather than mutating the shared defaults. Confidence Score: 5/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["src/__tests__/helpers/mockTab.ts"] -->|"exports createMockAITab"| B["14 hook tests"]
A -->|"exports createMockFileTab"| C["4 util/store tests"]
A -->|"exports both"| D["2 component tests"]
E["src/__tests__/helpers/index.ts"] -->|"barrel re-export"| A
B --> B1["useAgentExecution\n(local wrapper: +createdAt, +saveToHistory)"]
B --> B2["useAgentSessionManagement\n(local wrapper: +createdAt, +saveToHistory)"]
B --> B3["useAgentListeners\n(local wrapper: +createdAt, +saveToHistory)"]
B --> B4["useTabHandlers\n(local wrapper: +random id, +hasUnread, +isAtBottom)"]
B --> B5["useMergeSession / useSendToAgent\n(direct import)"]
C --> C1["tabStore\n(local wrapper: +random id)"]
C --> C2["tabHelpers\n(aliased direct import)"]
C --> C3["tabExport / contextExtractor\n(direct import)"]
D --> D1["MergeSessionModal"]
D --> D2["ThinkingStatusPill"]
|
| export function createMockAITab(overrides: Partial<AITab> = {}): AITab { | ||
| return { | ||
| id: 'tab-1', | ||
| agentSessionId: null, | ||
| name: null, | ||
| starred: false, | ||
| logs: [], | ||
| inputValue: '', | ||
| stagedImages: [], | ||
| createdAt: Date.now(), | ||
| state: 'idle', | ||
| ...overrides, | ||
| } as AITab; | ||
| } |
There was a problem hiding this comment.
Repeated local
createMockTab wrappers could be extracted
Four hook test files (useAgentExecution, useAgentSessionManagement, useAgentListeners, useRemoteIntegration) each define a nearly-identical local createMockTab that adds createdAt: 1700000000000 and saveToHistory: true on top of createMockAITab. If a future phase wants to consolidate these, a second shared factory (e.g., createMockSessionAITab) or an optional parameter on this one could eliminate the remaining boilerplate. Not a blocker for this phase — flagging for awareness.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Summary
Test-only change. Zero production risk.
Introduces
createMockAITabandcreateMockFileTabfactories atsrc/__tests__/helpers/mockTab.ts. Replaces per-file tab factory definitions across 19 test files.Net: -85 lines across 21 files
Files migrated: 14 hook tests, 4 util/store tests, 2 component tests. One file skipped (broadcastService - uses different
AITabDatashape).Test plan
npm run lintpasses cleanRisk
Zero - no production code changes.