Skip to content

Commit 92db503

Browse files
committed
refactor(ui): consolidate cron form control rendering
1 parent fd343ca commit 92db503

2 files changed

Lines changed: 398 additions & 680 deletions

File tree

‎ui/src/pages/cron/view.test.ts‎

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -602,19 +602,38 @@ describe("cron view editor", () => {
602602
expect(onClosePanel).toHaveBeenCalledTimes(1);
603603
});
604604

605-
it("wires form changes from prompt and name inputs", () => {
605+
it("wires shared text and select controls without changing their field ownership", () => {
606606
const onFormChange = vi.fn();
607-
const container = renderView({ createOpen: true, onFormChange });
607+
const container = renderView({
608+
createOpen: true,
609+
channels: ["telegram"],
610+
channelMeta: [{ id: "telegram", label: "", detailLabel: "Telegram" }],
611+
channelLabels: { telegram: "Telegram fallback" },
612+
form: { ...DEFAULT_CRON_FORM, scheduleKind: "cron", failureAlertMode: "custom" },
613+
onFormChange,
614+
});
608615

609616
const prompt = getElement(container, "#cron-payload-text", HTMLTextAreaElement);
610617
prompt.value = "do the thing";
611618
prompt.dispatchEvent(new Event("input", { bubbles: true }));
612619
expect(onFormChange).toHaveBeenCalledWith({ payloadText: "do the thing" });
613620

614-
const name = getElement(container, "#cron-name", HTMLInputElement);
615-
name.value = "Thing";
616-
name.dispatchEvent(new Event("input", { bubbles: true }));
617-
expect(onFormChange).toHaveBeenCalledWith({ name: "Thing" });
621+
for (const field of ["name", "sessionKey", "deliveryAccountId", "payloadModel"] as const) {
622+
const id = `cron-${field.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`)}`;
623+
const input = getElement(container, `#${id}`, HTMLInputElement);
624+
if (field === "sessionKey" || field === "deliveryAccountId") {
625+
expect(input.placeholder).toBe(field === "sessionKey" ? "agent:main:main" : "default");
626+
}
627+
input.value = field;
628+
input.dispatchEvent(new Event("input", { bubbles: true }));
629+
expect(onFormChange).toHaveBeenLastCalledWith({ [field]: field });
630+
}
631+
632+
const channel = getElement(container, "#cron-failure-alert-channel", HTMLSelectElement);
633+
channel.value = "telegram";
634+
expect(channel.selectedOptions[0]?.textContent).toBe("Telegram fallback");
635+
channel.dispatchEvent(new Event("change", { bubbles: true }));
636+
expect(onFormChange).toHaveBeenLastCalledWith({ failureAlertChannel: "telegram" });
618637
});
619638

620639
it("switches schedule inputs by segmented kind and wires kind changes", () => {

0 commit comments

Comments
 (0)