diff --git a/apps/mobile/src/features/threads/ThreadGitControls.logic.test.ts b/apps/mobile/src/features/threads/ThreadGitControls.logic.test.ts new file mode 100644 index 0000000000000..1538540949880 --- /dev/null +++ b/apps/mobile/src/features/threads/ThreadGitControls.logic.test.ts @@ -0,0 +1,9 @@ +import { expect, it } from "vite-plus/test"; + +import { compactMenuBranchLabel } from "./ThreadGitControls.logic"; + +it("keeps emoji whole at both cuts of a long branch name", () => { + expect(compactMenuBranchLabel("feature/abc😀-long-branch-name-😀-for-menus")).toBe( + "feature/abc…-for-menus", + ); +}); diff --git a/apps/mobile/src/features/threads/ThreadGitControls.logic.ts b/apps/mobile/src/features/threads/ThreadGitControls.logic.ts new file mode 100644 index 0000000000000..a3441835b5951 --- /dev/null +++ b/apps/mobile/src/features/threads/ThreadGitControls.logic.ts @@ -0,0 +1,17 @@ +import { splitsSurrogatePair } from "@t3tools/shared/assistantCitations"; + +function truncateMiddle(value: string, maxLength: number): string { + if (value.length <= maxLength) { + return value; + } + + const headLength = Math.ceil((maxLength - 1) / 2); + const tailStart = value.length - Math.floor((maxLength - 1) / 2); + const headEnd = splitsSurrogatePair(value, headLength) ? headLength - 1 : headLength; + const tailFrom = splitsSurrogatePair(value, tailStart) ? tailStart + 1 : tailStart; + return `${value.slice(0, headEnd)}…${value.slice(tailFrom)}`; +} + +export function compactMenuBranchLabel(branch: string): string { + return truncateMiddle(branch, 24); +} diff --git a/apps/mobile/src/features/threads/ThreadGitControls.tsx b/apps/mobile/src/features/threads/ThreadGitControls.tsx index 5e67fb0181ad5..880303b857fbc 100644 --- a/apps/mobile/src/features/threads/ThreadGitControls.tsx +++ b/apps/mobile/src/features/threads/ThreadGitControls.tsx @@ -30,20 +30,7 @@ import { type TerminalMenuSession, } from "../terminal/terminalMenu"; import { projectScriptMenuLabel } from "@t3tools/shared/projectScriptsCopy"; - -function truncateMiddle(value: string, maxLength: number): string { - if (value.length <= maxLength) { - return value; - } - - const headLength = Math.ceil((maxLength - 1) / 2); - const tailLength = Math.floor((maxLength - 1) / 2); - return `${value.slice(0, headLength)}…${value.slice(value.length - tailLength)}`; -} - -function compactMenuBranchLabel(branch: string): string { - return truncateMiddle(branch, 24); -} +import { compactMenuBranchLabel } from "./ThreadGitControls.logic"; function compactMenuStatus(gitStatus: VcsStatusResult | null, resolve: MessageResolver): string { if (!gitStatus) { diff --git a/scripts/scenarios/git-menu-branch-keeps-whole-characters.e2e.ts b/scripts/scenarios/git-menu-branch-keeps-whole-characters.e2e.ts new file mode 100644 index 0000000000000..088b9b00838c2 --- /dev/null +++ b/scripts/scenarios/git-menu-branch-keeps-whole-characters.e2e.ts @@ -0,0 +1,28 @@ +import { expect } from "e2e"; + +import { run } from "./shell.ts"; +import { runPromise } from "./t3.ts"; +import { IOS, test } from "./t3-mobile.ts"; + +// The Git menu shows 12 units, "…" and the last 11; each emoji straddles one cut. +const BRANCH = "feature/abc😀-long-branch-name-😀-for-menus"; + +test( + "The Git menu's branch title keeps whole characters at both cuts", + IOS, + async ({ t3, app, screen }) => { + const project = await t3.project("demo"); + await runPromise(run("git", ["checkout", "--quiet", "-b", BRANCH], { cwd: project })); + await t3.thread({ project, title: "Branch work", messages: ["first"] }); + // A local simulator keeps the last run's pairing. + await app.clearState().catch(() => {}); + await t3.open(); + + await screen.getByText("Branch work", { exact: false }).first().tap({ timeout: 120_000 }); + await screen.getByRole("button", "Git controls").tap({ timeout: 60_000 }); + const title = screen.getByText("feature/abc", { exact: false }).first(); + await title.waitFor({ timeout: 30_000 }); + await app.screenshot("git-menu"); + await expect(title).toHaveText("feature/abc…-for-menus, Clean"); + }, +);