From 6fe3625fae0b68733ca9937715bf05dd76fe4dfd Mon Sep 17 00:00:00 2001 From: Jason Woltje Date: Mon, 16 Nov 2026 12:07:50 -0600 Subject: [PATCH] fix(webui): sp17 review 2, a new step typed in the add form is not dropped by Save: the bar's Save with a typed new step says it is not added yet, keeps the form and puts the caret in its title, and an add form with nothing typed is closed and the rest saved; test types a new step and presses the bar's Save, sees the words and no write, then adds the step and sees all three in the write (red before: Save wrote without the new step and said Saved); the pack apply test waits for the autonomy read as well as the workflows read, as it answered later on a loaded host (#1873, lane sp17-workflow-clicks) --- packages/webui/src/public/workflows.js | 10 +++++++++ .../tests/org-live-edit-browser.test.mjs | 3 ++- .../webui/tests/workflows-browser.test.mjs | 22 +++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/packages/webui/src/public/workflows.js b/packages/webui/src/public/workflows.js index 5ecfb3f3a..2447e3240 100644 --- a/packages/webui/src/public/workflows.js +++ b/packages/webui/src/public/workflows.js @@ -547,6 +547,7 @@ // dropped when the answer redraws the form. Drawn off when busy; a held form (data-live-hold) is set here. const lockForms = off => document.querySelectorAll('#bus-view [data-wfg-page] :is([data-wfg-step-form],[data-wfg-meta-form])').forEach(f => f.querySelectorAll('input[name="title"],textarea,select,[data-wfg-roles-pick]').forEach(c => { c.disabled = off; })); + const toAddTitle = () => document.querySelector('#bus-view [data-wfg-page] [data-wfg-add-form] input[name="title"]')?.focus(); // Put focus back in the step form's title after a refusal (the form may be a held node). const toTitle = () => { const f = stepFormEl()?.elements.title; if (f) { f.focus(); f.setSelectionRange(f.value.length, f.value.length); } }; @@ -618,6 +619,15 @@ async function save({ org, name, scope, s, key }) { const d = drafts.get(key); if (!d || d.busy) return; + // SP17 review: a new step typed in the add form is not saved over or dropped: Save says so and keeps the + // form. An add form with nothing typed in it is closed and the rest is saved. + if (d.edit?.mode === 'add') { + if (d.edit.title.trim() || d.edit.roles.length) { + d.atBar = false; d.status = `Not saved: new step ${d.edit.i + 1} is not added yet. Press Add step, or Cancel to drop it.`; + say(d.status); paint(); return toAddTitle(); + } + d.edit = null; + } // SP17: the open step's edit goes in with the save; one the save check refuses stays in its form. const unfit = carry(d); d.atBar = false; diff --git a/packages/webui/tests/org-live-edit-browser.test.mjs b/packages/webui/tests/org-live-edit-browser.test.mjs index 3aa8b862e..eb9728467 100644 --- a/packages/webui/tests/org-live-edit-browser.test.mjs +++ b/packages/webui/tests/org-live-edit-browser.test.mjs @@ -124,7 +124,8 @@ test('E2E6 P2-2: a pack apply re-reads the other sections and keeps its receipt' const before = { ...counts }; await b.evaluate(`document.querySelector('[data-pack-apply]').click();true`); await waitFor(b, `/^Applied\\./.test(document.querySelector('[data-packs-status]')?.textContent??'')`, 'apply'); - for (let i = 0; i < 300 && counts.workflows === before.workflows; i++) await new Promise(r => setTimeout(r, 30)); + // Both reads are waited for: the autonomy read can answer after the workflows read on a loaded host. + for (let i = 0; i < 300 && (counts.workflows === before.workflows || counts.autonomy === before.autonomy); i++) await new Promise(r => setTimeout(r, 30)); assert.ok(counts.workflows > before.workflows, 'workflows read again after the apply'); assert.ok(counts.autonomy > before.autonomy, 'autonomy read again after the apply'); await b.evaluate(`new Promise(r=>setTimeout(()=>r(true),300))`); diff --git a/packages/webui/tests/workflows-browser.test.mjs b/packages/webui/tests/workflows-browser.test.mjs index 7ad61b925..2af600dda 100644 --- a/packages/webui/tests/workflows-browser.test.mjs +++ b/packages/webui/tests/workflows-browser.test.mjs @@ -975,3 +975,25 @@ test('SP17: while a Save is in flight the form takes no typing, and takes it aga assert.deepEqual(await b.evaluate(fields), [false, false, false], 'on again after a refusal'); assert.equal(await b.evaluate(`document.querySelector('${form} input[name="title"]').value`), 'Ship again'); }); + +// SP17 review 2 P2-1: a new step typed in the add form is not dropped by the bar's Save: Save says it is not +// added yet and keeps the form; once added, Save sends it. +test('SP17: the bar Save with a new step typed in the add form says so and keeps it, and saves it once added', { timeout: 60000 }, async t => { + const { b, wait, st } = await setup(t, { path: '#/orgs/acme/workflows/change?project=site&step=1' }); + await retitle(b, wait, 1, 'Build it'); + await b.evaluate(press('[data-wfg-add]')); + await wait(`!!document.querySelector('[data-wfg-add-form]')`, 'add form'); + await b.evaluate(fill('[data-wfg-add-form] input[name="title"]', 'Check')); + await b.evaluate(`document.querySelector('[data-wfg-add-form] input[name="role"][value="human"]').click();true`); + await b.evaluate(press('[data-wfg-bar] [data-wfg-save]')); + await wait(`/new step 2 is not added yet/.test(${text('[data-wfg-bar] [data-wfg-status]')})`, 'refused in words'); + assert.equal(st.writes.length, 0, 'nothing written'); + assert.equal(await b.evaluate(`document.querySelector('[data-wfg-add-form] input[name="title"]')?.value`), 'Check', 'the typed step is kept'); + assert.equal(await b.evaluate(`document.activeElement === document.querySelector('[data-wfg-add-form] input[name="title"]')`), true, 'focus in the new step'); + assert.equal(await b.evaluate(`window.MosaicWorkflows.hasDraft()`), true); + await b.evaluate(press('[data-wfg-add-step]')); + await wait(`${titles}.length === 3`, 'step added'); + await b.evaluate(press('[data-wfg-save]')); + await wait(`/Saved change\\./.test(${text('[data-wfg-status]')})`, 'saved'); + assert.deepEqual(st.writes.at(-1).args.workflow.steps.map(s => [s.title, s.roles]), [['Build it', ['coder']], ['Check', ['human']], ['Ship', ['human']]]); +});