feat(cover-letter): add contextual AI workspace

This commit is contained in:
cesnimda
2026-08-28 12:34:17 +02:00
parent e3f938cb42
commit b6dcc7c760
7 changed files with 346 additions and 21 deletions
@@ -182,6 +182,48 @@ test("an empty cover letter offers the template and an empty history", async ()
.toContain("Dear Hiring Manager");
});
test("AI cover letter suggestions use the linked CV and require explicit apply", async () => {
routeGet();
mockedApi.post.mockResolvedValue({
data: {
id: 9,
module: "cover-letter",
mode: "professional",
title: "Cover letter · Generate · Professional",
provider: "local",
result: { text: "A tailored, truthful suggestion." },
createdAtUtc: "2026-07-19T11:00:00Z",
},
} as any);
render(<ApplicationCoverLetterSection jobId={7} />);
expect(await screen.findByText(/application's full job advert and analysis/i)).toBeInTheDocument();
const assistantSelects = screen.getAllByRole("combobox");
fireEvent.mouseDown(assistantSelects[assistantSelects.length - 1]);
fireEvent.click(await screen.findByRole("option", { name: /Norsk bokmål/i }));
fireEvent.click(screen.getByRole("button", { name: "Generate" }));
await waitFor(() => expect(mockedApi.post).toHaveBeenCalledWith(
"/jobapplications/7/ai/generate",
expect.objectContaining({
module: "cover-letter",
targetLanguage: "nb-NO",
currentText: "Dear team",
action: "generate",
}),
));
expect(screen.getByLabelText("Cover letter")).toHaveValue("Dear team");
fireEvent.click(await screen.findByRole("button", { name: /Apply to editor/i }));
expect(screen.getByLabelText("Cover letter")).toHaveValue("A tailored, truthful suggestion.");
mockedApi.put.mockResolvedValue({ data: { ...coverLetter, text: "A tailored, truthful suggestion." } } as any);
fireEvent.click(screen.getByRole("button", { name: "Save" }));
await waitFor(() => expect(mockedApi.put).toHaveBeenCalledWith(
"/jobapplications/7/cover-letter",
{ text: "A tailored, truthful suggestion.", source: "ai", aiAction: "generate" },
));
});
test("a failed load surfaces an error", async () => {
mockedApi.get.mockRejectedValue(new Error("boom"));