Merges FN-3341 mobile keyboard handling improvements into the dashboard, wiring `useMobileKeyboard` into both TodoModal and PlanningModeModal with keyboard-aware CSS overrides for mobile, plus regression tests for both components. FN-3337's chat `isGenerating` state recovery is also included. Fusion-Task-Id: FN-3341
116 lines
4.0 KiB
TypeScript
116 lines
4.0 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
import { fireEvent, render, screen } from "@testing-library/react";
|
|
import { TodoModal } from "../TodoModal";
|
|
|
|
const mockTodoView = vi.fn();
|
|
const mockUseMobileKeyboard = vi.fn();
|
|
const mockUseViewportMode = vi.fn();
|
|
|
|
vi.mock("../TodoView", () => ({
|
|
TodoView: (props: unknown) => {
|
|
mockTodoView(props);
|
|
return <div data-testid="todo-view-content">Todo content</div>;
|
|
},
|
|
}));
|
|
|
|
vi.mock("../../hooks/useMobileKeyboard", () => ({
|
|
useMobileKeyboard: (...args: unknown[]) => mockUseMobileKeyboard(...args),
|
|
}));
|
|
|
|
vi.mock("../../hooks/useViewportMode", () => ({
|
|
useViewportMode: (...args: unknown[]) => mockUseViewportMode(...args),
|
|
}));
|
|
|
|
describe("TodoModal", () => {
|
|
const onClose = vi.fn();
|
|
const addToast = vi.fn();
|
|
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
mockUseViewportMode.mockReturnValue("desktop");
|
|
mockUseMobileKeyboard.mockReturnValue({
|
|
keyboardOverlap: 0,
|
|
viewportHeight: null,
|
|
viewportOffsetTop: 0,
|
|
keyboardOpen: false,
|
|
});
|
|
});
|
|
|
|
it("renders modal dialog semantics and header content", () => {
|
|
render(<TodoModal onClose={onClose} addToast={addToast} />);
|
|
|
|
expect(screen.getByRole("dialog")).toHaveAttribute("aria-modal", "true");
|
|
expect(screen.getByRole("heading", { name: "Todos" })).toBeInTheDocument();
|
|
expect(screen.getByText("Manage reusable todo lists for your project.")).toBeInTheDocument();
|
|
});
|
|
|
|
it("closes on Escape", () => {
|
|
render(<TodoModal onClose={onClose} addToast={addToast} />);
|
|
fireEvent.keyDown(document, { key: "Escape" });
|
|
expect(onClose).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it("closes on overlay backdrop click", () => {
|
|
render(<TodoModal onClose={onClose} addToast={addToast} />);
|
|
const overlay = screen.getByRole("dialog");
|
|
fireEvent.mouseDown(overlay);
|
|
fireEvent.mouseUp(overlay);
|
|
expect(onClose).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it("closes from close button", () => {
|
|
render(<TodoModal onClose={onClose} addToast={addToast} />);
|
|
fireEvent.click(screen.getByRole("button", { name: "Close" }));
|
|
expect(onClose).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it("passes projectId and addToast through to TodoView", () => {
|
|
render(<TodoModal onClose={onClose} addToast={addToast} projectId="proj-1" />);
|
|
|
|
expect(screen.getByTestId("todo-view-content")).toBeInTheDocument();
|
|
expect(mockTodoView).toHaveBeenCalledWith(
|
|
expect.objectContaining({ projectId: "proj-1", addToast }),
|
|
);
|
|
});
|
|
|
|
describe("mobile keyboard behavior", () => {
|
|
it("applies CSS variables when keyboard is open on mobile", () => {
|
|
mockUseViewportMode.mockReturnValue("mobile");
|
|
mockUseMobileKeyboard.mockReturnValue({
|
|
keyboardOverlap: 250,
|
|
viewportHeight: 450,
|
|
viewportOffsetTop: 40,
|
|
keyboardOpen: true,
|
|
});
|
|
|
|
render(<TodoModal onClose={onClose} addToast={addToast} />);
|
|
const modal = screen.getByRole("dialog").querySelector(".modal.todo-modal");
|
|
expect(modal).toBeTruthy();
|
|
|
|
const style = (modal as HTMLElement).style;
|
|
expect(style.getPropertyValue("--keyboard-overlap")).toBe("250px");
|
|
expect(style.getPropertyValue("--vv-offset-top")).toBe("40px");
|
|
expect(style.getPropertyValue("--vv-height")).toBe("450px");
|
|
});
|
|
|
|
it("does not apply keyboard CSS variables when keyboard is closed", () => {
|
|
mockUseViewportMode.mockReturnValue("mobile");
|
|
mockUseMobileKeyboard.mockReturnValue({
|
|
keyboardOverlap: 0,
|
|
viewportHeight: null,
|
|
viewportOffsetTop: 0,
|
|
keyboardOpen: false,
|
|
});
|
|
|
|
render(<TodoModal onClose={onClose} addToast={addToast} />);
|
|
const modal = screen.getByRole("dialog").querySelector(".modal.todo-modal");
|
|
expect(modal).toBeTruthy();
|
|
|
|
const style = (modal as HTMLElement).style;
|
|
expect(style.getPropertyValue("--keyboard-overlap")).toBe("");
|
|
expect(style.getPropertyValue("--vv-offset-top")).toBe("");
|
|
expect(style.getPropertyValue("--vv-height")).toBe("");
|
|
});
|
|
});
|
|
});
|