Skip to content

Commit 1e36712

Browse files
authored
test(discordbutton): add error resilience coverage (JhaSourav07#3235)
## Description Fixes JhaSourav07#2738 Added error resilience test coverage for the DiscordButton component. ### Changes Made * Created `components/DiscordButton.error-resilience.test.tsx` * Added tests to verify safe rendering under mocked animation dependencies * Verified Discord invite link renders correctly * Verified external link security attributes (`noopener`, `noreferrer`) * Added resilience checks to ensure UI remains functional when animation libraries are mocked ## 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 only) ## Checklist before requesting a review: * [x] I have read the `CONTRIBUTING.md` file. * [x] 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. * [ ] 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. * [x] The SVG output matches the CommitPulse "premium quality" aesthetic standard. * [x] (Recommended) I joined the CommitPulse Discord community for contributor discussions, mentorship, and faster PR support.
2 parents 29b32e2 + 412eb1f commit 1e36712

1 file changed

Lines changed: 64 additions & 0 deletions

File tree

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { render, screen } from '@testing-library/react';
2+
import { describe, expect, it, vi } from 'vitest';
3+
4+
import { DiscordButton } from './DiscordButton';
5+
6+
vi.mock('gsap', () => ({
7+
default: {
8+
to: vi.fn(),
9+
},
10+
}));
11+
12+
vi.mock('framer-motion', () => ({
13+
motion: {
14+
div: ({ children, ...props }: React.HTMLAttributes<HTMLDivElement>) => (
15+
<div {...props}>{children}</div>
16+
),
17+
a: ({ children, ...props }: React.AnchorHTMLAttributes<HTMLAnchorElement>) => (
18+
<a {...props}>{children}</a>
19+
),
20+
},
21+
}));
22+
23+
describe('DiscordButton error resilience', () => {
24+
it('renders without crashing', () => {
25+
render(<DiscordButton />);
26+
27+
expect(screen.getByText('Join the core community on Discord')).toBeTruthy();
28+
});
29+
30+
it('renders the discord link even when animations are mocked', () => {
31+
render(<DiscordButton />);
32+
33+
const link = screen.getByRole('link');
34+
35+
expect(link).toBeTruthy();
36+
});
37+
38+
it('contains a valid discord invite url', () => {
39+
render(<DiscordButton />);
40+
41+
const link = screen.getByRole('link');
42+
43+
expect(link.getAttribute('href')).toContain('discord.gg');
44+
});
45+
46+
it('opens discord link securely in a new tab', () => {
47+
render(<DiscordButton />);
48+
49+
const link = screen.getByRole('link');
50+
51+
expect(link.getAttribute('target')).toBe('_blank');
52+
53+
const rel = link.getAttribute('rel') ?? '';
54+
55+
expect(rel).toContain('noopener');
56+
expect(rel).toContain('noreferrer');
57+
});
58+
59+
it('keeps button content visible after render', () => {
60+
render(<DiscordButton />);
61+
62+
expect(screen.getByText('Join the core community on Discord')).toBeTruthy();
63+
});
64+
});

0 commit comments

Comments
 (0)