Skip to content

Commit f8a6a3e

Browse files
test: add HeroSection responsive rendering tests
1 parent 4dc3d98 commit f8a6a3e

1 file changed

Lines changed: 39 additions & 26 deletions

File tree

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,39 +13,51 @@ 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
});

0 commit comments

Comments
 (0)