fix(ai): discard proposals when section context changes
This commit is contained in:
@@ -176,6 +176,8 @@ test.each([
|
||||
["text", { text: "Changed career facts" }],
|
||||
["target", { targetId: "experience:job-2" }],
|
||||
["document language", { documentLanguage: "en" }],
|
||||
["context", { context: "Different recorded job requirements" }],
|
||||
["section name", { sectionName: "Different section purpose" }],
|
||||
] as const)("a changed %s invalidates a pending suggestion", async (_source, updates) => {
|
||||
const request = deferred<Proposal>();
|
||||
const { onAccept, rerenderAssistant } = renderAssistant({ onGenerate: jest.fn().mockReturnValue(request.promise) });
|
||||
@@ -188,12 +190,16 @@ test.each([
|
||||
expect(onAccept).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test("source changes remove an existing review before it can be accepted", async () => {
|
||||
test.each([
|
||||
["text", { text: "Changed career facts" }],
|
||||
["context", { context: "Different recorded job requirements" }],
|
||||
["section name", { sectionName: "Different section purpose" }],
|
||||
] as const)("changed %s removes an existing review before it can be accepted", async (_source, updates) => {
|
||||
const { onAccept, rerenderAssistant } = renderAssistant();
|
||||
fireEvent.click(screen.getByRole("button", { name: "AI suggestions" }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Suggest" }));
|
||||
expect(await screen.findByDisplayValue("Proposed wording")).toBeInTheDocument();
|
||||
rerenderAssistant({ text: "Changed career facts" });
|
||||
rerenderAssistant(updates);
|
||||
expect(screen.queryByDisplayValue("Proposed wording")).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole("button", { name: "Apply" })).not.toBeInTheDocument();
|
||||
expect(onAccept).not.toHaveBeenCalled();
|
||||
|
||||
@@ -42,7 +42,7 @@ export default function AiSectionAssistant({ sectionName, text, context, documen
|
||||
setBusy(false);
|
||||
setApplying(false);
|
||||
return () => { requestId.current += 1; };
|
||||
}, [text, targetId, normalizedLanguage, targetLanguage, canUseAi]);
|
||||
}, [text, targetId, context, sectionName, normalizedLanguage, targetLanguage, canUseAi]);
|
||||
|
||||
const discard = () => {
|
||||
requestId.current += 1;
|
||||
|
||||
Reference in New Issue
Block a user