From 7cc4712e2c9998e2f3aadc99a2b2c293aab85080 Mon Sep 17 00:00:00 2001 From: Wout Stiens <71498452+StiensWout@users.noreply.github.com> Date: Sun, 22 Nov 2026 18:41:30 +0100 Subject: [PATCH 1/7] test(mobile): cover web links in read-only chats Co-authored-by: GPT 6.2 Sol --- .../threads/LinkedThreadSheet.test.tsx | 133 ++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 apps/mobile/src/features/threads/LinkedThreadSheet.test.tsx diff --git a/apps/mobile/src/features/threads/LinkedThreadSheet.test.tsx b/apps/mobile/src/features/threads/LinkedThreadSheet.test.tsx new file mode 100644 index 0000000000000..f5e52a05cb7b1 --- /dev/null +++ b/apps/mobile/src/features/threads/LinkedThreadSheet.test.tsx @@ -0,0 +1,133 @@ +import { MessageId, type OrchestrationV2ProjectedTurnItem } from "@t3tools/contracts"; +import type { ReactNode } from "react"; +import { renderToStaticMarkup } from "react-dom/server"; +import { expect, it, vi } from "vite-plus/test"; +import { + v2MessageRow, + v2Projection, +} from "../../../../../packages/client-runtime/src/state/orchestrationV2TestFixtures"; + +const { openURL, readThread, links } = vi.hoisted(() => ({ + openURL: vi.fn(async (_url: string) => {}), + readThread: vi.fn(), + links: new Map void>(), +})); + +vi.mock("react", async (importOriginal) => { + const react = await importOriginal(); + return { + ...react, + useSyncExternalStore: ((subscribe, getSnapshot, getServerSnapshot = getSnapshot) => + react.useSyncExternalStore( + subscribe, + getSnapshot, + getServerSnapshot, + )) satisfies typeof react.useSyncExternalStore, + }; +}); + +vi.mock("react-native", () => ({ + AppState: { currentState: "active", addEventListener: () => ({ remove() {} }) }, + Linking: { openURL }, + ScrollView: ({ children }: { children: ReactNode }) =>
{children}
, + View: ({ children }: { children: ReactNode }) =>
{children}
, +})); +vi.mock("@react-navigation/native", () => ({ + useIsFocused: () => true, + useNavigation: () => ({}), +})); +vi.mock("react-native-safe-area-context", () => ({ useSafeAreaInsets: () => ({ bottom: 0 }) })); +vi.mock("../../components/ui/AppActivityIndicator", () => ({ AppActivityIndicator: () => null })); +vi.mock("../../components/ui/AppText", () => ({ + AppText: ({ children }: { children: ReactNode }) => {children}, +})); +vi.mock("../../components/ui/Button", () => ({ Button: () => null })); +vi.mock("../../components/ui/ScreenContent", () => ({ + ScreenContent: ({ children }: { children: ReactNode }) =>
{children}
, +})); +vi.mock("./ReadOnlyComposerBar", () => ({ ReadOnlyComposerBar: () => null })); +vi.mock("./thread-inspector-header", () => ({ ThreadInspectorHeader: () => null })); +vi.mock("../files/FileMarkdownPreview", () => ({ + useMarkdownPreviewStyles: () => ({ nativeTextStyle: {} }), +})); +vi.mock("../../state/environments", () => ({ useEnvironments: () => ({ environments: [] }) })); +vi.mock("../../state/linkedThread", () => ({ + useLinkedThreadView: readThread, + useConnectLinkedEnvironment: () => ({ state: { phase: "idle" } }), +})); +vi.mock("../../state/peerLinks", () => ({})); +vi.mock("../../state/query", () => ({})); +vi.mock("./useOpenLinkedThread", () => ({ useOpenLinkedThread: () => () => {} })); + +vi.mock("../../native/SelectableMarkdownText", () => ({ + SelectableMarkdownText: ({ + markdown, + onLinkPress, + }: { + markdown: string; + onLinkPress?: (href: string) => void; + }) => { + for (const [, label, href] of markdown.matchAll(/\[([^\]]+)\]\(([^)]*)\)/g)) { + if (label) links.set(label, () => onLinkPress?.(href ?? "")); + } + return null; + }, +})); + +import { LinkedThreadSheet } from "./LinkedThreadSheet"; + +it("opens web links from read-only agent messages through the system browser", () => { + const reply = v2MessageRow("reply", 0); + const sent = v2MessageRow("sent", 1); + const visibleTurnItems: OrchestrationV2ProjectedTurnItem[] = [ + { + ...reply, + item: { + ...reply.item, + type: "assistant_message", + messageId: MessageId.make("assistant-reply"), + text: "[Example](https://example.com/) [Docs](docs/readme.md) [Other](t3-thread://v2/env/thread) [Empty]()", + streaming: false, + }, + }, + { + ...sent, + position: 1, + item: { + ...sent.item, + type: "dynamic_tool", + toolName: "send_to_user", + input: {}, + output: { sentMessage: "[Reference](http://example.org/) [Guide](//example.net/guide)" }, + }, + }, + ]; + readThread.mockReturnValue({ + view: { + thread: { projection: { ...v2Projection, visibleTurnItems }, historyCursor: null }, + }, + error: null, + }); + openURL.mockClear(); + links.clear(); + + renderToStaticMarkup( + , + ); + expect([...links.keys()]).toEqual(["Example", "Docs", "Other", "Empty", "Reference", "Guide"]); + for (const press of links.values()) press(); + expect(openURL.mock.calls).toEqual([ + ["https://example.com/"], + ["http://example.org/"], + ["https://example.net/guide"], + ]); +}); From cab9243fff32b3fa0da1cae0e4da6fcfbfa2e665 Mon Sep 17 00:00:00 2001 From: Wout Stiens <71498452+StiensWout@users.noreply.github.com> Date: Sun, 22 Nov 2026 18:42:15 +0100 Subject: [PATCH 2/7] fix(mobile): open web links from read-only chats Co-authored-by: GPT 6.2 Sol --- .../features/threads/LinkedThreadSheet.tsx | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/apps/mobile/src/features/threads/LinkedThreadSheet.tsx b/apps/mobile/src/features/threads/LinkedThreadSheet.tsx index 0096c9d576a91..bd9325873f823 100644 --- a/apps/mobile/src/features/threads/LinkedThreadSheet.tsx +++ b/apps/mobile/src/features/threads/LinkedThreadSheet.tsx @@ -26,6 +26,8 @@ import { AppActivityIndicator } from "../../components/ui/AppActivityIndicator"; import { AppText as Text } from "../../components/ui/AppText"; import { Button } from "../../components/ui/Button"; import { ScreenContent } from "../../components/ui/ScreenContent"; +import { resolveMarkdownLinkPresentation } from "../../lib/markdownLinks"; +import { tryOpenExternalUrl } from "../../lib/openExternalUrl"; import { SelectableMarkdownText } from "../../native/SelectableMarkdownText"; import { useEnvironments } from "../../state/environments"; import { @@ -44,6 +46,11 @@ import { ReadOnlyComposerBar } from "./ReadOnlyComposerBar"; import { ThreadInspectorHeader, type ThreadInspectorPresentation } from "./thread-inspector-header"; import { useOpenLinkedThread } from "./useOpenLinkedThread"; +function openWebLink(href: string) { + const link = resolveMarkdownLinkPresentation(href); + if (link.kind === "external") void tryOpenExternalUrl(link.href, "markdown-link"); +} + function ActivityRow(props: { readonly activity: ThreadFeedActivity; readonly target: LinkedThreadTarget; @@ -163,7 +170,13 @@ function LinkedThreadEntry(props: { } // A message the agent sent with a tool reads as its own words, as on the thread screen. if (entry.type === "sent-message") { - return ; + return ( + + ); } if (entry.type !== "message" || entry.message.text.trim() === "") return null; return entry.message.role === "user" ? ( @@ -173,7 +186,11 @@ function LinkedThreadEntry(props: { ) : ( - + ); } From ff2d8ad55dfd4b5782911e160747e0cda7e0d485 Mon Sep 17 00:00:00 2001 From: Wout Stiens <71498452+StiensWout@users.noreply.github.com> Date: Sun, 22 Nov 2026 18:43:36 +0100 Subject: [PATCH 3/7] test(mobile): narrow the linked chat fixtures to message items Co-authored-by: GPT 6.2 Sol --- apps/mobile/src/features/threads/LinkedThreadSheet.test.tsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/apps/mobile/src/features/threads/LinkedThreadSheet.test.tsx b/apps/mobile/src/features/threads/LinkedThreadSheet.test.tsx index f5e52a05cb7b1..70bed6ca04da3 100644 --- a/apps/mobile/src/features/threads/LinkedThreadSheet.test.tsx +++ b/apps/mobile/src/features/threads/LinkedThreadSheet.test.tsx @@ -79,6 +79,9 @@ import { LinkedThreadSheet } from "./LinkedThreadSheet"; it("opens web links from read-only agent messages through the system browser", () => { const reply = v2MessageRow("reply", 0); const sent = v2MessageRow("sent", 1); + if (reply.item.type !== "user_message" || sent.item.type !== "user_message") { + throw new Error("Expected message fixtures"); + } const visibleTurnItems: OrchestrationV2ProjectedTurnItem[] = [ { ...reply, From b3f2b41f2c214af7daf708cbf0670b1d825770b4 Mon Sep 17 00:00:00 2001 From: Wout Stiens <71498452+StiensWout@users.noreply.github.com> Date: Sun, 22 Nov 2026 18:54:16 +0100 Subject: [PATCH 4/7] fix(mobile): hide Open link for unsupported linked chat destinations Co-authored-by: GPT 6.2 Sol --- .../features/threads/LinkedThreadSheet.tsx | 6 ++ .../src/native/EnrichedMarkdownText.test.tsx | 85 +++++++++++++++++++ .../src/native/EnrichedMarkdownText.tsx | 30 +++---- .../native/SelectableMarkdownText.types.ts | 1 + apps/mobile/vite.config.ts | 1 + 5 files changed, 106 insertions(+), 17 deletions(-) create mode 100644 apps/mobile/src/native/EnrichedMarkdownText.test.tsx diff --git a/apps/mobile/src/features/threads/LinkedThreadSheet.tsx b/apps/mobile/src/features/threads/LinkedThreadSheet.tsx index bd9325873f823..cc345f60d77bb 100644 --- a/apps/mobile/src/features/threads/LinkedThreadSheet.tsx +++ b/apps/mobile/src/features/threads/LinkedThreadSheet.tsx @@ -51,6 +51,10 @@ function openWebLink(href: string) { if (link.kind === "external") void tryOpenExternalUrl(link.href, "markdown-link"); } +function canOpenWebLink(href: string) { + return resolveMarkdownLinkPresentation(href).kind === "external"; +} + function ActivityRow(props: { readonly activity: ThreadFeedActivity; readonly target: LinkedThreadTarget; @@ -175,6 +179,7 @@ function LinkedThreadEntry(props: { markdown={entry.text} textStyle={styles.nativeTextStyle} onLinkPress={openWebLink} + canOpenLinkFromMenu={canOpenWebLink} /> ); } @@ -190,6 +195,7 @@ function LinkedThreadEntry(props: { markdown={entry.message.text} textStyle={styles.nativeTextStyle} onLinkPress={openWebLink} + canOpenLinkFromMenu={canOpenWebLink} /> ); } diff --git a/apps/mobile/src/native/EnrichedMarkdownText.test.tsx b/apps/mobile/src/native/EnrichedMarkdownText.test.tsx new file mode 100644 index 0000000000000..5ed52e2464d91 --- /dev/null +++ b/apps/mobile/src/native/EnrichedMarkdownText.test.tsx @@ -0,0 +1,85 @@ +import { act, type ComponentProps, type PropsWithChildren } from "react"; +import { createRoot } from "react-dom/client"; +import type { EnrichedMarkdownText } from "react-native-enriched-markdown"; +import { expect, it, vi } from "vite-plus/test"; + +type WidgetProps = ComponentProps; + +const widget = vi.hoisted(() => vi.fn<(_props: WidgetProps) => null>(() => null)); + +vi.mock("react-native", () => ({ + Platform: { OS: "ios" }, + StyleSheet: { hairlineWidth: 1 }, + useWindowDimensions: () => ({ fontScale: 1 }), + View: ({ children }: PropsWithChildren) => children, +})); +vi.mock("react-native-enriched-markdown", () => ({ EnrichedMarkdownText: widget })); +vi.mock("../components/ui/Menu", () => ({ Menu: () => null })); +vi.mock("../features/settings/appearance/AppearancePreferencesProvider", () => ({ + useAppearancePreferences: () => ({ themeAppearance: "dark", mathRenderingEnabled: false }), +})); +vi.mock("./HighlightedCodeBlock", () => ({ HighlightedCodeBlock: () => null })); +vi.mock("./MermaidCodeBlock", () => ({ MermaidCodeBlock: () => null })); +vi.mock("./useEnrichedLinkVariants", () => ({ useEnrichedLinkVariants: () => ({}) })); +vi.mock("../lib/copyTextWithHaptic", () => ({ copyTextWithHaptic: vi.fn() })); + +import { MobileEnrichedMarkdownText } from "./EnrichedMarkdownText"; + +it("offers Open link only for destinations the host can open", async () => { + vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true); + widget.mockClear(); + const root = createRoot(document.createElement("div")); + const webUrl = "https://example.com/"; + const fileUrl = "docs/readme.md"; + const markdown = `[Example](${webUrl}) [Docs](${fileUrl})`; + const onLinkPress = vi.fn(); + const textStyle = { + color: "#fff", + strongColor: "#fff", + mutedColor: "#aaa", + linkColor: "#fff", + inlineCodeColor: "#fff", + codeColor: "#fff", + codeBackgroundColor: "#000", + codeBlockBackgroundColor: "#000", + fileTextColor: "#fff", + quoteMarkerColor: "#aaa", + dividerColor: "#aaa", + fontSize: 14, + lineHeight: 20, + fontFamily: "System", + headingFontFamily: "System", + boldFontFamily: "System", + }; + + try { + await act(() => + root.render( + url === webUrl} + />, + ), + ); + await act(() => + widget.mock.lastCall?.[0].onLinksChange?.([ + { url: webUrl, label: "Example", title: "" }, + { url: fileUrl, label: "Docs", title: "" }, + ]), + ); + + const menus = Object.entries(widget.mock.lastCall?.[0].linkContextMenuItems ?? {}); + const menuFor = (url: string) => menus.find(([pattern]) => new RegExp(pattern).test(url))?.[1]; + + expect(menuFor(fileUrl)?.map(({ text }) => text)).toEqual(["Copy link", "Share link"]); + const webMenu = menuFor(webUrl); + expect(webMenu?.map(({ text }) => text)).toEqual(["Open link", "Copy link", "Share link"]); + webMenu?.find(({ text }) => text === "Open link")?.onPress({ url: webUrl }); + expect(onLinkPress).toHaveBeenCalledExactlyOnceWith(webUrl); + } finally { + await act(() => root.unmount()); + vi.unstubAllGlobals(); + } +}); diff --git a/apps/mobile/src/native/EnrichedMarkdownText.tsx b/apps/mobile/src/native/EnrichedMarkdownText.tsx index ff542959413ec..71b89c11d0b2a 100644 --- a/apps/mobile/src/native/EnrichedMarkdownText.tsx +++ b/apps/mobile/src/native/EnrichedMarkdownText.tsx @@ -346,19 +346,21 @@ export function MobileEnrichedMarkdownText(props: SelectableMarkdownTextProps) { else if (actionId === "enriched-share-link") void Share.share({ message: url }); else onFileContextMenuAction?.(url, actionId); }; + const defaultLinkMenu = (url: string) => ({ + title: url, + actions: [ + ...(props.canOpenLinkFromMenu?.(url) === false + ? [] + : [{ id: "enriched-open-link", title: gt("Open link") }]), + { id: "enriched-copy-link", title: gt("Copy link") }, + ...(Platform.OS === "ios" ? [{ id: "enriched-share-link", title: gt("Share link") }] : []), + ], + }); const linkContextMenuItems = Platform.OS === "ios" && (fileContextMenu || props.onLinkPress || props.onImagePress) ? Object.fromEntries( linkUrls.map((url) => { - const menu = modelContextMenu(url) ?? - fileContextMenu?.(url) ?? { - title: url, - actions: [ - { id: "enriched-open-link", title: gt("Open link") }, - { id: "enriched-copy-link", title: gt("Copy link") }, - { id: "enriched-share-link", title: gt("Share link") }, - ], - }; + const menu = modelContextMenu(url) ?? fileContextMenu?.(url) ?? defaultLinkMenu(url); return [ enrichedLinkVariantPattern(url), menu.actions.map((action) => ({ @@ -438,14 +440,8 @@ export function MobileEnrichedMarkdownText(props: SelectableMarkdownTextProps) { const onLinkLongPress = Platform.OS === "android" && props.fileContextMenu ? ({ url }: { url: string }) => { - const menu = modelContextMenu(url) ?? - props.fileContextMenu?.(url) ?? { - title: url, - actions: [ - { id: "enriched-open-link", title: gt("Open link") }, - { id: "enriched-copy-link", title: gt("Copy link") }, - ], - }; + const menu = + modelContextMenu(url) ?? props.fileContextMenu?.(url) ?? defaultLinkMenu(url); setActiveMenu({ url, menu }); openAndroidMenu?.(); } diff --git a/apps/mobile/src/native/SelectableMarkdownText.types.ts b/apps/mobile/src/native/SelectableMarkdownText.types.ts index 95b9545122b97..13ed9f6685815 100644 --- a/apps/mobile/src/native/SelectableMarkdownText.types.ts +++ b/apps/mobile/src/native/SelectableMarkdownText.types.ts @@ -77,6 +77,7 @@ export interface SelectableMarkdownTextProps { readonly models?: ReadonlyArray; readonly preserveSoftBreaks?: boolean; readonly onLinkPress?: (href: string) => void; + readonly canOpenLinkFromMenu?: (href: string) => boolean; readonly onCiteText?: (text: string) => void; readonly fileContextMenu?: (href: string) => MarkdownFileContextMenu | undefined; readonly onFileContextMenuAction?: (href: string, actionId: string) => void; diff --git a/apps/mobile/vite.config.ts b/apps/mobile/vite.config.ts index aa1231e934c16..a79d1f1c64222 100644 --- a/apps/mobile/vite.config.ts +++ b/apps/mobile/vite.config.ts @@ -40,6 +40,7 @@ const reactTests = [ "src/features/threads/PendingUserInputCard.test.tsx", "src/features/threads/NewTaskDraftRouteScreen.test.tsx", "src/native/NativeHeaderToolbar.test.tsx", + "src/native/EnrichedMarkdownText.test.tsx", "src/components/ComposerEditor.ios.test.tsx", "src/native/V5StackHeader.ios.test.tsx", "src/native/createV5StackNavigator.ios.test.tsx", From c490b83f9d282295b204098f390e0b387914140f Mon Sep 17 00:00:00 2001 From: Wout Stiens <71498452+StiensWout@users.noreply.github.com> Date: Sun, 22 Nov 2026 18:55:12 +0100 Subject: [PATCH 5/7] chore: credit the models that worked on this change Co-authored-by: Claude Opus 5.5 From 38b9d70d4307464c5a5309d7309f1d41d7d0784c Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sun, 22 Nov 2026 18:13:48 +0000 Subject: [PATCH 6/7] test(mobile): drop wiring tests for read-only chat links Link classification is already covered by markdownLinks.test.ts; the removed tests only mirrored callback wiring through heavy mocks. Co-Authored-By: Claude Opus 5.5 --- .../threads/LinkedThreadSheet.test.tsx | 136 ------------------ .../src/native/EnrichedMarkdownText.test.tsx | 85 ----------- 2 files changed, 221 deletions(-) delete mode 100644 apps/mobile/src/features/threads/LinkedThreadSheet.test.tsx delete mode 100644 apps/mobile/src/native/EnrichedMarkdownText.test.tsx diff --git a/apps/mobile/src/features/threads/LinkedThreadSheet.test.tsx b/apps/mobile/src/features/threads/LinkedThreadSheet.test.tsx deleted file mode 100644 index 70bed6ca04da3..0000000000000 --- a/apps/mobile/src/features/threads/LinkedThreadSheet.test.tsx +++ /dev/null @@ -1,136 +0,0 @@ -import { MessageId, type OrchestrationV2ProjectedTurnItem } from "@t3tools/contracts"; -import type { ReactNode } from "react"; -import { renderToStaticMarkup } from "react-dom/server"; -import { expect, it, vi } from "vite-plus/test"; -import { - v2MessageRow, - v2Projection, -} from "../../../../../packages/client-runtime/src/state/orchestrationV2TestFixtures"; - -const { openURL, readThread, links } = vi.hoisted(() => ({ - openURL: vi.fn(async (_url: string) => {}), - readThread: vi.fn(), - links: new Map void>(), -})); - -vi.mock("react", async (importOriginal) => { - const react = await importOriginal(); - return { - ...react, - useSyncExternalStore: ((subscribe, getSnapshot, getServerSnapshot = getSnapshot) => - react.useSyncExternalStore( - subscribe, - getSnapshot, - getServerSnapshot, - )) satisfies typeof react.useSyncExternalStore, - }; -}); - -vi.mock("react-native", () => ({ - AppState: { currentState: "active", addEventListener: () => ({ remove() {} }) }, - Linking: { openURL }, - ScrollView: ({ children }: { children: ReactNode }) =>
{children}
, - View: ({ children }: { children: ReactNode }) =>
{children}
, -})); -vi.mock("@react-navigation/native", () => ({ - useIsFocused: () => true, - useNavigation: () => ({}), -})); -vi.mock("react-native-safe-area-context", () => ({ useSafeAreaInsets: () => ({ bottom: 0 }) })); -vi.mock("../../components/ui/AppActivityIndicator", () => ({ AppActivityIndicator: () => null })); -vi.mock("../../components/ui/AppText", () => ({ - AppText: ({ children }: { children: ReactNode }) => {children}, -})); -vi.mock("../../components/ui/Button", () => ({ Button: () => null })); -vi.mock("../../components/ui/ScreenContent", () => ({ - ScreenContent: ({ children }: { children: ReactNode }) =>
{children}
, -})); -vi.mock("./ReadOnlyComposerBar", () => ({ ReadOnlyComposerBar: () => null })); -vi.mock("./thread-inspector-header", () => ({ ThreadInspectorHeader: () => null })); -vi.mock("../files/FileMarkdownPreview", () => ({ - useMarkdownPreviewStyles: () => ({ nativeTextStyle: {} }), -})); -vi.mock("../../state/environments", () => ({ useEnvironments: () => ({ environments: [] }) })); -vi.mock("../../state/linkedThread", () => ({ - useLinkedThreadView: readThread, - useConnectLinkedEnvironment: () => ({ state: { phase: "idle" } }), -})); -vi.mock("../../state/peerLinks", () => ({})); -vi.mock("../../state/query", () => ({})); -vi.mock("./useOpenLinkedThread", () => ({ useOpenLinkedThread: () => () => {} })); - -vi.mock("../../native/SelectableMarkdownText", () => ({ - SelectableMarkdownText: ({ - markdown, - onLinkPress, - }: { - markdown: string; - onLinkPress?: (href: string) => void; - }) => { - for (const [, label, href] of markdown.matchAll(/\[([^\]]+)\]\(([^)]*)\)/g)) { - if (label) links.set(label, () => onLinkPress?.(href ?? "")); - } - return null; - }, -})); - -import { LinkedThreadSheet } from "./LinkedThreadSheet"; - -it("opens web links from read-only agent messages through the system browser", () => { - const reply = v2MessageRow("reply", 0); - const sent = v2MessageRow("sent", 1); - if (reply.item.type !== "user_message" || sent.item.type !== "user_message") { - throw new Error("Expected message fixtures"); - } - const visibleTurnItems: OrchestrationV2ProjectedTurnItem[] = [ - { - ...reply, - item: { - ...reply.item, - type: "assistant_message", - messageId: MessageId.make("assistant-reply"), - text: "[Example](https://example.com/) [Docs](docs/readme.md) [Other](t3-thread://v2/env/thread) [Empty]()", - streaming: false, - }, - }, - { - ...sent, - position: 1, - item: { - ...sent.item, - type: "dynamic_tool", - toolName: "send_to_user", - input: {}, - output: { sentMessage: "[Reference](http://example.org/) [Guide](//example.net/guide)" }, - }, - }, - ]; - readThread.mockReturnValue({ - view: { - thread: { projection: { ...v2Projection, visibleTurnItems }, historyCursor: null }, - }, - error: null, - }); - openURL.mockClear(); - links.clear(); - - renderToStaticMarkup( - , - ); - expect([...links.keys()]).toEqual(["Example", "Docs", "Other", "Empty", "Reference", "Guide"]); - for (const press of links.values()) press(); - expect(openURL.mock.calls).toEqual([ - ["https://example.com/"], - ["http://example.org/"], - ["https://example.net/guide"], - ]); -}); diff --git a/apps/mobile/src/native/EnrichedMarkdownText.test.tsx b/apps/mobile/src/native/EnrichedMarkdownText.test.tsx deleted file mode 100644 index 5ed52e2464d91..0000000000000 --- a/apps/mobile/src/native/EnrichedMarkdownText.test.tsx +++ /dev/null @@ -1,85 +0,0 @@ -import { act, type ComponentProps, type PropsWithChildren } from "react"; -import { createRoot } from "react-dom/client"; -import type { EnrichedMarkdownText } from "react-native-enriched-markdown"; -import { expect, it, vi } from "vite-plus/test"; - -type WidgetProps = ComponentProps; - -const widget = vi.hoisted(() => vi.fn<(_props: WidgetProps) => null>(() => null)); - -vi.mock("react-native", () => ({ - Platform: { OS: "ios" }, - StyleSheet: { hairlineWidth: 1 }, - useWindowDimensions: () => ({ fontScale: 1 }), - View: ({ children }: PropsWithChildren) => children, -})); -vi.mock("react-native-enriched-markdown", () => ({ EnrichedMarkdownText: widget })); -vi.mock("../components/ui/Menu", () => ({ Menu: () => null })); -vi.mock("../features/settings/appearance/AppearancePreferencesProvider", () => ({ - useAppearancePreferences: () => ({ themeAppearance: "dark", mathRenderingEnabled: false }), -})); -vi.mock("./HighlightedCodeBlock", () => ({ HighlightedCodeBlock: () => null })); -vi.mock("./MermaidCodeBlock", () => ({ MermaidCodeBlock: () => null })); -vi.mock("./useEnrichedLinkVariants", () => ({ useEnrichedLinkVariants: () => ({}) })); -vi.mock("../lib/copyTextWithHaptic", () => ({ copyTextWithHaptic: vi.fn() })); - -import { MobileEnrichedMarkdownText } from "./EnrichedMarkdownText"; - -it("offers Open link only for destinations the host can open", async () => { - vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true); - widget.mockClear(); - const root = createRoot(document.createElement("div")); - const webUrl = "https://example.com/"; - const fileUrl = "docs/readme.md"; - const markdown = `[Example](${webUrl}) [Docs](${fileUrl})`; - const onLinkPress = vi.fn(); - const textStyle = { - color: "#fff", - strongColor: "#fff", - mutedColor: "#aaa", - linkColor: "#fff", - inlineCodeColor: "#fff", - codeColor: "#fff", - codeBackgroundColor: "#000", - codeBlockBackgroundColor: "#000", - fileTextColor: "#fff", - quoteMarkerColor: "#aaa", - dividerColor: "#aaa", - fontSize: 14, - lineHeight: 20, - fontFamily: "System", - headingFontFamily: "System", - boldFontFamily: "System", - }; - - try { - await act(() => - root.render( - url === webUrl} - />, - ), - ); - await act(() => - widget.mock.lastCall?.[0].onLinksChange?.([ - { url: webUrl, label: "Example", title: "" }, - { url: fileUrl, label: "Docs", title: "" }, - ]), - ); - - const menus = Object.entries(widget.mock.lastCall?.[0].linkContextMenuItems ?? {}); - const menuFor = (url: string) => menus.find(([pattern]) => new RegExp(pattern).test(url))?.[1]; - - expect(menuFor(fileUrl)?.map(({ text }) => text)).toEqual(["Copy link", "Share link"]); - const webMenu = menuFor(webUrl); - expect(webMenu?.map(({ text }) => text)).toEqual(["Open link", "Copy link", "Share link"]); - webMenu?.find(({ text }) => text === "Open link")?.onPress({ url: webUrl }); - expect(onLinkPress).toHaveBeenCalledExactlyOnceWith(webUrl); - } finally { - await act(() => root.unmount()); - vi.unstubAllGlobals(); - } -}); From 0b08b394c355263ed8e80c6bda3908dc706bf5ba Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sun, 22 Nov 2026 18:15:30 +0000 Subject: [PATCH 7/7] test(mobile): unregister the removed markdown menu test Co-Authored-By: Claude Opus 5.5 --- apps/mobile/vite.config.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/mobile/vite.config.ts b/apps/mobile/vite.config.ts index a79d1f1c64222..aa1231e934c16 100644 --- a/apps/mobile/vite.config.ts +++ b/apps/mobile/vite.config.ts @@ -40,7 +40,6 @@ const reactTests = [ "src/features/threads/PendingUserInputCard.test.tsx", "src/features/threads/NewTaskDraftRouteScreen.test.tsx", "src/native/NativeHeaderToolbar.test.tsx", - "src/native/EnrichedMarkdownText.test.tsx", "src/components/ComposerEditor.ios.test.tsx", "src/native/V5StackHeader.ios.test.tsx", "src/native/createV5StackNavigator.ios.test.tsx",