Skip to content

Commit 599695b

Browse files
authored
test: add ShareButtons accessibility coverage (JhaSourav07#3158)
## Description Adds accessibility test coverage for `ShareButtons.tsx`. Tests added: - Verifies LinkedIn share link has an accessible aria-label. - Verifies X/Twitter share link has an accessible aria-label. - Verifies social media icons are marked as decorative. - Verifies external links open securely in a new tab. - Ensures accessibility-related attributes are present and correctly configured. Fixes JhaSourav07#2766 ## 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-only change) ## 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). - [x] (Recommended) I joined the CommitPulse Discord community for contributor discussions, mentorship, and faster PR support.
2 parents ef2abd2 + e7af544 commit 599695b

1 file changed

Lines changed: 69 additions & 0 deletions

File tree

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { render, screen } from '@testing-library/react';
2+
import { describe, expect, it } from 'vitest';
3+
4+
import ShareButtons from './ShareButtons';
5+
6+
describe('ShareButtons accessibility behavior', () => {
7+
const url = 'https://example.com';
8+
const title = 'Test Title';
9+
10+
const renderShareButtons = () => render(<ShareButtons url={url} title={title} />);
11+
12+
it('provides an accessible label for the LinkedIn share link', () => {
13+
renderShareButtons();
14+
15+
const link = screen.getByRole('link', {
16+
name: 'Share on LinkedIn (opens in a new tab)',
17+
});
18+
19+
expect(link).toBeTruthy();
20+
});
21+
22+
it('provides an accessible label for the X/Twitter share link', () => {
23+
renderShareButtons();
24+
25+
const link = screen.getByRole('link', {
26+
name: 'Share on X / Twitter (opens in a new tab)',
27+
});
28+
29+
expect(link).toBeTruthy();
30+
});
31+
32+
it('marks social media icons as decorative', () => {
33+
const { container } = renderShareButtons();
34+
35+
const icons = container.querySelectorAll('svg[aria-hidden="true"]');
36+
37+
expect(icons).toHaveLength(2);
38+
});
39+
40+
it('opens LinkedIn share link in a new tab securely', () => {
41+
renderShareButtons();
42+
43+
const link = screen.getByRole('link', {
44+
name: 'Share on LinkedIn (opens in a new tab)',
45+
});
46+
47+
expect(link.getAttribute('target')).toBe('_blank');
48+
49+
const rel = link.getAttribute('rel') ?? '';
50+
51+
expect(rel).toContain('noopener');
52+
expect(rel).toContain('noreferrer');
53+
});
54+
55+
it('opens X/Twitter share link in a new tab securely', () => {
56+
renderShareButtons();
57+
58+
const link = screen.getByRole('link', {
59+
name: 'Share on X / Twitter (opens in a new tab)',
60+
});
61+
62+
expect(link.getAttribute('target')).toBe('_blank');
63+
64+
const rel = link.getAttribute('rel') ?? '';
65+
66+
expect(rel).toContain('noopener');
67+
expect(rel).toContain('noreferrer');
68+
});
69+
});

0 commit comments

Comments
 (0)