import { readFileSync } from "node:fs";
import { describe, expect, it } from "vitest";

const bridgeSource = readFileSync(new URL(
  "../../android/app/src/main/java/com/phenomrom/iwanttoheal/ControllerBridgeActivity.java",
  import.meta.url,
), "utf8");

describe("native controller bridge", () => {
  it("never requests WebView or window focus for controller input", () => {
    expect(bridgeSource).not.toMatch(/requestFocus\s*\(/);
    expect(bridgeSource).not.toMatch(/setFocusable/);
    expect(bridgeSource).not.toMatch(/onWindowFocusChanged/);
    expect(bridgeSource).not.toMatch(/dispatchTouchEvent/);
  });

  it("routes controller input from activity-level key and motion dispatch", () => {
    expect(bridgeSource).toMatch(/boolean dispatchKeyEvent\s*\(/);
    expect(bridgeSource).toMatch(/boolean dispatchGenericMotionEvent\s*\(/);
    expect(bridgeSource).toMatch(/evaluateJavascript\s*\(/);
  });
});
