Files
fusion/packages/dashboard/app/components/__tests__/OAuthManualCodeForm.test.tsx
gsxdsm f58fb8955a fix(engine-tests): eliminate temp-dir leak and raise subprocess guard for concurrent workspace runs
Two engine merger tests created mkdtempSync workspaces directly in tmpdir()
under the tracked `fusion-test-` prefix; under full-suite concurrent load
the post-run check-test-isolation flagged them as leaks. Route both
(`merger-no-op-fix-finalize.test.ts`, `merger-verification-fix-already-on-main.test.ts`)
through FUSION_TEST_WORKER_ROOT like sibling merger tests so they nest
inside the already-tracked worker root.

Bump engine vitest subprocess guard from 60s to 120s and testTimeout to
30s — plain git commands (branch -d, worktree remove) queued behind
system contention during `pnpm -r --workspace-concurrency=2` runs were
timing out. The guard only fires on hangs, so healthy tests pay nothing.

Also bundles in-progress dashboard mobile-breakpoint regex/CSS test
updates and docs index additions.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-22 20:20:42 -07:00

111 lines
3.0 KiB
TypeScript

import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
import { render, screen, fireEvent } from "@testing-library/react";
import { OAuthManualCodeForm } from "../OAuthManualCodeForm";
function mockMatchMedia({ mobile = false, coarse = false, reducedMotion = false }: { mobile?: boolean; coarse?: boolean; reducedMotion?: boolean }) {
Object.defineProperty(window, "matchMedia", {
writable: true,
value: vi.fn().mockImplementation((query: string) => ({
matches:
(query === "(max-width: 768px)" || query === "(max-width: 768px), (max-height: 480px)" && mobile)
|| (query === "(pointer: coarse)" && coarse)
|| (query === "(prefers-reduced-motion: reduce)" && reducedMotion),
media: query,
onchange: null,
addEventListener: vi.fn(),
removeEventListener: vi.fn(),
addListener: vi.fn(),
removeListener: vi.fn(),
dispatchEvent: vi.fn(),
})),
});
}
describe("OAuthManualCodeForm", () => {
beforeEach(() => {
vi.useFakeTimers();
});
afterEach(() => {
vi.useRealTimers();
vi.restoreAllMocks();
});
it("scrolls the textarea into view on mobile focus and visual viewport resize", () => {
mockMatchMedia({ mobile: true });
const listeners: Record<string, (() => void) | undefined> = {};
Object.defineProperty(window, "visualViewport", {
configurable: true,
value: {
addEventListener: vi.fn((event: string, callback: () => void) => {
listeners[event] = callback;
}),
removeEventListener: vi.fn((event: string) => {
delete listeners[event];
}),
},
});
render(
<OAuthManualCodeForm
value=""
onChange={vi.fn()}
onSubmit={vi.fn()}
prompt="Paste code"
/>,
);
const textarea = screen.getByRole("textbox");
const scrollIntoView = vi.fn();
Object.defineProperty(textarea, "scrollIntoView", {
value: scrollIntoView,
writable: true,
});
fireEvent.focus(textarea);
vi.runAllTimers();
expect(scrollIntoView).toHaveBeenCalledWith({
block: "center",
behavior: "smooth",
inline: "nearest",
});
Object.defineProperty(document, "activeElement", {
configurable: true,
get: () => textarea,
});
listeners.resize?.();
vi.runAllTimers();
expect(scrollIntoView).toHaveBeenCalled();
});
it("does not trigger scroll assist on non-mobile layouts", () => {
mockMatchMedia({ mobile: false, coarse: false });
render(
<OAuthManualCodeForm
value=""
onChange={vi.fn()}
onSubmit={vi.fn()}
prompt="Paste code"
/>,
);
const textarea = screen.getByRole("textbox");
const scrollIntoView = vi.fn();
Object.defineProperty(textarea, "scrollIntoView", {
value: scrollIntoView,
writable: true,
});
fireEvent.focus(textarea);
vi.runAllTimers();
expect(scrollIntoView).not.toHaveBeenCalled();
});
});