From 5d6738fbc64efccf38283d95b7805ae456b046b6 Mon Sep 17 00:00:00 2001 From: riyadhafraa <49757212-riyadhafraa@users.noreply.replit.com> Date: Wed, 29 Apr 2026 18:25:00 +0000 Subject: [PATCH] Add test to ensure turning off edit mode cancels inline editors Adds a new test case to `executive-meetings-edit-toggle.spec.mjs` that verifies turning off the edit mode toggle correctly cancels any open inline editor and discards unsaved draft changes. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 77cfe984-2c65-4152-bb7a-0df28274fe66 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Event-Id: ecc0f121-1bcf-46f5-a729-28d8af363bab Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/c3c252e4-c83d-40ca-9fff-99a3ea60701e/77cfe984-2c65-4152-bb7a-0df28274fe66/m6nH0ju Replit-Helium-Checkpoint-Created: true --- .../executive-meetings-edit-toggle.spec.mjs | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/artifacts/tx-os/tests/executive-meetings-edit-toggle.spec.mjs b/artifacts/tx-os/tests/executive-meetings-edit-toggle.spec.mjs index 94d6bf3b..9e220936 100644 --- a/artifacts/tx-os/tests/executive-meetings-edit-toggle.spec.mjs +++ b/artifacts/tx-os/tests/executive-meetings-edit-toggle.spec.mjs @@ -79,3 +79,70 @@ test("Schedule: Edit toggle hides editing affordances by default and reveals the await expect(toggleAfterReload).toHaveAttribute("aria-pressed", "false"); await expect(page.getByTestId("em-add-row-button")).toHaveCount(0); }); + +test("Schedule: turning edit mode OFF cancels any open inline editor and discards the draft", async ({ + page, +}) => { + await page.addInitScript(() => { + try { + window.localStorage.setItem("tx-lang", "en"); + } catch { + /* ignore */ + } + }); + + await loginViaUi(page, "admin", "admin123"); + await page.goto("/executive-meetings"); + // Start clean (view mode), then flip edit mode on. + await page.evaluate(() => { + try { + const keys = Object.keys(window.localStorage); + for (const k of keys) { + if (k.startsWith("em-schedule-edit-mode-v1")) { + window.localStorage.removeItem(k); + } + } + } catch { + /* ignore */ + } + }); + await page.reload(); + + const toggle = page.getByTestId("em-edit-mode-toggle"); + await expect(toggle).toBeVisible(); + await toggle.click(); + await expect(toggle).toHaveAttribute("aria-pressed", "true"); + + // Make sure there's at least one row to edit. If the schedule is + // empty for today, add a row via the now-visible "+ Add meeting" + // button so the test has a stable target. + const addRow = page.getByTestId("em-add-row-button"); + await expect(addRow).toBeVisible(); + let titleCells = page.locator('[data-testid^="em-edit-title-"]'); + if ((await titleCells.count()) === 0) { + await addRow.click(); + await expect(titleCells.first()).toBeVisible({ timeout: 5_000 }); + } + + // Open the first inline title editor and type a draft we expect + // to be discarded. + const firstTitle = titleCells.first(); + const originalText = (await firstTitle.innerText()).trim(); + await firstTitle.click(); + // The editor renders a contenteditable inside the cell. Type a + // unique draft so we can later assert it never landed. + const draft = "DRAFT-DO-NOT-PERSIST-" + Date.now(); + await page.keyboard.type(draft); + + // Now flip edit mode OFF while the editor is still open. The + // EditableCell `disabled` effect should exit edit mode and reset + // the displayed content back to its saved value. + await toggle.click(); + await expect(toggle).toHaveAttribute("aria-pressed", "false"); + + // The displayed cell should NOT contain our draft text — i.e. the + // open editor was cancelled and the unsaved draft was discarded. + const afterText = (await firstTitle.innerText()).trim(); + expect(afterText).not.toContain(draft); + expect(afterText).toBe(originalText); +});