Skip to content

Tests for AI features — settings UI, copy generator, autofill, analyzer #30

@anurag629

Description

@anurag629

Testing for Phases 2-4

Comprehensive tests for all AI feature UI components and integrations.

Scope

Unit Tests

`tests/ai/prompts.test.ts`

  • Title generation prompt includes category and tone
  • Subtitle prompt includes the title for context
  • Prompts respect character limits in instructions
  • Prompt builder handles missing/optional fields gracefully

`tests/ai/generate.test.ts`

  • `generateTitles()` returns array of strings
  • `generateSubtitles()` returns array of strings
  • JSON response parsing handles: clean JSON, markdown-wrapped JSON, plain text
  • Character limit filtering removes oversized results
  • Retry logic triggers on parse failure
  • Empty/malformed AI responses return graceful fallback

`tests/api/ai-autofill.test.ts`

  • Returns 400 for missing URL
  • Returns 400 for invalid URL format
  • Returns correct response shape `{ templateId, fields, colors }`
  • Handles unreachable URLs gracefully

Component Tests (if React Testing Library is set up)

`tests/components/AISettingsModal.test.tsx`

  • Renders all 5 providers
  • Provider switch loads saved key for that provider
  • Validate button triggers API call
  • Shows valid/invalid status after validation
  • Clear button removes key (with confirmation)
  • Modal closes on ESC and backdrop click

`tests/components/AISuggestionPicker.test.tsx`

  • Renders suggestions list
  • Click selects a suggestion and calls onSelect
  • Regenerate button triggers new generation
  • Cancel closes picker
  • Keyboard navigation works (arrows, Enter, Escape)

Integration Tests

`tests/ai/integration.test.ts`

  • Full flow: set API key → validate → generate title → receive suggestions
  • Provider switching preserves keys
  • Generate with invalid key → returns auth error, doesn't crash
  • All mocked — no real API calls

Mock Strategy

  • Mock `fetch` globally for all AI API calls
  • Mock `localStorage` for storage tests
  • Provider responses should cover: success, auth error, rate limit, malformed response
  • Create shared fixtures: `tests/ai/fixtures/` with sample responses per provider

Acceptance Criteria

  • All test files created and passing
  • Prompt builder tested with various category/context combinations
  • Response parsing edge cases covered (at least 5 parse scenarios)
  • UI components tested for key interactions
  • Integration flow tested end-to-end (mocked)
  • No real API calls in any test
  • Tests run in CI without environment variables

Metadata

Metadata

Assignees

No one assigned

    Labels

    aiAI-powered featuresphase-4Advanced AI featurestestingTests and quality assurance

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions