diff --git a/src/features/settings/__tests__/runTargetsSwitchDraft.test.tsx b/src/features/settings/__tests__/runTargetsSwitchDraft.test.tsx index 7dd05b203b..7ce3eed51d 100644 --- a/src/features/settings/__tests__/runTargetsSwitchDraft.test.tsx +++ b/src/features/settings/__tests__/runTargetsSwitchDraft.test.tsx @@ -43,17 +43,26 @@ afterEach(() => { }); describe("Run Targets detail form", () => { - it("does not commit an uncommitted ports edit to the target selected while it is open", () => { + it("keeps a ports edit with the target it was made to when another target is selected", () => { mount(); - // An edit to odoo110's published ports that ListField has not committed yet. + // An edit to odoo110's published ports, still focused. fireEvent.change(portsBox(), { target: { value: "8069" } }); - // Selecting another target switches selection on mousedown, before the blur commits. + // Selecting another target switches selection on mousedown, before the field loses focus. fireEvent.mouseDown(screen.getByRole("option", { name: /odoo170/ })); fireEvent.blur(portsBox()); - // odoo170 keeps its own ports; the uncommitted draft is not written over them. + // odoo170 keeps its own ports; the edit is not written over them. expect(portsBox().value).toBe("9000:9000"); - // And odoo110 still holds what it held before the edit was committed anywhere. + // And odoo110 holds the edit. fireEvent.mouseDown(screen.getByRole("option", { name: /odoo110/ })); - expect(portsBox().value).toBe("8069:8069"); + expect(portsBox().value).toBe("8069"); + }); + + it("stages a ports edit before the field loses focus, so OK applies it", () => { + mount(); + fireEvent.change(portsBox(), { target: { value: "8069:8069 8070:8070" } }); + expect(portsBox().value).toBe("8069:8069 8070:8070"); + const change = Object.values(useSettingsDialog.getState().staged).find((c) => c.key === "runTargets"); + const targets = change?.value as Array<{ id: string; ports: string[] }> | undefined; + expect(targets?.find((t) => t.id === "odoo110")?.ports).toEqual(["8069:8069", "8070:8070"]); }); }); diff --git a/src/features/settings/pages/RunTargetsBody.tsx b/src/features/settings/pages/RunTargetsBody.tsx index ae88bfc93a..dc2e31c26c 100644 --- a/src/features/settings/pages/RunTargetsBody.tsx +++ b/src/features/settings/pages/RunTargetsBody.tsx @@ -263,7 +263,8 @@ function ListField({ hint?: string; }) { const id = useId(); - // Edited as text; the list is stored once the field loses focus. + // Edited as text, which stays as typed while the field has focus; the list is stored on every change, so OK + // (Enter included) applies an edit that hasn't left the field. const [draft, setDraft] = useState(null); return ( @@ -273,11 +274,11 @@ function ListField({ className={styles.wide} value={draft ?? value.join(" ")} placeholder={placeholder} - onChange={(e) => setDraft(e.target.value)} - onBlur={() => { - if (draft !== null) onChange(splitList(draft)); - setDraft(null); + onChange={(e) => { + setDraft(e.target.value); + onChange(splitList(e.target.value)); }} + onBlur={() => setDraft(null)} /> );