Skip to content

Add comprehensive unit tests (Jest + RTL) and Cypress E2E tests — 95%+ coverage#41

Open
devin-ai-integration[bot] wants to merge 2 commits into
mainfrom
devin/1747934400-add-testing
Open

Add comprehensive unit tests (Jest + RTL) and Cypress E2E tests — 95%+ coverage#41
devin-ai-integration[bot] wants to merge 2 commits into
mainfrom
devin/1747934400-add-testing

Conversation

@devin-ai-integration
Copy link
Copy Markdown

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

Summary

Adds a complete testing infrastructure to the ecommerce app, going from 0% to 95%+ test coverage.

What's included:

Phase 1 — Testing dependencies:

  • Jest ^29, @testing-library/react ^12, @testing-library/jest-dom ^5, @testing-library/user-event ^14
  • jest-environment-jsdom, identity-obj-proxy (CSS mock), @types/jest
  • Cypress ^13 for E2E, next-router-mock
  • New scripts: test, test:watch, test:e2e, cypress:open

Phase 2 — Jest configuration:

  • jest.config.js using next/jest with CSS module mocking and coverage collection
  • jest.setup.js with jest-dom matchers

Phase 3 — 17 unit test suites, 93 tests:

  • context/__tests__/StateContext.test.js — all cart logic (onAdd, onRemove, toggleCartItemQuanitity, incQty, decQty, showCart, reset)
  • components/__tests__/ — Footer, Product, HeroBanner, FooterBanner, Layout, Navbar, Cart
  • pages/__tests__/ — index (+ getServerSideProps), success, _app
  • pages/product/__tests__/slug.test.jsx — ProductDetails + getStaticPaths/getStaticProps
  • pages/api/__tests__/ — stripe handler (POST, 405, error paths), hello handler
  • lib/__tests__/ — client, getStripe (singleton caching), utils (runFireworks confetti)

Phase 4 — Cypress E2E tests:

  • home.cy.js — hero banner, product cards, footer banner, navigation
  • product-detail.cy.js — product page navigation, qty increment/decrement, add to cart
  • cart.cy.js — add/remove items, qty controls, empty cart message
  • checkout.cy.js — Pay with Stripe flow (API intercept)

Coverage results:

Metric Coverage
Statements 95.51%
Branches 90%
Functions 95%
Lines 95.73%

Review & Testing Checklist for Human

  • Run npm test to verify all 93 unit tests pass
  • Run npm test -- --coverage to verify 95%+ coverage report
  • Review the StateContext tests — these test the core cart business logic
  • For E2E tests: start dev server (npm run dev), then run npx cypress run — note these require Sanity backend data or will rely on intercepts

Notes

  • Used @testing-library/react@^12 (not ^14) due to React 17 peer dependency compatibility
  • Used --legacy-peer-deps for npm install due to some peer dep conflicts
  • Cypress E2E tests use cy.intercept() for the home page Sanity API calls; other E2E tests work against the live app
  • The components/index.js barrel file shows low coverage (14%) because it's just re-exports — the actual components all have 100% coverage

Link to Devin session: https://app.devin.ai/sessions/0c4802d1afb7449dab465fa7b827bcd6
Requested by: @davidbean-hash


Devin Review

Status Commit
⚪ Not started

Run Devin Review

💡 Connect your GitHub account to enable automatic code reviews.

Open in Devin Review (Staging)
Open in Devin Review

@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

devin-ai-integration[bot]

This comment was marked as resolved.

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