feat(jobs): complete workspace draft parity
CI and Deploy / test (pull_request) Successful in 5m4s
CI and Deploy / deploy (pull_request) Has been skipped

This commit is contained in:
cesnimda
2026-08-15 17:34:32 +02:00
parent 3b86ea2da0
commit deed948183
28 changed files with 676 additions and 131 deletions
+55 -2
View File
@@ -3,7 +3,7 @@ import "@testing-library/jest-dom";
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
import {
ApplicationCoverLetterSection, ApplicationCvSection,
ApplicationCoverLetterSection, ApplicationCvSection, ApplicationPackageDraftsSection,
} from "./components/ApplicationAssets";
import { api } from "./api";
@@ -134,11 +134,13 @@ test("cover letter loads the current text and its history", async () => {
test("editing marks the draft dirty and saving sends the new text", async () => {
routeGet();
mockedApi.put.mockResolvedValue({ data: { ...coverLetter, text: "Dear hiring team" } } as any);
const onDirtyChange = jest.fn();
render(<ApplicationCoverLetterSection jobId={7} />);
render(<ApplicationCoverLetterSection jobId={7} onDirtyChange={onDirtyChange} />);
fireEvent.change(await screen.findByLabelText("Cover letter"), { target: { value: "Dear hiring team" } });
expect(screen.getByText("Unsaved changes")).toBeInTheDocument();
expect(onDirtyChange).toHaveBeenLastCalledWith(true);
fireEvent.click(screen.getByRole("button", { name: "Save" }));
await waitFor(() => expect(mockedApi.put).toHaveBeenCalledWith(
@@ -187,3 +189,54 @@ test("a failed load surfaces an error", async () => {
expect(await screen.findByText(/Could not load this section/i)).toBeInTheDocument();
});
// ---------- Application package drafts ----------
test("application answer and recruiter drafts save from the dedicated workspace", async () => {
mockedApi.put.mockResolvedValue({ data: undefined } as any);
const onSaved = jest.fn();
render(
<ApplicationPackageDraftsSection
jobId={7}
initialApplicationAnswer="Saved answer"
initialRecruiterMessage="Saved recruiter note"
onSaved={onSaved}
/>,
);
fireEvent.change(screen.getByLabelText("Application answer"), { target: { value: "Edited answer" } });
fireEvent.change(screen.getByLabelText("Recruiter message"), { target: { value: "Edited recruiter note" } });
expect(screen.getByText("Unsaved changes")).toBeInTheDocument();
fireEvent.click(screen.getByRole("button", { name: "Save application drafts" }));
await waitFor(() => expect(mockedApi.put).toHaveBeenCalledWith(
"/jobapplications/7/application-drafts",
{
applicationAnswerDraft: "Edited answer",
recruiterMessageDraft: "Edited recruiter note",
},
));
expect(onSaved).toHaveBeenCalled();
});
test("application package drafts can be cleared without deleting ordinary notes", async () => {
mockedApi.put.mockResolvedValue({ data: undefined } as any);
render(
<ApplicationPackageDraftsSection
jobId={7}
initialApplicationAnswer="Saved answer"
initialRecruiterMessage="Saved recruiter note"
/>,
);
fireEvent.change(screen.getByLabelText("Application answer"), { target: { value: "" } });
fireEvent.change(screen.getByLabelText("Recruiter message"), { target: { value: "" } });
fireEvent.click(screen.getByRole("button", { name: "Save application drafts" }));
await waitFor(() => expect(mockedApi.put).toHaveBeenCalledWith(
"/jobapplications/7/application-drafts",
{ applicationAnswerDraft: "", recruiterMessageDraft: "" },
));
});