fix(webui): keep automation change-back state accurate
This commit is contained in:
1 parent
b032a24960
commit
17a66dcecf
2 files changed
+42
-2
No files matched your search
@@ -56,7 +56,10 @@ export function AutomationChatBinding({ job, token, chatNames, onSave, children
|
||||
const controller = new AbortController();
|
||||
setLoadError(false);
|
||||
void fetchAutomationChats(token, job.id, controller.signal).then(value => {
|
||||
if (!controller.signal.aborted) setData(value);
|
||||
if (!controller.signal.aborted) {
|
||||
setData(value);
|
||||
setSaved(previous => previous?.target.id === value.current?.id ? previous : null);
|
||||
}
|
||||
}).catch(() => { if (!controller.signal.aborted) setLoadError(true); });
|
||||
return () => controller.abort();
|
||||
}, [token, job.id, job.chat_binding_revision, reload]);
|
||||
@@ -91,7 +94,7 @@ export function AutomationChatBinding({ job, token, chatNames, onSave, children
|
||||
disabled={pickerDisabled} onValueChange={id => {
|
||||
const target = data?.chats.find(chat => chat.id === id);
|
||||
if (!target || target.unavailable || id === current?.id) return;
|
||||
setError(""); setSaved(null);
|
||||
setError("");
|
||||
setDraft(previous => previous ? { ...previous, target } : {
|
||||
target, previous: current ?? fallback,
|
||||
revision: job.chat_binding_revision!, message: job.payload.message,
|
||||
|
||||
@@ -90,6 +90,43 @@ it("uses Chinese for the task menu and the change/cancel path", async () => {
|
||||
expect(save).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("keeps change-back available when another proposed change is cancelled", async () => {
|
||||
const user = userEvent.setup();
|
||||
const save = vi.fn().mockResolvedValue(undefined);
|
||||
const { rerender } = render(<AutomationDetailDialog {...props} job={job} onChangeChat={save} />);
|
||||
await choose();
|
||||
vi.mocked(fetchAutomationChats).mockResolvedValue({ ...choices, current: target, revision: "rev-2" });
|
||||
await user.click(screen.getByRole("button", { name: "Confirm change" }));
|
||||
rerender(<AutomationDetailDialog {...props} job={{ ...job, chat_binding_revision: "rev-2" }} onChangeChat={save} />);
|
||||
const changeBack = await screen.findByRole("button", { name: "Change back to “My planning”" });
|
||||
await waitFor(() => expect(changeBack).toBeEnabled());
|
||||
fireEvent.keyDown(screen.getByRole("combobox", { name: "Run and reply in" }), { key: "ArrowDown" });
|
||||
await user.click(await screen.findByRole("option", { name: /My planning/ }));
|
||||
await user.click(screen.getByRole("button", { name: "Cancel" }));
|
||||
expect(screen.getByRole("combobox", { name: "Run and reply in" })).toHaveTextContent("Product team");
|
||||
expect(screen.getByRole("button", { name: "Change back to “My planning”" })).toBeEnabled();
|
||||
expect(save).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("removes an obsolete save confirmation after another client changes the chat", async () => {
|
||||
const user = userEvent.setup();
|
||||
const save = vi.fn().mockResolvedValue(undefined);
|
||||
const { rerender } = render(<AutomationDetailDialog {...props} job={job} onChangeChat={save} />);
|
||||
await choose();
|
||||
vi.mocked(fetchAutomationChats).mockResolvedValue({ ...choices, current: target, revision: "rev-2" });
|
||||
await user.click(screen.getByRole("button", { name: "Confirm change" }));
|
||||
rerender(<AutomationDetailDialog {...props} job={{ ...job, chat_binding_revision: "rev-2" }} onChangeChat={save} />);
|
||||
expect(await screen.findByRole("status")).toHaveTextContent("Product team");
|
||||
|
||||
vi.mocked(fetchAutomationChats).mockResolvedValue({ ...choices, revision: "rev-3" });
|
||||
rerender(<AutomationDetailDialog {...props} job={{ ...job, chat_binding_revision: "rev-3" }} onChangeChat={save} />);
|
||||
await waitFor(() => expect(screen.getByRole("combobox", { name: "Run and reply in" })).toBeEnabled());
|
||||
expect(screen.getByRole("combobox", { name: "Run and reply in" })).toHaveTextContent("My planning");
|
||||
expect(screen.queryByRole("status")).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole("button", { name: /Change back/ })).not.toBeInTheDocument();
|
||||
expect(save).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("cancels a chat change without saving the edited instructions", async () => {
|
||||
const user = userEvent.setup();
|
||||
const save = vi.fn();
|
||||
|
||||
Reference in new issue
Block a user