feat(jobs): complete workspace draft parity
This commit is contained in:
@@ -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: "" },
|
||||
));
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user