|
1 | | -import { describe, it, expect } from 'vitest'; |
| 1 | +import '@testing-library/jest-dom/vitest'; |
2 | 2 | import { render, screen } from '@testing-library/react'; |
| 3 | +import { describe, expect, it } from 'vitest'; |
3 | 4 | import { Footer } from './Footer'; |
4 | 5 |
|
5 | 6 | describe('Footer Component', () => { |
6 | 7 | it('renders community text', () => { |
7 | 8 | render(<Footer />); |
8 | 9 |
|
9 | | - const text = screen.getByText(/Designed for the elite builder community/i); |
10 | | - |
11 | | - expect(text).toBeTruthy(); |
| 10 | + expect(screen.getByText(/Designed for the elite builder community/i)).toBeInTheDocument(); |
12 | 11 | }); |
13 | 12 |
|
14 | | - it('renders Documentation link', () => { |
| 13 | + it('renders Documentation link with the correct destination', () => { |
15 | 14 | render(<Footer />); |
16 | 15 |
|
17 | | - const docLink = screen.getByText(/Documentation/i); |
18 | | - |
19 | | - expect(docLink).toBeTruthy(); |
| 16 | + const documentationLink = screen.getByRole('link', { |
| 17 | + name: /Documentation/i, |
| 18 | + }); |
20 | 19 |
|
21 | | - expect(docLink.closest('a')?.getAttribute('href')).toBe( |
| 20 | + expect(documentationLink).toHaveAttribute( |
| 21 | + 'href', |
22 | 22 | 'https://github.com/JhaSourav07/commitpulse/blob/main/README.md' |
23 | 23 | ); |
24 | 24 | }); |
25 | 25 |
|
26 | | - it('opens documentation in new tab', () => { |
| 26 | + it('opens Documentation link in a new tab securely', () => { |
27 | 27 | render(<Footer />); |
28 | 28 |
|
29 | | - const docLink = screen.getByText(/Documentation/i); |
| 29 | + const documentationLink = screen.getByRole('link', { |
| 30 | + name: /Documentation/i, |
| 31 | + }); |
30 | 32 |
|
31 | | - expect(docLink.closest('a')?.getAttribute('target')).toBe('_blank'); |
| 33 | + expect(documentationLink).toHaveAttribute('target', '_blank'); |
| 34 | + expect(documentationLink).toHaveAttribute('rel', expect.stringContaining('noopener')); |
| 35 | + expect(documentationLink).toHaveAttribute('rel', expect.stringContaining('noreferrer')); |
32 | 36 | }); |
33 | 37 |
|
34 | 38 | it('renders Contributors link', () => { |
35 | 39 | render(<Footer />); |
36 | 40 |
|
37 | | - const contributorsLink = screen.getByText(/Contributors/i); |
38 | | - |
39 | | - expect(contributorsLink).toBeTruthy(); |
| 41 | + expect( |
| 42 | + screen.getByRole('link', { |
| 43 | + name: /Contributors/i, |
| 44 | + }) |
| 45 | + ).toBeInTheDocument(); |
40 | 46 | }); |
41 | 47 |
|
42 | | - describe('responsive links and footer tag', () => { |
43 | | - it.each([ |
44 | | - ['mobile', 375], |
45 | | - ['desktop', 1280], |
46 | | - ])('renders documented links and the footer tag at the %s breakpoint', (_breakpoint, width) => { |
47 | | - window.innerWidth = width; |
48 | | - |
49 | | - const { container } = render(<Footer />); |
50 | | - |
51 | | - const layout = container.querySelector('.flex.flex-col.md\\:flex-row'); |
52 | | - const contributorsLink = screen.getByRole('link', { name: 'Contributors' }); |
53 | | - const documentationLink = screen.getByRole('link', { name: 'Documentation' }); |
54 | | - const creatorLink = screen.getByRole('link', { name: 'Creator' }); |
55 | | - |
56 | | - expect(layout).toBeTruthy(); |
57 | | - expect(contributorsLink.getAttribute('href')).toBe('/contributors'); |
58 | | - expect(documentationLink.getAttribute('href')).toBe( |
59 | | - 'https://github.com/JhaSourav07/commitpulse/blob/main/README.md' |
60 | | - ); |
61 | | - expect(creatorLink.getAttribute('href')).toBe('https://github.com/jhasourav07'); |
62 | | - expect(screen.getByText(/2026 CommitPulse\. All rights reserved\./i)).toBeTruthy(); |
63 | | - }); |
64 | | - }); |
65 | | -}); |
66 | | -it('renders CommitPulse heading', () => { |
67 | | - render(<Footer />); |
68 | | - |
69 | | - const heading = screen.getByText('CommitPulse'); |
70 | | - |
71 | | - expect(heading).toBeTruthy(); |
72 | | -}); |
73 | | -it('renders Creator link', () => { |
74 | | - render(<Footer />); |
| 48 | + it('exposes the footer as a semantic contentinfo landmark for screen readers', () => { |
| 49 | + render(<Footer />); |
75 | 50 |
|
76 | | - const creatorLink = screen.getByText(/Creator/i); |
| 51 | + // A semantic <footer> is exposed to assistive technology as the contentinfo landmark. |
| 52 | + const footer = screen.getByRole('contentinfo'); |
77 | 53 |
|
78 | | - expect(creatorLink).toBeTruthy(); |
79 | | -}); |
80 | | -it('creator link points to GitHub profile', () => { |
81 | | - render(<Footer />); |
82 | | - |
83 | | - const creatorLink = screen.getByText(/Creator/i); |
| 54 | + expect(footer).toBeInTheDocument(); |
| 55 | + expect(footer.tagName).toBe('FOOTER'); |
| 56 | + }); |
84 | 57 |
|
85 | | - expect(creatorLink.closest('a')?.getAttribute('href')).toBe('https://github.com/jhasourav07'); |
86 | | -}); |
87 | | -it('renders copyright text', () => { |
88 | | - render(<Footer />); |
| 58 | + it('includes responsive layout classes for mobile and desktop breakpoints', () => { |
| 59 | + render(<Footer />); |
89 | 60 |
|
90 | | - expect(screen.getByText(/© 2026 CommitPulse. All rights reserved./i)).toBeTruthy(); |
| 61 | + const footer = screen.getByRole('contentinfo'); |
| 62 | + |
| 63 | + // JSDOM cannot calculate Tailwind media queries, so this verifies the actual |
| 64 | + // responsive utility classes that switch the footer layout at the md breakpoint. |
| 65 | + const responsiveLayout = footer.querySelector('.flex.flex-col.md\\:flex-row.md\\:items-start'); |
| 66 | + |
| 67 | + expect(responsiveLayout).toBeInTheDocument(); |
| 68 | + expect(responsiveLayout).toHaveClass( |
| 69 | + 'mx-auto', |
| 70 | + 'flex', |
| 71 | + 'max-w-6xl', |
| 72 | + 'flex-col', |
| 73 | + 'items-center', |
| 74 | + 'justify-between', |
| 75 | + 'gap-6', |
| 76 | + 'text-sm', |
| 77 | + 'md:flex-row', |
| 78 | + 'md:items-start', |
| 79 | + 'md:gap-0' |
| 80 | + ); |
| 81 | + }); |
91 | 82 | }); |
0 commit comments