fabro/apps/fabro-web/app/routes/run-files/keyboard.test.ts
Bryan Helmkamp 695a6ca536
test(web): Run Files UI + pierre smoke test coverage (P2-10, P2-12)
Adds four test files for the Run Files route:

- placeholders.test.tsx: validates pickPlaceholder priority order
  (sensitive > binary > symlink/submodule > truncated) and
  bannerCopyForReason copy distinctness + unknown-reason fallback
- states.test.tsx: full deriveEmptyKind decision table (R4a
  starting, R4b no_changes, R4c1 failed_before_checkpoint, R4c2
  diff_lost, unknown) plus component rendering assertions for
  EmptyState, LoadingSkeleton, InlineErrorBanner onRetry wiring,
  and Toast aria-live
- keyboard.test.ts: isEditableElement correctness across
  input/textarea/select/contenteditable/null/case variants
- pierre-smoke.test.tsx: asserts MultiFileDiff, PatchDiff, and
  Virtualizer remain exported as callable components after the 1.0
  -> 1.1 upgrade (a full mount-under-test hits pierre's
  useLayoutEffect teardown path that's incompatible with
  react-test-renderer under React 19; functional mount coverage
  lives in the dev-server smoke flow)

All rendering tests wrap TestRenderer.create in TestRenderer.act to
keep React 19 from synchronously unmounting before assertions run.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-19 17:48:20 -04:00

40 lines
1.3 KiB
TypeScript

import { describe, expect, test } from "bun:test";
import { isEditableElement } from "./keyboard";
// Lightweight stand-in for the DOM `Element` API. We only need `tagName`
// and `isContentEditable` for `isEditableElement`.
function mk(tagName: string, isContentEditable = false): Element {
return {
tagName: tagName.toUpperCase(),
isContentEditable,
} as unknown as Element;
}
describe("isEditableElement", () => {
test("flags input / textarea / select as editable", () => {
expect(isEditableElement(mk("input"))).toBe(true);
expect(isEditableElement(mk("textarea"))).toBe(true);
expect(isEditableElement(mk("select"))).toBe(true);
});
test("flags contenteditable elements as editable", () => {
expect(isEditableElement(mk("div", true))).toBe(true);
expect(isEditableElement(mk("span", true))).toBe(true);
});
test("non-editable elements are left alone", () => {
expect(isEditableElement(mk("div"))).toBe(false);
expect(isEditableElement(mk("button"))).toBe(false);
expect(isEditableElement(mk("a"))).toBe(false);
});
test("null never claims editable", () => {
expect(isEditableElement(null)).toBe(false);
});
test("case-insensitive on tag name", () => {
expect(isEditableElement(mk("Input"))).toBe(true);
expect(isEditableElement(mk("TEXTAREA"))).toBe(true);
});
});