Skip to content

Commit 886ef4f

Browse files
committed
test(mobile): check selectable HTML at the helper layer
1 parent b9ae608 commit 886ef4f

4 files changed

Lines changed: 24 additions & 27 deletions

File tree

‎apps/mobile/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"generate": "node --disable-warning=MODULE_TYPELESS_PACKAGE_JSON scripts/generate-uniwind-themes.mts",
4848
"generate:highlights": "node scripts/generate-highlights.mts",
4949
"eas-build-on-success": "node scripts/upload-sourcemaps.mts build",
50-
"test": "vp test run --project unit --project react && T3_MOBILE_TEST_PLATFORM=android vp test run --project react src/components/FilePreviewModal.test.tsx src/features/files/SourceFileSurface.test.tsx",
50+
"test": "vp test run --project unit --project react && T3_MOBILE_TEST_PLATFORM=android vp test run --project react src/components/FilePreviewModal.test.tsx",
5151
"typecheck": "effect-tsgo tsrs --noEmit"
5252
},
5353
"dependencies": {

‎apps/mobile/src/features/files/SourceFileSurface.test.tsx‎

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ vi.mock("@t3tools/mobile-source-text", () => ({
3838
SourceText: ({ children }: { readonly children?: ReactNode }) => <span>{children}</span>,
3939
}));
4040
vi.mock("react-native-webview", () => ({
41-
WebView: (props: { readonly source: { readonly html: string } }) => (
42-
<div data-testid="source-selectable-web-view" data-html={props.source.html} />
43-
),
41+
WebView: () => null,
4442
}));
4543
vi.mock("react-native-safe-area-context", () => ({ useSafeAreaInsets: () => ({ top: 0 }) }));
4644
vi.mock("../../native/native-layout-metrics", () => ({ useNativeColumnLayoutMetrics: () => null }));
@@ -65,9 +63,8 @@ vi.mock("@effect/atom-react", () => ({ useAtomValue: () => AsyncResult.success(n
6563

6664
import { SourceFileSurface } from "./SourceFileSurface";
6765

68-
function setup(
69-
contents = Array.from({ length: 80 }, (_, index) => `line ${index + 1}`).join("\n"),
70-
) {
66+
function setup() {
67+
const contents = Array.from({ length: 80 }, (_, index) => `line ${index + 1}`).join("\n");
7168
(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
7269
vi.useFakeTimers();
7370
vi.stubGlobal("requestAnimationFrame", (callback: () => void) => setTimeout(callback, 16));
@@ -90,12 +87,6 @@ function setup(
9087
);
9188
act(() => vi.runAllTimers());
9289
},
93-
selectableDocument: () => {
94-
const html = container
95-
.querySelector('[data-testid="source-selectable-web-view"]')
96-
?.getAttribute("data-html");
97-
return html ? new DOMParser().parseFromString(html, "text/html") : null;
98-
},
9990
lineList: () => container.querySelector<HTMLDivElement>('[data-testid="source-lines"]'),
10091
[Symbol.dispose]() {
10192
act(() => root.unmount());
@@ -120,17 +111,3 @@ it("restores the requested wrapped line after leaving selection mode", () => {
120111
expect(returnedList).not.toBe(firstList);
121112
expect(returnedList.scrollTop).toBe(39 * 24);
122113
});
123-
124-
it("lets Android select plain text in a browser that keeps every character as text", () => {
125-
using screen = setup("\n\tlead\r\n<script>alert(1)</script> &amp; > 😀\u00a0end\n");
126-
screen.render(true);
127-
const page = screen.selectableDocument();
128-
129-
if (process.env.T3_MOBILE_TEST_PLATFORM !== "android") {
130-
expect(page).toBeNull();
131-
return;
132-
}
133-
134-
expect(page!.querySelector("script")).toBeNull();
135-
expect(page!.body.textContent).toBe("\n\tlead\n<script>alert(1)</script> &amp; > 😀\u00a0end\n");
136-
});
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { expect, it } from "vite-plus/test";
2+
import { prepareSourceFileDocument, selectableSourceHtml } from "./source-file-document";
3+
4+
it("preserves source whitespace and markup as literal selectable text", () => {
5+
const source = prepareSourceFileDocument(
6+
"\n\tlead\r\n<script>alert(1)</script> &amp; > 😀\u00a0end\n",
7+
);
8+
const html = selectableSourceHtml(source.contents, {
9+
foreground: "#000000",
10+
selection: "#3366ff",
11+
fontSize: 14,
12+
rowHeight: 24,
13+
wordBreak: true,
14+
});
15+
const page = new DOMParser().parseFromString(html, "text/html");
16+
17+
expect(page.querySelector("script")).toBeNull();
18+
expect(page.body.textContent).toBe("\n\tlead\n<script>alert(1)</script> &amp; > 😀\u00a0end\n");
19+
});

‎apps/mobile/vite.config.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const reactTests = [
1111
"src/features/threads/git/GitBranchesSheet.occupancy.test.tsx",
1212
"src/features/files/useFileTreeEntries.test.tsx",
1313
"src/features/files/SourceFileSurface.test.tsx",
14+
"src/features/files/source-file-document.test.ts",
1415
"src/features/projects/AddProjectScreen.test.ts",
1516
"src/lib/useMediaVideoPlayback.test.tsx",
1617
"src/features/pull-requests/usePullRequestEnvironmentFallback.test.tsx",

0 commit comments

Comments
 (0)