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.

feat(cover-letter): add generate action to job details

Khuram Niaz08bc856e712e
diff --git a/__tests__/JobDetails.spec.tsx b/__tests__/JobDetails.spec.tsx
index c01c196..ae96cf8 100644
--- a/__tests__/JobDetails.spec.tsx
+++ b/__tests__/JobDetails.spec.tsx
@@ -2,6 +2,7 @@ import React from "react";
import JobDetails from "@/components/myjobs/JobDetails";
import { JobResponse, Tag } from "@/models/job.model";
import { render, screen, act } from "@testing-library/react";
+import userEvent from "@testing-library/user-event";
vi.mock("next/navigation", () => ({
useRouter: vi.fn(() => ({ back: vi.fn(), push: vi.fn(), replace: vi.fn() })),
@@ -18,6 +19,11 @@ vi.mock("@/components/profile/AiJobMatchSection", () => ({
},
}));
+vi.mock("@/components/myjobs/GenerateCoverLetterSection", () => ({
+ GenerateCoverLetterSection: ({ open }: { open: boolean }) =>
+ open ? <div data-testid="cover-letter-sheet" /> : null,
+}));
+
vi.mock("@/components/myjobs/NotesSection", () => ({
NotesSection: () => null,
}));
@@ -209,3 +215,50 @@ describe("JobDetails – match data display", () => {
expect(screen.getByText("90%")).toBeInTheDocument();
});
});
+
+describe("JobDetails cover letter action", () => {
+ it("stays enabled when no resume is linked", () => {
+ render(<JobDetails {...baseProps} job={makeJob({ resumeId: undefined })} />);
+ expect(screen.getByTestId("generate-cover-letter-btn")).toBeEnabled();
+ });
+
+ it("disables the action for a title-only description", () => {
+ render(
+ <JobDetails
+ {...baseProps}
+ job={makeJob({
+ resumeId: "resume-1",
+ descriptionCompleteness: "title-only",
+ })}
+ />,
+ );
+ expect(screen.getByTestId("generate-cover-letter-btn")).toBeDisabled();
+ });
+
+ it("enables the action for a real description", () => {
+ render(
+ <JobDetails {...baseProps} job={makeJob({ resumeId: "resume-1" })} />,
+ );
+ expect(screen.getByTestId("generate-cover-letter-btn")).toBeEnabled();
+ });
+
+ it("opens the sheet on click", async () => {
+ render(
+ <JobDetails {...baseProps} job={makeJob({ resumeId: "resume-1" })} />,
+ );
+ await userEvent.click(screen.getByTestId("generate-cover-letter-btn"));
+ expect(screen.getByTestId("cover-letter-sheet")).toBeInTheDocument();
+ });
+
+ it("labels the action Regenerate when a letter is already linked", () => {
+ render(
+ <JobDetails
+ {...baseProps}
+ job={makeJob({ resumeId: "resume-1", coverLetterId: "cl-1" })}
+ />,
+ );
+ expect(screen.getByTestId("generate-cover-letter-btn")).toHaveTextContent(
+ /regenerate/i,
+ );
+ });
+});
diff --git a/src/components/myjobs/JobDetails.tsx b/src/components/myjobs/JobDetails.tsx
index 3445fd0..6d333d1 100644
--- a/src/components/myjobs/JobDetails.tsx
+++ b/src/components/myjobs/JobDetails.tsx
@@ -25,6 +25,7 @@ import {
import { Button } from "../ui/button";
import {
ArrowLeft,
+ FileText,
MoreVertical,
Pencil,
Sparkles,
@@ -35,6 +36,7 @@ import {
} from "lucide-react";
import { useRouter } from "next/navigation";
import { AiJobMatchSection } from "../profile/AiJobMatchSection";
+import { GenerateCoverLetterSection } from "./GenerateCoverLetterSection";
import { NotesSection } from "./NotesSection";
import { useState, useMemo, useCallback } from "react";
import { DownloadFileButton } from "../profile/DownloadFileButton";
@@ -82,6 +84,10 @@ function JobDetails({
const [currentMatchScore, setCurrentMatchScore] = useState(job.matchScore);
const [currentMatchData, setCurrentMatchData] = useState(job.matchData);
const [currentStatus, setCurrentStatus] = useState(job.Status);
+ const [coverLetterOpen, setCoverLetterOpen] = useState(false);
+ const [currentCoverLetterId, setCurrentCoverLetterId] = useState(
+ job.coverLetterId,
+ );
const [editJobTarget, setEditJobTarget] = useState<JobResponse | null>(
null,
);
@@ -110,6 +116,15 @@ function JobDetails({
setAiSectionOpen(true);
};
+ const coverLetterBlockedReason =
+ job.descriptionCompleteness === "title-only"
+ ? "Add a job description first"
+ : undefined;
+
+ const handleCoverLetterSaved = useCallback((coverLetterId: string) => {
+ setCurrentCoverLetterId(coverLetterId);
+ }, []);
+
const onEditJob = () => {
setEditJobTarget({ ...job, Status: currentStatus });
};
@@ -186,6 +201,20 @@ function JobDetails({
Match with AI
</span>
</Button>
+ <Button
+ size="sm"
+ variant="outline"
+ className="h-8 gap-1 cursor-pointer"
+ data-testid="generate-cover-letter-btn"
+ disabled={!!coverLetterBlockedReason}
+ title={coverLetterBlockedReason}
+ onClick={() => setCoverLetterOpen(true)}
+ >
+ <FileText className="h-3.5 w-3.5" />
+ <span className="sr-only sm:not-sr-only sm:whitespace-nowrap">
+ {currentCoverLetterId ? "Regenerate Letter" : "Cover Letter"}
+ </span>
+ </Button>
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button
@@ -368,6 +397,13 @@ function JobDetails({
onMatchSaved={handleMatchSaved}
/>
}
+ <GenerateCoverLetterSection
+ jobId={job?.id}
+ jobResumeId={job.resumeId}
+ open={coverLetterOpen}
+ triggerChange={setCoverLetterOpen}
+ onSaved={handleCoverLetterSaved}
+ />
<AddJob
jobStatuses={jobStatuses}
companies={companies}
diff --git a/src/models/job.model.ts b/src/models/job.model.ts
index bd523f8..71b6ab5 100644
--- a/src/models/job.model.ts
+++ b/src/models/job.model.ts
@@ -56,6 +56,7 @@ export interface JobResponse {
tags?: Tag[];
createdVia?: string | null;
discoveryStatus?: string | null;
+ descriptionCompleteness?: DescriptionCompleteness | null;
_count?: { Notes?: number };
}