Files
fusion/packages/dashboard/app/hooks/__tests__/useViewportMode.test.ts
gsxdsm fa23782dbb FN-5972: fix mobile auto-merge blank dashboard
Restore mobile auto-merge dashboard stability and broaden regression coverage.

- share the mobile media query between viewport detection and board stabilization so landscape phones stay on the mobile path
- add an integration regression suite for toggling auto-merge across mobile, tablet, desktop, rollback, and task review surfaces
- expand dashboard and CLI tests, keep the new published changeset, and preserve related vitest coverage lists and safety comments

Files changed:
$(git diff --cached --stat)

Fusion-Task-Id: FN-5972

Fusion-Task-Lineage: f3a3bbae-21c2-451b-b24f-848cc12d0542
2026-06-07 18:51:46 -07:00

56 lines
1.6 KiB
TypeScript

import { renderHook } from "@testing-library/react";
import { afterEach, describe, expect, it, vi } from "vitest";
import { getViewportMode, MOBILE_MEDIA_QUERY, useViewportMode } from "../useViewportMode";
describe("useViewportMode", () => {
afterEach(() => {
vi.unstubAllGlobals();
});
it("treats short landscape phones as mobile", () => {
vi.stubGlobal(
"matchMedia",
vi.fn((query: string) => ({
matches:
query === MOBILE_MEDIA_QUERY
? true
: query === "(min-width: 769px) and (max-width: 1024px)"
? false
: false,
media: query,
onchange: null,
addEventListener: vi.fn(),
removeEventListener: vi.fn(),
})),
);
expect(getViewportMode()).toBe("mobile");
expect(renderHook(() => useViewportMode()).result.current).toBe("mobile");
});
it("supports legacy MediaQueryList listeners without runtime errors", () => {
const listeners: Array<() => void> = [];
const removeListener = vi.fn((listener: () => void) => {
const index = listeners.indexOf(listener);
if (index >= 0) listeners.splice(index, 1);
});
const consoleErrorSpy = vi.spyOn(console, "error").mockImplementation(() => {});
vi.stubGlobal(
"matchMedia",
vi.fn((query: string) => ({
matches: query === MOBILE_MEDIA_QUERY,
media: query,
onchange: null,
addListener: (listener: () => void) => listeners.push(listener),
removeListener,
})),
);
renderHook(() => useViewportMode());
expect(consoleErrorSpy).not.toHaveBeenCalled();
consoleErrorSpy.mockRestore();
});
});