Files
stack/apps/web/src/components/widgets/__tests__/WidgetGrid.test.tsx
T
jason.woltjeandClaude Sonnet 4.5 ac1f2c176f fix: Resolve all ESLint errors and warnings in web package
Fixes all 542 ESLint problems in the web package to achieve 0 errors and 0 warnings.

Changes:
- Fixed 144 issues: nullish coalescing, return types, unused variables
- Fixed 118 issues: unnecessary conditions, type safety, template literals
- Fixed 79 issues: non-null assertions, unsafe assignments, empty functions
- Fixed 67 issues: explicit return types, promise handling, enum comparisons
- Fixed 45 final warnings: missing return types, optional chains
- Fixed 25 typecheck-related issues: async/await, type assertions, formatting
- Fixed JSX.Element namespace errors across 90+ files

All Quality Rails violations resolved. Lint and typecheck both pass with 0 problems.

Files modified: 118 components, tests, hooks, and utilities

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
2026-01-31 00:10:03 -06:00

103 lines
3.2 KiB
TypeScript

/**
* WidgetGrid Component Tests
* Following TDD - write tests first!
*/
import { describe, it, expect, vi } from "vitest";
import { render, screen } from "@testing-library/react";
import { WidgetGrid } from "../WidgetGrid";
import type { WidgetPlacement } from "@mosaic/shared";
// Mock react-grid-layout
vi.mock("react-grid-layout", () => ({
default: ({ children }: { children: React.ReactNode }): React.JSX.Element => (
<div data-testid="grid-layout">{children}</div>
),
Responsive: ({ children }: { children: React.ReactNode }): React.JSX.Element => (
<div data-testid="responsive-grid-layout">{children}</div>
),
}));
describe("WidgetGrid", (): void => {
const mockLayout: WidgetPlacement[] = [
{ i: "tasks-1", x: 0, y: 0, w: 2, h: 2 },
{ i: "calendar-1", x: 2, y: 0, w: 2, h: 2 },
];
const mockOnLayoutChange = vi.fn();
it("should render grid layout", (): void => {
render(<WidgetGrid layout={mockLayout} onLayoutChange={mockOnLayoutChange} />);
expect(screen.getByTestId("grid-layout")).toBeInTheDocument();
});
it("should render widgets from layout", (): void => {
render(<WidgetGrid layout={mockLayout} onLayoutChange={mockOnLayoutChange} />);
// Should render correct number of widgets
const widgets = screen.getAllByTestId(/widget-/);
expect(widgets).toHaveLength(mockLayout.length);
});
it("should call onLayoutChange when layout changes", (): void => {
const { rerender } = render(
<WidgetGrid layout={mockLayout} onLayoutChange={mockOnLayoutChange} />
);
const newLayout: WidgetPlacement[] = [
{ i: "tasks-1", x: 1, y: 0, w: 2, h: 2 },
{ i: "calendar-1", x: 2, y: 0, w: 2, h: 2 },
];
rerender(<WidgetGrid layout={newLayout} onLayoutChange={mockOnLayoutChange} />);
// Layout change handler should be set up (actual calls handled by react-grid-layout)
expect(mockOnLayoutChange).toBeDefined();
});
it("should support edit mode", (): void => {
render(<WidgetGrid layout={mockLayout} onLayoutChange={mockOnLayoutChange} isEditing={true} />);
// In edit mode, widgets should have edit controls
expect(screen.getByTestId("grid-layout")).toBeInTheDocument();
});
it("should support read-only mode", (): void => {
render(
<WidgetGrid layout={mockLayout} onLayoutChange={mockOnLayoutChange} isEditing={false} />
);
expect(screen.getByTestId("grid-layout")).toBeInTheDocument();
});
it("should render empty state when no widgets", (): void => {
render(<WidgetGrid layout={[]} onLayoutChange={mockOnLayoutChange} />);
expect(screen.getByText(/no widgets/i)).toBeInTheDocument();
});
it("should handle widget removal", (): void => {
const mockOnRemoveWidget = vi.fn();
render(
<WidgetGrid
layout={mockLayout}
onLayoutChange={mockOnLayoutChange}
onRemoveWidget={mockOnRemoveWidget}
isEditing={true}
/>
);
// Widget removal should be supported
expect(mockOnRemoveWidget).toBeDefined();
});
it("should apply custom className", (): void => {
const { container } = render(
<WidgetGrid layout={mockLayout} onLayoutChange={mockOnLayoutChange} className="custom-grid" />
);
expect(container.querySelector(".custom-grid")).toBeInTheDocument();
});
});