Skip to content

Commit fc03fd2

Browse files
authored
test: add HeroSection responsive rendering tests (JhaSourav07#1911)
## Description Fixes JhaSourav07#1547 Added tests for `HeroSection` to verify responsive rendering, typography headings, layout structure, and key UI elements across mobile, tablet, and desktop breakpoints. Increased component test coverage using `@testing-library/react` and Vitest. ## Pillar * [ ] 🎨 Pillar 1 — New Theme Design * [ ] 📐 Pillar 2 — Geometric SVG Improvement * [ ] 🕐 Pillar 3 — Timezone Logic Optimization * [x] 🛠️ Other (Bug fix, refactoring, docs) ## Visual Preview N/A — test coverage update (no UI changes) ## Checklist before requesting a review: * [x] I have read the `CONTRIBUTING.md` file. * [ ] I have tested these changes locally (`localhost:3000/api/streak?user=YOUR_USERNAME`) * [x] I have run `npm run format` and `npm run lint` locally and resolved all errors (CI will fail otherwise). * [x] My commits follow the Conventional Commits format (e.g., `feat(themes): ...`, `fix(calculate): ...`). * [ ] I have updated `README.md` if I added a new theme or URL parameter. * [x] I have started the repo. * [x] I have made sure that i have only one commit to merge in this PR. * [ ] The SVG output matches the CommitPulse "premium quality" aesthetic standard (no raw elements, smooth animations, correct fonts). * [ ] (Recommended) I joined the CommitPulse Discord community for contributor discussions, mentorship, and faster PR support.
2 parents 30f4f66 + 252b2b7 commit fc03fd2

1 file changed

Lines changed: 39 additions & 26 deletions

File tree

app/components/HeroSection.test.tsx

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { render, screen } from '@testing-library/react';
2+
import '@testing-library/jest-dom/vitest';
23
import { describe, expect, it, vi } from 'vitest';
34
import { HeroSection } from './HeroSection';
45

@@ -12,40 +13,52 @@ vi.mock('framer-motion', () => ({
1213
}));
1314

1415
describe('HeroSection', () => {
15-
it('renders the h1 heading', () => {
16+
it('renders the hero heading and content', () => {
1617
render(<HeroSection />);
1718

18-
const heading = screen.getByRole('heading', {
19-
level: 1,
20-
});
21-
22-
expect(heading).toBeDefined();
23-
});
24-
25-
it("heading contains 'Elevate Your'", () => {
26-
render(<HeroSection />);
27-
28-
expect(screen.getByText(/Elevate Your/i)).toBeDefined();
29-
});
30-
31-
it("heading contains 'Contribution Story'", () => {
32-
render(<HeroSection />);
33-
34-
expect(screen.getByText(/Contribution Story/i)).toBeDefined();
19+
expect(
20+
screen.getByRole('heading', {
21+
level: 1,
22+
name: /elevate your contribution story/i,
23+
})
24+
).toBeInTheDocument();
25+
expect(screen.getByText(/isometric/i).textContent).toMatch(/isometric/i);
3526
});
27+
});
3628

37-
it('renders the descriptive paragraph', () => {
38-
render(<HeroSection />);
29+
describe('HeroSection responsive breakpoints', () => {
30+
const renderAtViewport = (width: number) => {
31+
window.innerWidth = width;
32+
window.dispatchEvent(new Event('resize'));
3933

40-
const paragraph = screen.getByText(/isometric/i);
34+
return render(<HeroSection />);
35+
};
4136

42-
expect(paragraph).toBeDefined();
43-
});
37+
it.each([
38+
{ width: 375, label: 'mobile' },
39+
{ width: 768, label: 'tablet' },
40+
{ width: 1280, label: 'desktop' },
41+
])('renders full typography and high contrast background values at $label width', ({ width }) => {
42+
const { container } = renderAtViewport(width);
4443

45-
it("paragraph mentions 'isometric'", () => {
46-
render(<HeroSection />);
44+
const hero = container.firstElementChild;
45+
const heading = screen.getByRole('heading', {
46+
level: 1,
47+
name: /elevate your contribution story/i,
48+
});
4749

48-
expect(screen.getByText(/isometric/i).textContent).toMatch(/isometric/i);
50+
expect(hero?.className).toContain('bg-[radial-gradient');
51+
expect(heading.tagName).toBe('H1');
52+
expect(heading.className).toContain('text-5xl');
53+
expect(heading.className).toContain('md:text-8xl');
54+
expect(heading.className).toContain('from-green-500');
55+
expect(heading.className).toContain('to-purple-600');
56+
expect(screen.getByText(/generate high-fidelity, 3d isometric monoliths/i).className).toContain(
57+
'text-gray-600'
58+
);
59+
expect(screen.getByPlaceholderText(/enter github username/i)).toBeInTheDocument();
60+
expect(screen.getByRole('button', { name: /copy link/i })).toBeInTheDocument();
61+
expect(screen.getByRole('button', { name: /watch dashboard/i })).toBeInTheDocument();
4962
});
5063
});
5164

0 commit comments

Comments
 (0)