Skip to content

Phase 3: Core Components with TDD Approach (MBA-45) in COG-GTM/angular2-hn#276

Open
devin-ai-integration[bot] wants to merge 8 commits into
masterfrom
devin/1779811634-phase3-core-components-tdd
Open

Phase 3: Core Components with TDD Approach (MBA-45) in COG-GTM/angular2-hn#276
devin-ai-integration[bot] wants to merge 8 commits into
masterfrom
devin/1779811634-phase3-core-components-tdd

Conversation

@devin-ai-integration
Copy link
Copy Markdown

@devin-ai-integration devin-ai-integration Bot commented May 26, 2026

Summary

Implements Phase 3 of the Angular-to-React migration (Jira MBA-45): comprehensive TDD testing for all core UI components, plus new shared components (ErrorBoundary, Layout).

Built on top of the Phase 1/2 React infrastructure branch (devin/1779402204-react-migration-infra), which already migrated the Angular app to React 19 + Vite + TypeScript with core components (Header, Footer, Settings, Loader, ErrorMessage) and the SettingsContext.

What this PR adds:

New Components:

  • ErrorBoundary — Class component with getDerivedStateFromError and componentDidCatch, supports custom fallback rendering
  • Layout — Wraps Header + ErrorBoundary + main + Footer, applies theme class from SettingsContext

Refactored:

  • App.tsx — Now uses Layout component instead of manually composing Header/Footer
  • Removed unused eslint-disable directive in SettingsContext.tsx

Test Infrastructure:

  • Configured Vitest with jsdom, CSS modules support, and global test setup
  • Added @testing-library/user-event and vitest-axe dev dependencies
  • Setup file with @testing-library/jest-dom matchers, vitest-axe matchers, and window.matchMedia mock

Test Suites (48 tests across 9 files):

  • Header.test.tsx — Navigation links, logo, settings toggle, routing, accessibility
  • Footer.test.tsx — GitHub link attributes, content rendering, accessibility
  • Loader.test.tsx — Container/spinner rendering, accessibility
  • Settings.test.tsx — Theme radios, checkbox toggle, font/spacing inputs, localStorage persistence, accessibility
  • ErrorMessage.test.tsx — Message rendering, rerendering, accessibility
  • ErrorBoundary.test.tsx — Error catching, default/custom fallback, console logging
  • Layout.test.tsx — Composition, main element, theme class, error boundary integration, accessibility
  • SettingsContext.test.tsx — All state actions, localStorage persistence/loading, provider requirement

Review & Testing Checklist for Human

  • Run npm test — all 48 tests should pass
  • Run npm run typecheck — should pass with 0 errors
  • Run npm run lint — should pass (1 pre-existing warning in SettingsContext.tsx about fast refresh)
  • Run npm run dev and verify the app loads correctly at localhost:4200
  • Click the settings gear icon — verify the Settings modal opens/closes
  • Switch themes (Default, Night, Black AMOLED) and verify they persist across page reloads
  • Verify Header navigation links (new, show, ask, jobs) route correctly

Notes

  • The HTMLCanvasElement.prototype.getContext warnings in test stderr are a known jsdom limitation with axe-core's color contrast checks — they don't affect test results
  • The single remaining ESLint warning (react-refresh/only-export-components in SettingsContext.tsx) is pre-existing from the base branch and not introduced by this PR
  • All accessibility tests pass via vitest-axe (axe-core)

Link to Devin session: https://app.devin.ai/sessions/fe76dcad05f3489ebd65c81fa8967d06
Requested by: @bcmake


Devin Review

Status Commit
⚪ Not started

Run Devin Review

💡 Connect your GitHub account to enable automatic code reviews.

Open in Devin Review (Staging)

devin-ai-integration Bot and others added 8 commits May 21, 2026 22:26
- Replace Angular 9 with React 19, Vite 6, TypeScript 5.8
- Add React Router v7 for client-side routing
- Add TanStack Query v5 for data fetching (replaces RxJS)
- Create API service layer using official HN Firebase API
- Port TypeScript interfaces from Angular models
- Create SettingsContext (replaces SettingsService)
- Port SCSS theme system (default, night, AMOLED black)
- Implement all page components (Feed, ItemDetails, User)
- Add shared components (Header, Footer, Settings, Loader, ErrorMessage)
- Add ESLint 9 + Prettier for code quality
- Add GitHub Actions CI (replaces Travis CI)
- Update Firebase config for Vite output
- Remove all Angular-specific files and dependencies

Co-Authored-By: Matthew Guerra <matthew.guerra@cognition.ai>
Co-Authored-By: Matthew Guerra <matthew.guerra@cognition.ai>
Co-Authored-By: Matthew Guerra <matthew.guerra@cognition.ai>
- Set theme default to 'default' instead of '' to avoid flash of
  unstyled content on first visit (Devin Review)
- Return hasMore flag from fetchFeed based on total IDs count instead
  of relying on items.length === 30, which breaks when deleted items
  are filtered out (Devin Review)

Co-Authored-By: Matthew Guerra <matthew.guerra@cognition.ai>
The useEffect guard checked settings.theme which is always truthy
('default'), making the system color scheme detection dead code.
Check localStorage.getItem('theme') directly so first-time users
with no saved preference get the system dark/light mode applied.

Co-Authored-By: Matthew Guerra <matthew.guerra@cognition.ai>
…division by zero

- Add APPLY_SYSTEM_THEME reducer action that updates state without
  writing to localStorage, so system dark mode detection stays active
  across page reloads until the user explicitly picks a theme
- Guard poll bar width calculation against division by zero when
  poll_votes_count is 0

Co-Authored-By: Matthew Guerra <matthew.guerra@cognition.ai>
…ar 'second'

- Check localStorage inside media query change handler so an explicit
  user theme choice stops system theme from overriding it mid-session
- Fix '1 seconds ago' → '1 second ago' for consistency with other units

Co-Authored-By: Matthew Guerra <matthew.guerra@cognition.ai>
- Add ErrorBoundary component with custom fallback support
- Add Layout component wrapping Header, Footer, and ErrorBoundary
- Refactor App.tsx to use Layout component
- Add comprehensive test suites for Header, Footer, Loader, Settings,
  ErrorMessage, ErrorBoundary, Layout components
- Add SettingsContext unit tests covering all state management
- Add accessibility tests (vitest-axe) for all components
- Configure Vitest with jsdom, CSS modules, and test setup
- Add @testing-library/user-event, vitest-axe dev dependencies
- Mock window.matchMedia for jsdom test environment
- 48 tests across 9 test files, all passing

MBA-45
@devin-ai-integration
Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

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.

0 participants