Skip to content

test(frontend): comprehensive snapshot tests for all screens - #35

Merged
hoangsonww merged 1 commit into
masterfrom
feat/frontend-snapshot-tests
Jun 13, 2026
Merged

test(frontend): comprehensive snapshot tests for all screens#35
hoangsonww merged 1 commit into
masterfrom
feat/frontend-snapshot-tests

Conversation

@hoangsonww

Copy link
Copy Markdown
Owner

What

The frontend had behavioral tests but no snapshot coverage. This adds Jest + React Testing Library snapshot tests for all 18 screens:

Home, Shop, ProductDetails, Cart, Checkout, OrderSuccess, OrderTracking, Login, Register, ForgotPassword, ResetPassword, About, Privacy, ShippingReturns, Support, NotFoundPage — plus the NavigationBar and Footer.

Each test renders the screen inside a MemoryRouter with its dependencies mocked (apiClient, ProductCard, carousel, notifier) and asserts the rendered markup with toMatchSnapshot(). Tests live in src/tests/snapshots/.

Harness

jest.setup.js gains jsdom polyfills (matchMedia, scrollTo, scrollIntoView, Resize/IntersectionObserver) and a global autoFocus neutralization (jsdom applies focus inconsistently across environments). No config or dependency changes.

Determinism — passes identically on local + CI regardless of when/where

  • apiClient mocked as pending → data screens render their deterministic loading/initial state offline.
  • Home — banner images, ProductCard, and the carousel stubbed.
  • FooterDate frozen (renders the current year).

Verification

Test Suites: 25 passed, 25 total   (18 snapshot + 7 existing behavioral)
Tests:       45 passed, 45 total
Snapshots:   18 passed, 18 total

Snapshot suites verified against the committed baselines under UTC, Pacific/Kiritimati (UTC+14), and Pacific/Pago_Pago (UTC-11) — all pass. The 7 existing behavioral suites still pass. Files are Prettier-clean per .prettierrc. No new dependencies.

Docs: the README "Frontend Tests" section now documents the snapshot suites and how to run/update them.

🤖 Generated with Claude Code

The frontend had behavioral tests but no snapshot coverage. Add Jest +
React Testing Library snapshot tests for every screen (18): Home, Shop,
ProductDetails, Cart, Checkout, OrderSuccess, OrderTracking, Login,
Register, ForgotPassword, ResetPassword, About, Privacy, ShippingReturns,
Support, NotFoundPage, plus the NavigationBar and Footer.

Each test renders the screen inside a MemoryRouter with its dependencies
mocked (apiClient, ProductCard, carousel, notifier) and asserts the
rendered markup with toMatchSnapshot(), so unintended UI changes surface
as a diff. Tests live in src/tests/snapshots/.

Harness (jest.setup.js): add jsdom polyfills (matchMedia, scrollTo,
scrollIntoView, Resize/IntersectionObserver) and neutralize autoFocus so
focus-sensitive markup is stable across environments.

Determinism (passes identically on local + CI regardless of when/where):
- apiClient mocked as pending so data screens render their deterministic
  loading/initial state offline.
- Home: banner images, ProductCard, and the carousel are stubbed.
- Footer: Date frozen (renders the current year).

Verified: frontend suite 25 suites / 45 tests / 18 snapshots green in CI
mode (the existing 7 behavioral suites still pass), and the snapshot suites
pass against the committed baselines under UTC, Pacific/Kiritimati (UTC+14),
and Pacific/Pago_Pago (UTC-11). No new dependencies.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 13, 2026 07:34
@netlify

netlify Bot commented Jun 13, 2026

Copy link
Copy Markdown

Deploy Preview for mern-stack-ecommerce-website ready!

Name Link
🔨 Latest commit 92644d2
🔍 Latest deploy log https://app.netlify.com/projects/mern-stack-ecommerce-website/deploys/6a2d0808ba33ae00083e5959
😎 Deploy Preview https://deploy-preview-35--mern-stack-ecommerce-website.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 64
Accessibility: 88
Best Practices: 100
SEO: 100
PWA: 80
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify project configuration.

@vercel

vercel Bot commented Jun 13, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
mern-stack-ecommerce-app Ignored Ignored Jun 13, 2026 7:34am

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces comprehensive snapshot tests for all screens and key components under src/tests/snapshots/, along with their baseline snapshot files, and updates the README.md with instructions on running and updating these tests. Additionally, jest.setup.js is updated with several jsdom polyfills and stubs to prevent rendering crashes during testing. The reviewer feedback highlights two main areas for improvement: first, globally overriding HTMLElement.prototype.focus with a no-op in jest.setup.js should be avoided to prevent test pollution, suggesting local mocking instead; second, manually monkey-patching the global Date constructor in Footer.snapshot.test.js should be replaced with Jest's native system time mocking utilities (jest.useFakeTimers and jest.setSystemTime).

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread jest.setup.js
Comment on lines +27 to +31
// autoFocus toggles MUI focus classes, and jsdom applies it inconsistently
// across environments (focuses locally but not on CI), which would make
// focus-sensitive snapshots flaky. Neutralize focus so the rendered markup
// is the unfocused state everywhere.
window.HTMLElement.prototype.focus = () => {};

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Globally overriding HTMLElement.prototype.focus with a no-op in jest.setup.js can cause test pollution and break other behavioral or accessibility tests that rely on focus tracking (e.g., asserting document.activeElement or testing form validation focus). Instead of mutating the global prototype for all tests, consider mocking focus locally within the specific snapshot tests that require it, or using a Jest spy that can be restored after each test.

Comment on lines +8 to +24
const RealDate = Date;
const FIXED_ISO = '2024-06-15T12:00:00.000Z';

beforeAll(() => {
global.Date = class extends RealDate {
constructor(...args) {
super(...(args.length ? args : [FIXED_ISO]));
}
static now() {
return new RealDate(FIXED_ISO).getTime();
}
};
});

afterAll(() => {
global.Date = RealDate;
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Monkey-patching the global Date constructor manually is an anti-pattern in Jest and can lead to flaky tests or unexpected side effects in other test suites running in the same environment. Instead, use Jest's built-in, safe system time mocking utilities (jest.useFakeTimers and jest.setSystemTime).

beforeAll(() => {
  jest.useFakeTimers();
  jest.setSystemTime(new Date('2024-06-15T12:00:00.000Z'));
});

afterAll(() => {
  jest.useRealTimers();
});

@hoangsonww hoangsonww self-assigned this Jun 13, 2026
@hoangsonww hoangsonww added enhancement New feature or request help wanted Extra attention is needed good first issue Good for newcomers dependencies Pull requests that update a dependency file labels Jun 13, 2026
@hoangsonww hoangsonww added bug Something isn't working documentation Improvements or additions to documentation question Further information is requested labels Jun 13, 2026
@hoangsonww hoangsonww added this to the v1.x.x - Stable Release milestone Jun 13, 2026
@hoangsonww
hoangsonww merged commit 2e41ebe into master Jun 13, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working dependencies Pull requests that update a dependency file documentation Improvements or additions to documentation enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed question Further information is requested

Projects

Development

Successfully merging this pull request may close these issues.

2 participants