| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260 |
- import { readFileSync } from "node:fs";
- import { resolve } from "node:path";
- import { describe, expect, it } from "vitest";
- import {
- shouldResetLexicalEditorAfterSubmit,
- shouldSubmitLexicalEnter,
- shouldSubmitLexicalModifiedEnter,
- } from "@/LexicalChatInput.js";
- import {
- isPrimaryFollowupModifierPressed,
- resolveOppositeFollowupDelivery,
- resolveFollowupModifierTooltip,
- shouldEnableModifiedEnterSubmit,
- shouldReverseFollowupDeliveryForPointer,
- } from "@/v4/composer/followupModeSettings.js";
- import { cn } from "@/components/lib/utils.js";
- import {
- resolveChatEnterShortcut,
- resolveChatEnterSubmits,
- resolveMobileInputTextSizeClassName,
- shouldAvoidIosInputFocusZoom,
- } from "@/lib/mobileTextInput.js";
- function readSource(path: string) {
- return readFileSync(resolve(process.cwd(), path), "utf8");
- }
- describe("mobile text input zoom guard", () => {
- it("keeps modified submit on desktop drafts and Windows coarse-pointer viewports", () => {
- expect(
- shouldEnableModifiedEnterSubmit({
- inputRoutingMode: "startNow",
- isMobileTextInputViewport: true,
- isWebRemoteControl: false,
- }),
- ).toBe(true);
- expect(
- shouldEnableModifiedEnterSubmit({
- inputRoutingMode: "enqueue",
- isMobileTextInputViewport: true,
- isWebRemoteControl: false,
- }),
- ).toBe(true);
- expect(
- shouldEnableModifiedEnterSubmit({
- inputRoutingMode: "enqueue",
- isMobileTextInputViewport: true,
- isWebRemoteControl: true,
- }),
- ).toBe(false);
- expect(
- shouldEnableModifiedEnterSubmit({
- inputRoutingMode: "reject",
- isMobileTextInputViewport: false,
- isWebRemoteControl: false,
- }),
- ).toBe(false);
- });
- it("resolves Cmd/Ctrl+Enter as send-now for queue and queue for guide", () => {
- expect(resolveOppositeFollowupDelivery("queue")).toBe("startNow");
- expect(resolveOppositeFollowupDelivery("guide")).toBe("queue");
- const composerSource = readSource("packages/ui/src/v4/ConversationComposer.tsx");
- expect(composerSource).not.toContain('if (routingMode === "startNow")');
- expect(
- shouldSubmitLexicalModifiedEnter({
- ctrlKey: true,
- modifiedEnterSubmits: true,
- text: "opposite delivery",
- }),
- ).toBe(true);
- expect(
- shouldSubmitLexicalModifiedEnter({
- metaKey: true,
- modifiedEnterSubmits: true,
- text: "opposite delivery",
- }),
- ).toBe(true);
- expect(
- shouldSubmitLexicalModifiedEnter({
- ctrlKey: true,
- isComposing: true,
- modifiedEnterSubmits: true,
- text: "IME",
- }),
- ).toBe(false);
- expect(
- shouldSubmitLexicalModifiedEnter({
- ctrlKey: true,
- modifiedEnterSubmits: true,
- shiftKey: true,
- text: "keep newline",
- }),
- ).toBe(false);
- });
- it("only clears the Lexical editor when the submit callback accepts the clear", () => {
- expect(shouldResetLexicalEditorAfterSubmit()).toBe(true);
- expect(shouldResetLexicalEditorAfterSubmit(true)).toBe(true);
- expect(shouldResetLexicalEditorAfterSubmit(false)).toBe(false);
- });
- it("only reverses pointer delivery for an enabled desktop modifier click", () => {
- expect(
- shouldReverseFollowupDeliveryForPointer({ enabled: true, metaKey: true, ctrlKey: false }),
- ).toBe(true);
- expect(
- shouldReverseFollowupDeliveryForPointer({ enabled: true, metaKey: false, ctrlKey: true }),
- ).toBe(true);
- expect(
- shouldReverseFollowupDeliveryForPointer({ enabled: true, metaKey: false, ctrlKey: false }),
- ).toBe(false);
- expect(
- shouldReverseFollowupDeliveryForPointer({ enabled: false, metaKey: true, ctrlKey: false }),
- ).toBe(false);
- });
- it("resolves the automatic opposite-action tooltip with a platform shortcut", () => {
- expect(
- resolveFollowupModifierTooltip({
- enabled: true,
- canSend: true,
- modifierPressed: true,
- followupMode: "queue",
- isApplePlatform: true,
- }),
- ).toEqual({
- delivery: "startNow",
- shortcut: "⌘ + Enter",
- titleId: "chat.followup.sendNow",
- });
- expect(
- resolveFollowupModifierTooltip({
- enabled: true,
- canSend: true,
- modifierPressed: true,
- followupMode: "guide",
- isApplePlatform: false,
- }),
- ).toEqual({
- delivery: "queue",
- shortcut: "Ctrl + Enter",
- titleId: "chat.followup.addToQueue",
- });
- expect(
- resolveFollowupModifierTooltip({
- enabled: true,
- canSend: false,
- modifierPressed: true,
- followupMode: "queue",
- isApplePlatform: true,
- }),
- ).toBeNull();
- });
- it("tracks only the platform primary follow-up modifier", () => {
- expect(
- isPrimaryFollowupModifierPressed({ isApplePlatform: true, metaKey: true, ctrlKey: false }),
- ).toBe(true);
- expect(
- isPrimaryFollowupModifierPressed({ isApplePlatform: true, metaKey: false, ctrlKey: true }),
- ).toBe(false);
- expect(
- isPrimaryFollowupModifierPressed({ isApplePlatform: false, metaKey: false, ctrlKey: true }),
- ).toBe(true);
- expect(
- isPrimaryFollowupModifierPressed({ isApplePlatform: false, metaKey: true, ctrlKey: false }),
- ).toBe(false);
- });
- it("keeps Enter as newline for mobile web remote control only", () => {
- const mobileRemoteEnterSubmits = resolveChatEnterSubmits({
- isMobileTextInputViewport: true,
- preferEnterNewline: true,
- });
- expect(mobileRemoteEnterSubmits).toBe(false);
- expect(resolveChatEnterShortcut({ enterSubmits: mobileRemoteEnterSubmits })).toBeUndefined();
- expect(
- shouldSubmitLexicalEnter({
- enterSubmits: mobileRemoteEnterSubmits,
- text: "first line",
- }),
- ).toBe(false);
- expect(
- resolveChatEnterSubmits({
- isMobileTextInputViewport: false,
- preferEnterNewline: true,
- }),
- ).toBe(true);
- });
- it("keeps desktop and non-remote input typography unchanged", () => {
- expect(
- shouldAvoidIosInputFocusZoom({
- isMobileTextInputViewport: false,
- isWebRemoteControl: true,
- }),
- ).toBe(false);
- expect(
- shouldAvoidIosInputFocusZoom({
- isMobileTextInputViewport: true,
- isWebRemoteControl: false,
- }),
- ).toBe(false);
- expect(
- resolveMobileInputTextSizeClassName({
- avoidIosInputFocusZoom: false,
- }),
- ).toBe("text-ui-base leading-5");
- });
- it("uses a fixed 16px token for mobile remote input even with a 12px UI preference", () => {
- expect(
- shouldAvoidIosInputFocusZoom({
- isMobileTextInputViewport: true,
- isWebRemoteControl: true,
- }),
- ).toBe(true);
- const className = resolveMobileInputTextSizeClassName({
- avoidIosInputFocusZoom: true,
- });
- const stylesSource = readSource("packages/ui/src/styles.css");
- expect(className).toBe("text-mobile-input-safe leading-6");
- expect(cn("text-ui-base", className)).toBe("text-mobile-input-safe leading-6");
- expect(cn("text-ui-base", "text-ui-xl")).toBe("text-ui-xl");
- expect(cn("text-ui-base", "text-ui-caption")).toBe("text-ui-caption");
- expect(stylesSource).toContain("--text-mobile-input-safe: 16px;");
- expect(stylesSource).toContain("--text-ui-xl: calc(var(--ui-font-size) + 4px);");
- expect(stylesSource).toContain("--text-ui-lg: calc(var(--ui-font-size) + 2px);");
- });
- it("wires the zoom guard through remote composer inputs", () => {
- const composerSource = readSource("packages/ui/src/v4/ConversationComposer.tsx");
- const interactionDialogSource = readSource("packages/ui/src/v4/V4InteractionDialogs.tsx");
- const permissionDialogSource = readSource("packages/ui/src/PermissionDialog.tsx");
- const sessionPaneSource = readSource("packages/ui/src/v4/SessionPane.tsx");
- const promptEditorSource = readSource("packages/ui/src/prompt-editor/ChatPromptEditor.tsx");
- const lexicalInputSource = readSource("packages/ui/src/LexicalChatInput.tsx");
- expect(composerSource).toContain("shouldAvoidIosInputFocusZoom({");
- expect(composerSource).toContain("isWebRemoteControl,");
- expect(composerSource).toContain("isMobileTextInputViewport,");
- expect(composerSource).toContain("preferEnterNewline: isWebRemoteControl,");
- expect(composerSource).toContain("avoidIosInputFocusZoom={avoidIosInputFocusZoom}");
- expect(composerSource).toContain("compactPlaceholder={compactMobilePlaceholder}");
- expect(sessionPaneSource).toContain("isWebRemoteControl={compactForRemoteControl}");
- expect(interactionDialogSource).toContain("isWebRemoteControl={isWebRemoteControl}");
- expect(permissionDialogSource).toContain("useIsMobileTextInputViewport");
- expect(permissionDialogSource).toContain("resolveMobileInputTextSizeClassName({");
- expect(permissionDialogSource).toContain("avoidIosInputFocusZoom");
- expect(promptEditorSource).toContain("avoidIosInputFocusZoom={avoidIosInputFocusZoom}");
- expect(promptEditorSource).toContain("compactPlaceholder={compactPlaceholder}");
- expect(lexicalInputSource).toContain("resolveMobileInputTextSizeClassName({");
- expect(lexicalInputSource).toContain('compactPlaceholder ? "line-clamp-2" : ""');
- expect(lexicalInputSource).not.toContain("user-scalable=no");
- expect(lexicalInputSource).not.toContain("maximum-scale");
- });
- });
|