Skip to content

Commit 73bdc8e

Browse files
committed
test(resume-preview-form): add empty fallback coverage
1 parent e3369ea commit 73bdc8e

1 file changed

Lines changed: 125 additions & 0 deletions

File tree

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
import { render, screen, fireEvent } from '@testing-library/react';
2+
import { describe, it, expect, vi, beforeEach } from 'vitest';
3+
import type { ReactNode, HTMLAttributes } from 'react';
4+
import '@testing-library/jest-dom';
5+
6+
import ResumePreviewForm from './ResumePreviewForm';
7+
8+
const mocks = vi.hoisted(() => ({
9+
error: vi.fn(),
10+
success: vi.fn(),
11+
}));
12+
13+
vi.mock('sonner', () => ({
14+
toast: {
15+
error: mocks.error,
16+
success: mocks.success,
17+
},
18+
}));
19+
20+
vi.mock('framer-motion', () => ({
21+
motion: {
22+
div: ({ children, ...props }: HTMLAttributes<HTMLDivElement> & { children?: ReactNode }) => (
23+
<div {...props}>{children}</div>
24+
),
25+
},
26+
}));
27+
28+
const emptyParsed = {
29+
name: '',
30+
email: '',
31+
phone: '',
32+
skills: [],
33+
education: [],
34+
experience: [],
35+
};
36+
37+
describe('ResumePreviewForm empty fallback behavior', () => {
38+
const onBack = vi.fn();
39+
const onComplete = vi.fn();
40+
41+
beforeEach(() => {
42+
vi.clearAllMocks();
43+
});
44+
45+
it('renders safely with empty parsed resume values', () => {
46+
render(
47+
<ResumePreviewForm
48+
githubUsername="john"
49+
parsed={emptyParsed}
50+
fileName="empty.pdf"
51+
onBack={onBack}
52+
onComplete={onComplete}
53+
/>
54+
);
55+
56+
expect(screen.getByText('Review Parsed Data')).toBeInTheDocument();
57+
});
58+
59+
it('shows empty fallback input fields for missing profile values', () => {
60+
render(
61+
<ResumePreviewForm
62+
githubUsername="john"
63+
parsed={emptyParsed}
64+
fileName="empty.pdf"
65+
onBack={onBack}
66+
onComplete={onComplete}
67+
/>
68+
);
69+
70+
const inputs = screen.getAllByRole('textbox');
71+
72+
expect(inputs[0]).toHaveValue('');
73+
expect(inputs[1]).toHaveValue('');
74+
});
75+
76+
it('does not crash when skills array is empty', () => {
77+
render(
78+
<ResumePreviewForm
79+
githubUsername="john"
80+
parsed={emptyParsed}
81+
fileName="empty.pdf"
82+
onBack={onBack}
83+
onComplete={onComplete}
84+
/>
85+
);
86+
87+
expect(screen.getByText(/skills/i)).toBeInTheDocument();
88+
});
89+
90+
it('prevents submission when required fallback fields are empty', () => {
91+
const fetchMock = vi.fn();
92+
vi.stubGlobal('fetch', fetchMock);
93+
94+
render(
95+
<ResumePreviewForm
96+
githubUsername="john"
97+
parsed={emptyParsed}
98+
fileName="empty.pdf"
99+
onBack={onBack}
100+
onComplete={onComplete}
101+
/>
102+
);
103+
104+
fireEvent.click(screen.getByText('Save Profile'));
105+
106+
expect(fetchMock).not.toHaveBeenCalled();
107+
expect(onComplete).not.toHaveBeenCalled();
108+
});
109+
110+
it('allows user to add a skill from an empty fallback state', () => {
111+
render(
112+
<ResumePreviewForm
113+
githubUsername="john"
114+
parsed={emptyParsed}
115+
fileName="empty.pdf"
116+
onBack={onBack}
117+
onComplete={onComplete}
118+
/>
119+
);
120+
121+
fireEvent.click(screen.getAllByText('Add')[0]);
122+
123+
expect(screen.getByText('Skills')).toBeInTheDocument();
124+
});
125+
});

0 commit comments

Comments
 (0)