@crossed/ui
Version:
A universal & performant styling library for React Native, Next.js & React
39 lines (38 loc) • 1.85 kB
JavaScript
var import_jsx_runtime = require("react/jsx-runtime");
var import_test = require("@crossed/test");
var import_SelectMonth = require("../SelectMonth");
jest.mock("../../Select", () => ({
Select: ({ value, onChange, items }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("select", { value, onChange: (e) => onChange(e.target.value), children: items.map((item) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: item.value, children: item.label }, item.value)) })
}));
describe("SelectMonth", () => {
const mockMonths = [
{ value: "0", label: "January" },
{ value: "1", label: "February" },
{ value: "2", label: "March" }
];
const mockOnChange = jest.fn();
test("renders correctly with given months and selected month", () => {
(0, import_test.render)(
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_SelectMonth.SelectMonth, { month: 1, months: mockMonths, onChange: mockOnChange })
);
expect(import_test.screen.getByDisplayValue("February")).toBeInTheDocument();
});
test("calls onChange when a new month is selected", () => {
(0, import_test.render)(
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_SelectMonth.SelectMonth, { month: 1, months: mockMonths, onChange: mockOnChange })
);
import_test.fireEvent.change(import_test.screen.getByDisplayValue("February"), {
target: { value: "2" }
});
expect(mockOnChange).toHaveBeenCalledWith(2);
});
test("renders all months in the dropdown", () => {
(0, import_test.render)(
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_SelectMonth.SelectMonth, { month: 1, months: mockMonths, onChange: mockOnChange })
);
mockMonths.forEach((month) => {
expect(import_test.screen.getByText(month.label)).toBeInTheDocument();
});
});
});
//# sourceMappingURL=SelectMonth.spec.js.map