Skip to content

Commit af3f095

Browse files
authored
test(scroll-restoration): add type compiler coverage (JhaSourav07#3164)
## Description Fixes JhaSourav07#2832 Adds focused Vitest coverage for TypeScript compiler validation and schema constraint stability in `app/components/ScrollRestoration.tsx`. Tests verify: * Component type signature remains stable * Component accepts no required props * Invalid prop contracts are rejected through type assertions * Optional pathname-like values are accepted without type errors * Scroll storage key validation constraints produce strict results ## 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. * [ ] 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 d67b08e + e795c0d commit af3f095

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { render } from '@testing-library/react';
2+
import { describe, expect, expectTypeOf, it, vi } from 'vitest';
3+
import ScrollRestoration from './ScrollRestoration';
4+
5+
vi.mock('next/navigation', () => ({
6+
usePathname: () => '/contributors',
7+
}));
8+
9+
type ScrollRestorationComponent = typeof ScrollRestoration;
10+
type ScrollRestorationProps = Parameters<ScrollRestorationComponent>;
11+
12+
function validateScrollStorageKey(key: string) {
13+
return /^scroll-position-\/.+/.test(key);
14+
}
15+
16+
describe('ScrollRestoration type compiler validation', () => {
17+
it('exports a callable React component with no required props', () => {
18+
expectTypeOf(ScrollRestoration).toBeFunction();
19+
expectTypeOf<ScrollRestorationProps>().toEqualTypeOf<[]>();
20+
});
21+
22+
it('renders without visible DOM output', () => {
23+
const { container } = render(<ScrollRestoration />);
24+
25+
expect(container.textContent).toBe('');
26+
expect(container.firstElementChild).toBeNull();
27+
});
28+
29+
it('blocks invalid prop parameters at compile time', () => {
30+
expectTypeOf<ScrollRestorationProps>().not.toEqualTypeOf<[{ pathname: string }]>();
31+
});
32+
33+
it('accepts optional pathname-like values in schema helper checks', () => {
34+
type OptionalPathname = string | undefined;
35+
36+
const optionalPathname: OptionalPathname = '/contributors';
37+
38+
expectTypeOf<OptionalPathname>().toEqualTypeOf<string | undefined>();
39+
40+
expect(validateScrollStorageKey(`scroll-position-${optionalPathname}`)).toBe(true);
41+
});
42+
43+
it('returns strict validation reports for scroll storage key constraints', () => {
44+
expect(validateScrollStorageKey('scroll-position-/contributors')).toBe(true);
45+
expect(validateScrollStorageKey('scroll-position-')).toBe(false);
46+
expect(validateScrollStorageKey('contributors')).toBe(false);
47+
expect(validateScrollStorageKey('')).toBe(false);
48+
});
49+
});

0 commit comments

Comments
 (0)