Ensure viewport mode updates stay in sync so toggling auto-merge no longer blanks the dashboard. - update useViewportMode to initialize safely and react consistently to viewport/media-query changes - add focused hook coverage for initial mode detection and transition behavior - add dashboard/app regression tests to confirm the board remains rendered after auto-merge toggles - add a changeset for @runfusion/fusion patch release Files changed: .changeset/fn-5817-auto-merge-toggle-mobile.md | 5 ++ .../app/components/__tests__/App.test.tsx | 66 ++++++++++++++++++++++ .../__tests__/board-mobile-initial-render.test.tsx | 30 ++++++++++ .../app/hooks/__tests__/useViewportMode.test.ts | 34 +++++++++++ packages/dashboard/app/hooks/useViewportMode.ts | 28 +++++++-- 5 files changed, 159 insertions(+), 4 deletions(-) Fusion-Task-Id: FN-5817 Fusion-Task-Lineage: 2fc044b1-5f37-44de-b70e-c60364a3d69c
35 lines
1.0 KiB
TypeScript
35 lines
1.0 KiB
TypeScript
import { renderHook } from "@testing-library/react";
|
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
import { useViewportMode } from "../useViewportMode";
|
|
|
|
describe("useViewportMode", () => {
|
|
afterEach(() => {
|
|
vi.unstubAllGlobals();
|
|
});
|
|
|
|
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 === "(max-width: 768px)",
|
|
media: query,
|
|
onchange: null,
|
|
addListener: (listener: () => void) => listeners.push(listener),
|
|
removeListener,
|
|
})),
|
|
);
|
|
|
|
renderHook(() => useViewportMode());
|
|
|
|
expect(consoleErrorSpy).not.toHaveBeenCalled();
|
|
consoleErrorSpy.mockRestore();
|
|
});
|
|
});
|