AGENTS.md
autogpt_platform/frontend/src/tests/AGENTS.mdAGENTS.md
Quality
81/100
Scores the file, not the repository.Length
1,092 words
13 headings · 8 code blocksRepository
186k
— · pushed 0 days agoLast changed
3 days ago
First indexed 3 days ago.1# Frontend Testing Rules 🧪23## Testing Types Overview45| Type | Tool | Speed | Purpose |6| --------------- | --------------------- | --------------- | -------------------------------- |7| **E2E** | Playwright | Slow (~5s/test) | Real browser, full user journeys |8| **Integration** | Vitest + RTL | Fast (~100ms) | Component + mocked API |9| **Unit** | Vitest + RTL | Fastest (~10ms) | Individual functions/components |10| **Visual** | Storybook + Chromatic | N/A | UI appearance, design system |1112---1314## When to Use Each1516### ✅ E2E Tests (Playwright)1718**Use for:** Critical user journeys that MUST work in a real browser.1920- Authentication flows (login, signup, logout)21- Payment or sensitive transactions22- Flows requiring real browser APIs (clipboard, downloads)23- Cross-page navigation that must work end-to-end2425**Location:** `src/playwright/*.spec.ts` (centralized, as there will be fewer of them)2627**Import:** Always import `test` and `expect` from `./coverage-fixture` instead of `@playwright/test`. This auto-collects V8 coverage per test for Codecov reporting.2829```ts30// correct31import { test, expect } from "./coverage-fixture";3233// wrong - bypasses coverage collection34import { test, expect } from "@playwright/test";35```3637### ✅ Integration Tests (Vitest + RTL)3839**Use for:** Testing components with their dependencies (API calls, state).4041- Page-level behavior with mocked API responses42- Components that fetch data43- User interactions that trigger API calls44- Feature flows within a single page4546**Location:** Place tests in a `__tests__` folder next to the component:4748```49ComponentName/50 __tests__/51 main.test.tsx52 some-flow.test.tsx53 ComponentName.tsx54 useComponentName.ts55```5657**Start at page level:** Initially write integration tests at the "page" level. No need to write them for every small component.5859```60/library/61 __tests__/62 main.test.tsx63 searching-agents.test.tsx64 agents-pagination.test.tsx65 page.tsx66 useLibraryPage.ts67```6869Start with a `main.test.tsx` file and split into smaller files as it grows.7071**What integration tests should do:**72731. Render a page or complex modal (e.g., `AgentPublishModal`)742. Mock API requests via MSW753. Assert UI scenarios via Testing Library7677**Prefer the UI surface over direct hook tests:** if a `use*.ts` hook only exists to support a page/component, test that page/component instead of adding a `renderHook()` test. Reserve direct hook tests for shared hooks with standalone business logic that cannot be exercised cleanly through the UI.7879**Prefer Orval-generated mocks:** use the generated MSW handlers and response builders from `src/app/api/__generated__/endpoints/*/*.msw.ts` instead of hand-built API response objects or mocking a page/component hook.8081```tsx82// Example: Test page renders data from API83import { server } from "@/mocks/mock-server";84import { getDeleteV2DeleteStoreSubmissionMockHandler422 } from "@/app/api/__generated__/endpoints/store/store.msw";8586test("shows error when submission fails", async () => {87 // Override default handler to return error status88 server.use(getDeleteV2DeleteStoreSubmissionMockHandler422());8990 render(<MarketplacePage />);91 await screen.findByText("Featured Agents");92 // ... assert error UI93});94```9596**Tip:** Use `findBy...` methods most of the time—they wait for elements to appear, so async code won't cause flaky tests. The regular `getBy...` methods don't wait and error immediately.9798### ✅ Unit Tests (Vitest + RTL)99100**Use for:** Testing isolated components and utility functions.101102- Pure utility functions (`lib/utils.ts`)103- Component rendering with various props104- Component state changes105- Shared hooks with standalone business logic106107**Location:** Co-located with the file: `Component.test.tsx` next to `Component.tsx`108109```tsx110// Example: Test component renders correctly111render(<AgentCard title="My Agent" />);112expect(screen.getByText("My Agent")).toBeInTheDocument();113```114115### ✅ Storybook Tests (Visual)116117**Use for:** Design system, visual appearance, component documentation.118119- Atoms (Button, Input, Badge)120- Molecules (Dialog, Card)121- Visual states (hover, disabled, loading)122- Responsive layouts123124**Location:** Co-located: `Component.stories.tsx` next to `Component.tsx`125126---127128## Decision Flowchart129130```131Does it need a REAL browser/backend?132├─ YES → E2E (Playwright)133└─ NO134 └─ Does it involve API calls or complex state?135 ├─ YES → Integration (Vitest + RTL)136 └─ NO137 └─ Is it about visual appearance?138 ├─ YES → Storybook139 └─ NO → Unit (Vitest + RTL)140```141142---143144## What NOT to Test145146❌ Third-party library internals (Radix UI, React Query)147❌ CSS styling details (use Storybook)148❌ Simple prop-passing components with no logic149❌ TypeScript types150151---152153## File Organization154155```156src/157├── components/158│ └── atoms/159│ └── Button/160│ ├── Button.tsx161│ ├── Button.test.tsx # Unit test162│ └── Button.stories.tsx # Visual test163├── app/164│ └── (platform)/165│ └── marketplace/166│ └── components/167│ └── MainMarketplacePage/168│ ├── __tests__/169│ │ ├── main.test.tsx # Integration test170│ │ └── search-agents.test.tsx # Integration test171│ ├── MainMarketplacePage.tsx172│ └── useMainMarketplacePage.ts173├── lib/174│ ├── utils.ts175│ └── utils.test.ts # Unit test176├── mocks/177│ ├── mock-handlers.ts # MSW handlers (auto-generated via Orval)178│ └── mock-server.ts # MSW server setup179├── playwright/180│ ├── *.spec.ts # E2E tests (Playwright) - centralized181│ ├── pages/ # Playwright page objects182│ └── utils/ # Playwright helpers/fixtures183└── tests/184 ├── integrations/185 │ ├── test-utils.tsx # Testing utilities186 │ └── vitest.setup.tsx # Integration test setup187 └── AGENTS.md # Testing guidance for agents188```189190---191192## Priority Matrix193194| Component Type | Test Priority | Recommended Test |195| ------------------- | ------------- | -------------------------------------- |196| Pages/Features | **Highest** | Integration |197| Custom Hooks | Medium | Parent integration or shared-hook unit |198| Utility Functions | High | Unit |199| Organisms (complex) | High | Integration |200| Molecules | Medium | Unit + Storybook |201| Atoms | Medium | Storybook only\* |202203\*Atoms are typically simple enough that Storybook visual tests suffice.204205---206207## MSW Mocking208209API mocking is handled via MSW (Mock Service Worker). Handlers are auto-generated by Orval from the OpenAPI schema.210211**Default behavior:** All client-side requests are intercepted and return 200 status with faker-generated data.212213**Override for specific tests:** Use generated error handlers to test non-OK status scenarios:214215```tsx216import { server } from "@/mocks/mock-server";217import { getDeleteV2DeleteStoreSubmissionMockHandler422 } from "@/app/api/__generated__/endpoints/store/store.msw";218219test("shows error when deletion fails", async () => {220 server.use(getDeleteV2DeleteStoreSubmissionMockHandler422());221222 render(<MyComponent />);223 // ... assert error UI224});225```226227**Generated handlers location:** `src/app/api/__generated__/endpoints/*/` - each endpoint has handlers for different status codes.228229For Playwright support code, keep browser-only helpers in `src/playwright/` rather than `src/tests/`.230231---232233## Golden Rules2342351. **Test behavior, not implementation** - Query by role/text, not class names2362. **One assertion per concept** - Tests should be focused2373. **Mock at boundaries** - Mock API calls, not internal functions2384. **Co-locate integration tests** - Keep `__tests__/` folder next to the component2395. **E2E is expensive** - Only for critical happy paths; prefer integration tests2406. **AI agents are good at writing integration tests** - Start with these when adding test coverage2417. **Prefer component/page tests over hook tests** - Don't add `renderHook()` coverage for component implementation details2428. **Use generated API mocks** - Prefer Orval MSW helpers over manual API object stubs243
Also in Significant-Gravitas/AutoGPT
Diff this repo’s formatsOne repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| Significant-Gravitas/AutoGPT.github/copilot-instructions.md · 186k | Copilot instructions | setupbuildtestlint-format+10 | 88/100 | 3 days ago | |
| Significant-Gravitas/AutoGPTAGENTS.md · 186k | AGENTS.md | teststylearchgit+1 | 87/100 | 3 days ago | |
| Significant-Gravitas/AutoGPTautogpt_platform/AGENTS.md · 186k | AGENTS.md | setuptestarchtesting-strategy+3 | 77/100 | 3 days ago | |
| Significant-Gravitas/AutoGPTautogpt_platform/backend/AGENTS.md · 186k | AGENTS.md | setuptestlint-formatstyle+9 | 81/100 | 3 days ago | |
| Significant-Gravitas/AutoGPTautogpt_platform/backend/backend/copilot/graphiti/AGENTS.md · 186k | AGENTS.md | styleperformance | 66/100 | 3 days ago | |
| Significant-Gravitas/AutoGPTautogpt_platform/frontend/AGENTS.md · 186k | AGENTS.md | setupbuildtestlint-format+7 | 96/100 | 3 days ago | |
| Significant-Gravitas/AutoGPTclassic/CLAUDE.md · 186k | CLAUDE.md | setuptestlint-formatstyle+7 | 89/100 | 3 days ago | |
| Significant-Gravitas/AutoGPTclassic/direct_benchmark/CLAUDE.md · 186k | CLAUDE.md | setuptestlint-formatarch+4 | 78/100 | 3 days ago | |
| Significant-Gravitas/AutoGPTclassic/forge/CLAUDE.md · 186k | CLAUDE.md | teststylearchtypes+3 | 73/100 | 3 days ago | |
| Significant-Gravitas/AutoGPTclassic/original_autogpt/CLAUDE.md · 186k | CLAUDE.md | testarchuiperformance+2 | 90/100 | 3 days ago | |
| Significant-Gravitas/AutoGPT.claude/skills/vercel-react-best-practices/AGENTS.md · 186k | AGENTS.md | buildlint-formatstyledependencies+4 | 61/100 | 3 days ago |
Diff against .github/copilot-instructions.md Diff against AGENTS.md Diff against autogpt_platform/AGENTS.md Diff against autogpt_platform/backend/AGENTS.md Diff against autogpt_platform/backend/backend/copilot/graphiti/AGENTS.md Diff against autogpt_platform/frontend/AGENTS.md Diff against classic/CLAUDE.md Diff against classic/direct_benchmark/CLAUDE.md Diff against classic/forge/CLAUDE.md Diff against classic/original_autogpt/CLAUDE.md Diff against .claude/skills/vercel-react-best-practices/AGENTS.md
Similar configs
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| trick77/agents-md-syncAGENTS.md · 2 | AGENTS.md | setupbuildteststyle+5 | 100/100 | 3 days ago | |
| SkeneTechnologies/skene-cookbookAGENTS.md · 51 | AGENTS.md | setupbuildtestlint-format+7 | 100/100 | 2 days ago | |
| duckduckgo/content-scope-scriptsspecial-pages/AGENTS.md · 70 | AGENTS.md | buildteststylearch+3 | 100/100 | 3 days ago | |
| OnlyTerp/prompt-cache-skillsAGENTS.md · 112 | AGENTS.md | setupbuildtestlint-format+5 | 100/100 | 3 days ago | |
| mui/material-uiAGENTS.md · 99k | AGENTS.md | setupbuildtestlint-format+9 | 100/100 | 3 days ago | |
| n8n-io/n8npackages/@n8n/agents/AGENTS.md · 199k | AGENTS.md | buildteststylearch+3 | 100/100 | 3 days ago | |
| vllm-project/vllmAGENTS.md · 88k | AGENTS.md | setuptestlint-formatstyle+5 | 100/100 | 3 days ago | |
| TryGhost/Ghoste2e/AGENTS.md · 55k | AGENTS.md | setupteststylearch+2 | 100/100 | 3 days ago |
