diff --git a/e2e/stashDialogLayout.spec.ts b/e2e/stashDialogLayout.spec.ts new file mode 100644 index 000000000..2d19f86f0 --- /dev/null +++ b/e2e/stashDialogLayout.spec.ts @@ -0,0 +1,60 @@ +import { expect, ipcCalls, stubDesktop, test } from "./fixtures"; + +test("Stash wraps the current branch and accepts a multiline message in a narrow window", async ({ + workbench: page, +}) => { + await page.setViewportSize({ width: 380, height: 590 }); + await stubDesktop(page); + const root = "/dev/settlement-engine"; + const head = "release/QuarterlyInternationalSettlementReconciliationAndAuthorizationForMerchantOperations"; + await page.evaluate( + async ({ root, head }) => { + const branch = { head, headCommit: "c1", upstream: null, ahead: 0, behind: 0, operation: null }; + const h = window.__ipc.handlers; + h.vcs_branch_info = () => branch; + h.vcs_roots = () => [{ root, ...branch }]; + h.vcs_status = () => []; + h.vcs_stashes = () => []; + h.vcs_stash_push = () => null; + const storeModule = "/src/features/vcs/store.ts"; + const { useVcs } = await import(/* @vite-ignore */ storeModule); + useVcs.setState({ available: true, root, repo: root, roots: [root], branch }); + const contextModule = "/src/platform/context.ts"; + const { setContext } = await import(/* @vite-ignore */ contextModule); + setContext("vcsAvailable", true); + const actionsModule = "/src/platform/actions.ts"; + const { executeAction } = await import(/* @vite-ignore */ actionsModule); + await executeAction("vcs.stash"); + }, + { root, head }, + ); + + const dialog = page.getByRole("dialog", { name: "Stash", exact: true }); + await expect(dialog.getByText(`Current branch: ${head}`)).toBeVisible(); + const body = dialog.locator("[data-dialog-body]"); + expect(await body.evaluate((el) => el.scrollWidth - el.clientWidth)).toBe(0); + const message = dialog.getByRole("textbox", { name: "Message", exact: true }); + await expect(message).toBeFocused(); + await message.fill("Set aside settlement work"); + await message.press("End"); + await message.press("Enter"); + await expect(message).toHaveValue("Set aside settlement work\n"); + await message.pressSequentially("Continue after the release."); + expect(await ipcCalls(page, "vcs_stash_push")).toEqual([]); + + await dialog.getByRole("checkbox", { name: "Keep index" }).check(); + await dialog.getByRole("checkbox", { name: "Include untracked files" }).check(); + await message.press("Control+Enter"); + await expect(dialog).toBeHidden(); + await expect + .poll(() => ipcCalls(page, "vcs_stash_push")) + .toEqual([ + { + repo: root, + message: "Set aside settlement work\nContinue after the release.", + keepIndex: true, + includeUntracked: true, + paths: null, + }, + ]); +}); diff --git a/src/features/vcs/changeOps.tsx b/src/features/vcs/changeOps.tsx index 5de446e29..d0fac830a 100644 --- a/src/features/vcs/changeOps.tsx +++ b/src/features/vcs/changeOps.tsx @@ -1,5 +1,5 @@ /** Local change operations: commit, rollback, add, stash. */ -import { useEffect, useState } from "react"; +import { useEffect, useId, useState } from "react"; import type { FileStatus, Stash } from "@/bindings"; import { call, commands } from "@/platform/ipc"; import { Checkbox, Dialog, Icon, IconButton, Input, T, fileIconName } from "@/ui"; @@ -367,7 +367,9 @@ function StashDialog({ const [message, setMessage] = useState(""); const [keepIndex, setKeepIndex] = useState(false); const [includeUntracked, setIncludeUntracked] = useState(false); + const showRepo = useVcs((s) => pickRepo && s.roots.length > 1); const branch = useBranchInfo(repo)?.head ?? null; + const messageId = useId(); const submit = () => onDone({ repo, message: message.trim(), keepIndex, includeUntracked }); return (
{ e.preventDefault(); submit(); }} > - {pickRepo && } - {branch &&
{tx`Current branch: ${branch}`}
} - - setMessage(e.target.value)} - /> - - + {showRepo && ( +
+ Repository: + +
+ )} + {branch &&
{tx`Current branch: ${branch}`}
} +
+ +