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.
This commit is contained in:
Riyadh
2026-04-29 18:25:00 +00:00
parent 3dd732b3d8
commit 69f7dfb2fc
@@ -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);
});