Skip to content

Job application tracker and AI-powered job search assistant. Helps job seekers manage their search journey with AI resume review, job matching, task logging, and application analytics, all while keeping your data private.

fix(AddExperience): clear end date when switching job status to current

Khuram Niaz946299a8dbd5
diff --git a/__tests__/AddExperience.spec.tsx b/__tests__/AddExperience.spec.tsx
index 4cfc51f..5b26895 100644
--- a/__tests__/AddExperience.spec.tsx
+++ b/__tests__/AddExperience.spec.tsx
@@ -491,6 +491,65 @@ describe("AddExperience Component", () => {
});
});
+ it("should clear the end date when an ended job is switched to current", async () => {
+ const mockExperienceToEdit: ResumeSection = {
+ id: "section-1",
+ resumeId: mockResumeId,
+ sectionTitle: "Work Experience",
+ sectionType: "experience" as any,
+ workExperiences: [
+ {
+ id: "exp-1",
+ Company: mockCompanies[0] as any,
+ jobTitle: mockJobTitles[0] as any,
+ location: mockLocations[0] as any,
+ startDate: new Date("2020-01-01"),
+ endDate: new Date("2022-12-31"),
+ currentJob: false,
+ description: "Worked on various projects",
+ },
+ ],
+ };
+
+ (updateExperience as any).mockResolvedValue({
+ success: true,
+ message: "Experience updated successfully",
+ });
+
+ render(
+ <AddExperience
+ resumeId={mockResumeId}
+ sectionId={mockSectionId}
+ dialogOpen={true}
+ setDialogOpen={mockSetDialogOpen}
+ experienceToEdit={mockExperienceToEdit}
+ />
+ );
+
+ await waitFor(() => {
+ expect(screen.getByText(/job ended/i)).toBeInTheDocument();
+ });
+
+ await user.click(screen.getByRole("switch"));
+
+ await waitFor(() => {
+ const saveButton = screen.getByRole("button", { name: /save/i });
+ expect(saveButton).not.toBeDisabled();
+ });
+
+ await user.click(screen.getByRole("button", { name: /save/i }));
+
+ await waitFor(() => {
+ expect(updateExperience).toHaveBeenCalledWith(
+ expect.objectContaining({
+ id: "exp-1",
+ currentJob: true,
+ endDate: null,
+ })
+ );
+ });
+ });
+
it("should close dialog and show success toast on successful submission", async () => {
(addExperience as any).mockResolvedValue({
success: true,
diff --git a/src/components/profile/AddExperience.tsx b/src/components/profile/AddExperience.tsx
index 1fe525e..bb31c1d 100644
--- a/src/components/profile/AddExperience.tsx
+++ b/src/components/profile/AddExperience.tsx
@@ -76,7 +76,7 @@ function AddExperience({
},
});
- const { watch, reset, formState, resetField } = form;
+ const { watch, reset, formState, setValue } = form;
const currentJobValue = watch("currentJob");
@@ -134,7 +134,7 @@ function AddExperience({
const onCurrentJob = (current: boolean) => {
if (current) {
- resetField("endDate");
+ setValue("endDate", null, { shouldDirty: true });
}
};