Skip to content

Commit 3267843

Browse files
authored
test(LanguageChart): add empty fallback coverage (JhaSourav07#3615)
## Description Fixes JhaSourav07#2563 Added empty/fallback state test coverage for `LanguageChart`. ## Pillar * [ ] 🎨 Pillar 1 β€” New Theme Design * [ ] πŸ“ Pillar 2 β€” Geometric SVG Improvement * [ ] πŸ• Pillar 3 β€” Timezone Logic Optimization * [x] πŸ› οΈ Other (Bug fix, refactoring, docs) ## Visual Preview Not applicable β€” test-only change. ## Checklist before requesting a review: * [x] I have read the `CONTRIBUTING.md` file. * [x] I have tested these changes locally (`npm run test -- LanguageChart.empty-fallback.test.tsx`). * [x] I have run `npm run lint` locally and resolved all errors. * [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. * [ ] The SVG output matches the CommitPulse "premium quality" aesthetic standard. * [ ] (Recommended) I joined the CommitPulse Discord community for contributor discussions, mentorship, and faster PR support. ## Tests * Added 5 test cases for `LanguageChart` empty/missing input fallback behavior. * Verified fallback UI renders without crashing. * Verified empty layout remains stable. * Verified no unexpected runtime errors occur. * Added `IntersectionObserver` mock for test environment stability.
2 parents 3178ef7 + e363e10 commit 3267843

1 file changed

Lines changed: 46 additions & 0 deletions

File tree

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { render, screen } from '@testing-library/react';
2+
import { describe, expect, it, vi } from 'vitest';
3+
4+
import LanguageChart, { buildGradientStops } from './LanguageChart';
5+
6+
class MockIntersectionObserver implements IntersectionObserver {
7+
readonly root: Element | Document | null = null;
8+
readonly rootMargin: string = '';
9+
readonly thresholds: ReadonlyArray<number> = [];
10+
11+
disconnect = vi.fn();
12+
observe = vi.fn();
13+
takeRecords = vi.fn(() => []);
14+
unobserve = vi.fn();
15+
}
16+
17+
global.IntersectionObserver = MockIntersectionObserver;
18+
describe('LanguageChart empty fallback', () => {
19+
it('renders fallback UI for empty languages array', () => {
20+
render(<LanguageChart languages={[]} />);
21+
22+
expect(screen.getByText('Top Languages')).toBeInTheDocument();
23+
expect(screen.getByText('No language data found')).toBeInTheDocument();
24+
});
25+
26+
it('does not render language percentage markers in empty state', () => {
27+
render(<LanguageChart languages={[]} />);
28+
29+
expect(screen.queryByText('%')).not.toBeInTheDocument();
30+
});
31+
32+
it('keeps the fallback layout stable', () => {
33+
const { container } = render(<LanguageChart languages={[]} />);
34+
35+
expect(container.firstChild).toBeInTheDocument();
36+
expect(container.textContent).toContain('No language data found');
37+
});
38+
39+
it('does not throw runtime error for empty languages array', () => {
40+
expect(() => render(<LanguageChart languages={[]} />)).not.toThrow();
41+
});
42+
43+
it('returns empty gradient stops for empty language data', () => {
44+
expect(buildGradientStops([])).toBe('');
45+
});
46+
});

0 commit comments

Comments
Β (0)