All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
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 <noreply@anthropic.com>
111 lines
3.3 KiB
TypeScript
111 lines
3.3 KiB
TypeScript
import { describe, it, expect, vi } from "vitest";
|
|
import { render, screen } from "@testing-library/react";
|
|
import userEvent from "@testing-library/user-event";
|
|
import { DomainSelector } from "./DomainSelector";
|
|
import type { Domain } from "@mosaic/shared";
|
|
|
|
describe("DomainSelector", (): void => {
|
|
const mockDomains: Domain[] = [
|
|
{
|
|
id: "domain-1",
|
|
workspaceId: "workspace-1",
|
|
name: "Work",
|
|
slug: "work",
|
|
description: "Work-related tasks",
|
|
color: "#3B82F6",
|
|
icon: "💼",
|
|
sortOrder: 0,
|
|
metadata: {},
|
|
createdAt: new Date("2026-01-28"),
|
|
updatedAt: new Date("2026-01-28"),
|
|
},
|
|
{
|
|
id: "domain-2",
|
|
workspaceId: "workspace-1",
|
|
name: "Personal",
|
|
slug: "personal",
|
|
description: null,
|
|
color: "#10B981",
|
|
icon: null,
|
|
sortOrder: 1,
|
|
metadata: {},
|
|
createdAt: new Date("2026-01-28"),
|
|
updatedAt: new Date("2026-01-28"),
|
|
},
|
|
];
|
|
|
|
it("should render with default placeholder", (): void => {
|
|
const onChange = vi.fn();
|
|
render(<DomainSelector domains={mockDomains} value={null} onChange={onChange} />);
|
|
expect(screen.getByText("Select a domain")).toBeInTheDocument();
|
|
});
|
|
|
|
it("should render with custom placeholder", (): void => {
|
|
const onChange = vi.fn();
|
|
render(
|
|
<DomainSelector
|
|
domains={mockDomains}
|
|
value={null}
|
|
onChange={onChange}
|
|
placeholder="Choose domain"
|
|
/>
|
|
);
|
|
expect(screen.getByText("Choose domain")).toBeInTheDocument();
|
|
});
|
|
|
|
it("should render all domains as options", (): void => {
|
|
const onChange = vi.fn();
|
|
render(<DomainSelector domains={mockDomains} value={null} onChange={onChange} />);
|
|
expect(screen.getByText("💼 Work")).toBeInTheDocument();
|
|
expect(screen.getByText("Personal")).toBeInTheDocument();
|
|
});
|
|
|
|
it("should call onChange when selection changes", async (): Promise<void> => {
|
|
const user = userEvent.setup();
|
|
const onChange = vi.fn();
|
|
|
|
render(<DomainSelector domains={mockDomains} value={null} onChange={onChange} />);
|
|
|
|
const select = screen.getByRole("combobox");
|
|
await user.selectOptions(select, "domain-1");
|
|
|
|
expect(onChange).toHaveBeenCalledWith("domain-1");
|
|
});
|
|
|
|
it("should call onChange with null when cleared", async (): Promise<void> => {
|
|
const user = userEvent.setup();
|
|
const onChange = vi.fn();
|
|
|
|
render(<DomainSelector domains={mockDomains} value="domain-1" onChange={onChange} />);
|
|
|
|
const select = screen.getByRole("combobox");
|
|
await user.selectOptions(select, "");
|
|
|
|
expect(onChange).toHaveBeenCalledWith(null);
|
|
});
|
|
|
|
it("should show selected value", (): void => {
|
|
const onChange = vi.fn();
|
|
render(<DomainSelector domains={mockDomains} value="domain-1" onChange={onChange} />);
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
const select = screen.getByRole("combobox") as HTMLSelectElement;
|
|
expect(select.value).toBe("domain-1");
|
|
});
|
|
|
|
it("should apply custom className", (): void => {
|
|
const onChange = vi.fn();
|
|
render(
|
|
<DomainSelector
|
|
domains={mockDomains}
|
|
value={null}
|
|
onChange={onChange}
|
|
className="custom-class"
|
|
/>
|
|
);
|
|
|
|
const select = screen.getByRole("combobox");
|
|
expect(select.className).toContain("custom-class");
|
|
});
|
|
});
|