118 lines
4.1 KiB
TypeScript
118 lines
4.1 KiB
TypeScript
import { render, screen } from "@testing-library/react";
|
|
import { describe, expect, it, vi } from "vitest";
|
|
import { ExceptionModal } from "./ExceptionModal";
|
|
|
|
// Mock Dialog components
|
|
vi.mock("@xtablo/ui/components/dialog", () => ({
|
|
Dialog: ({ open, children }: any) => (open ? <div data-testid="dialog">{children}</div> : null),
|
|
DialogContent: ({ children }: any) => <div>{children}</div>,
|
|
DialogHeader: ({ children }: any) => <div>{children}</div>,
|
|
DialogTitle: ({ children }: any) => <h2>{children}</h2>,
|
|
DialogDescription: ({ children }: any) => <p>{children}</p>,
|
|
DialogFooter: ({ children }: any) => <div>{children}</div>,
|
|
}));
|
|
|
|
// Mock other components
|
|
vi.mock("@xtablo/ui/components/button", () => ({
|
|
Button: ({ children, onClick, type }: any) => (
|
|
<button onClick={onClick} type={type}>
|
|
{children}
|
|
</button>
|
|
),
|
|
}));
|
|
|
|
vi.mock("@xtablo/ui/components/button-group", () => ({
|
|
ButtonGroup: ({ children }: any) => <div data-testid="button-group">{children}</div>,
|
|
}));
|
|
|
|
vi.mock("@xtablo/ui/components/label", () => ({
|
|
Label: ({ children }: any) => <label>{children}</label>,
|
|
}));
|
|
|
|
vi.mock("@xtablo/ui/components/date-picker", () => ({
|
|
DatePickerV1: ({ value, onChange }: any) => (
|
|
<input
|
|
type="date"
|
|
value={value?.toISOString().split("T")[0]}
|
|
onChange={(e) => onChange && onChange(new Date(e.target.value))}
|
|
data-testid="date-picker"
|
|
/>
|
|
),
|
|
}));
|
|
|
|
vi.mock("@xtablo/ui/components/time-input", () => ({
|
|
TimeInput: ({ value, onChange }: any) => (
|
|
<input
|
|
type="time"
|
|
value={value}
|
|
onChange={(e) => onChange && onChange(e.target.value)}
|
|
data-testid="time-input"
|
|
/>
|
|
),
|
|
}));
|
|
|
|
vi.mock("react-i18next", () => ({
|
|
useTranslation: () => ({
|
|
t: (key: string) => key,
|
|
}),
|
|
}));
|
|
|
|
describe("ExceptionModal", () => {
|
|
const mockOnClose = vi.fn();
|
|
const mockOnSubmit = vi.fn();
|
|
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
it("renders when open", () => {
|
|
render(<ExceptionModal isOpen={true} onClose={mockOnClose} onSubmit={mockOnSubmit} />);
|
|
expect(screen.getByTestId("dialog")).toBeInTheDocument();
|
|
});
|
|
|
|
it("does not render when closed", () => {
|
|
render(<ExceptionModal isOpen={false} onClose={mockOnClose} onSubmit={mockOnSubmit} />);
|
|
expect(screen.queryByTestId("dialog")).not.toBeInTheDocument();
|
|
});
|
|
|
|
it("displays title", () => {
|
|
render(<ExceptionModal isOpen={true} onClose={mockOnClose} onSubmit={mockOnSubmit} />);
|
|
expect(screen.getByText("exceptionModal.title")).toBeInTheDocument();
|
|
});
|
|
|
|
it("displays description", () => {
|
|
render(<ExceptionModal isOpen={true} onClose={mockOnClose} onSubmit={mockOnSubmit} />);
|
|
expect(screen.getByText("exceptionModal.description")).toBeInTheDocument();
|
|
});
|
|
|
|
it("displays exception type label", () => {
|
|
render(<ExceptionModal isOpen={true} onClose={mockOnClose} onSubmit={mockOnSubmit} />);
|
|
expect(screen.getByText("exceptionModal.labels.exceptionType")).toBeInTheDocument();
|
|
});
|
|
|
|
it("displays exception type buttons", () => {
|
|
render(<ExceptionModal isOpen={true} onClose={mockOnClose} onSubmit={mockOnSubmit} />);
|
|
expect(screen.getByText("exceptionModal.types.allDay")).toBeInTheDocument();
|
|
expect(screen.getByText("exceptionModal.types.customHours")).toBeInTheDocument();
|
|
});
|
|
|
|
it("displays date picker", () => {
|
|
render(<ExceptionModal isOpen={true} onClose={mockOnClose} onSubmit={mockOnSubmit} />);
|
|
expect(screen.getByTestId("date-picker")).toBeInTheDocument();
|
|
});
|
|
|
|
it("renders button group for exception types", () => {
|
|
render(<ExceptionModal isOpen={true} onClose={mockOnClose} onSubmit={mockOnSubmit} />);
|
|
expect(screen.getByTestId("button-group")).toBeInTheDocument();
|
|
});
|
|
|
|
it("displays cancel button", () => {
|
|
render(<ExceptionModal isOpen={true} onClose={mockOnClose} onSubmit={mockOnSubmit} />);
|
|
expect(screen.getByText("exceptionModal.buttons.cancel")).toBeInTheDocument();
|
|
});
|
|
|
|
it("displays add button", () => {
|
|
render(<ExceptionModal isOpen={true} onClose={mockOnClose} onSubmit={mockOnSubmit} />);
|
|
expect(screen.getByText("exceptionModal.buttons.add")).toBeInTheDocument();
|
|
});
|
|
});
|