Backend modules from tastefully 8bd93d15: core-libs, core-session, api-gateway, mobile-api, services-auth, services-system, services-counter, services-member, services-log, services-email. solvway-admin-portal from babyboo f64d096ea, solvway-customer-portal from tastefully 8bd93d15. Copied as tracked files only. Literal secrets replaced with environment placeholders: - services-email: SMTP_PASSWORD, MAILGUN_API_KEY, SENDGRID_API_KEY, MAILJET_API_KEY, MAILJET_SECRET_KEY (optional, empty default) - services-system: JUMIO_TOKEN, JUMIO_SECRET (optional) - services-auth: USER_AUTH_API_SECRET (required); commented JWT secret removed - core-libs: JWT_TOKEN default removed (required), XXL_JOB_TOKEN default removed, ipgeolocation key read from IPGEOLOCATION_API_KEY - services-system EkycAppConfig: commented Jumio credentials removed Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
64 lines
2.7 KiB
TypeScript
64 lines
2.7 KiB
TypeScript
import { render, screen, waitFor } from "@testing-library/react";
|
|
import userEvent from "@testing-library/user-event";
|
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
|
const catalog = vi.hoisted(() => ({ listCatalogRows: vi.fn() }));
|
|
vi.mock("@/app/lib/services/adminCatalog", () => catalog);
|
|
|
|
import { SupplierSelect } from "./SupplierSelect";
|
|
|
|
// add-sku-supplier: the SKU editor's Supplier select lists active suppliers and keeps a deactivated current one.
|
|
describe("SupplierSelect", () => {
|
|
beforeEach(() => {
|
|
catalog.listCatalogRows.mockReset();
|
|
catalog.listCatalogRows.mockResolvedValue([
|
|
{ id: "1", code: "SUP01", name: "Acme Baby", status: "Y" },
|
|
{ id: "2", code: "SUP02", name: "Old Co", status: "N" },
|
|
{ id: "3", code: "SUP03", name: "Bee Kids", status: "Y" },
|
|
]);
|
|
});
|
|
|
|
it("offers No supplier and the active suppliers only", async () => {
|
|
const user = userEvent.setup();
|
|
render(<SupplierSelect value={null} onChange={vi.fn()} />);
|
|
await waitFor(() => expect(catalog.listCatalogRows).toHaveBeenCalledWith("supplier"));
|
|
|
|
await user.click(screen.getByRole("combobox", { name: "Supplier" }));
|
|
|
|
expect(await screen.findByRole("option", { name: "SUP01 · Acme Baby" })).toBeTruthy();
|
|
expect(screen.getByRole("option", { name: "SUP03 · Bee Kids" })).toBeTruthy();
|
|
expect(screen.getByRole("option", { name: "No supplier" })).toBeTruthy();
|
|
expect(screen.queryByRole("option", { name: /SUP02/ })).toBeNull();
|
|
});
|
|
|
|
it("reports the picked supplier id as a number, and null for No supplier", async () => {
|
|
const user = userEvent.setup();
|
|
const onChange = vi.fn();
|
|
render(<SupplierSelect value={3} onChange={onChange} />);
|
|
|
|
await user.click(await screen.findByRole("combobox", { name: "Supplier" }));
|
|
await user.click(await screen.findByRole("option", { name: "SUP01 · Acme Baby" }));
|
|
expect(onChange).toHaveBeenLastCalledWith(1);
|
|
|
|
await user.click(screen.getByRole("combobox", { name: "Supplier" }));
|
|
await user.click(await screen.findByRole("option", { name: "No supplier" }));
|
|
expect(onChange).toHaveBeenLastCalledWith(null);
|
|
});
|
|
|
|
it("still shows a current supplier that has been deactivated", async () => {
|
|
render(<SupplierSelect value={2} onChange={vi.fn()} />);
|
|
|
|
await waitFor(() =>
|
|
expect(screen.getByRole("combobox", { name: "Supplier" }).textContent).toContain("SUP02 · Old Co (inactive)"),
|
|
);
|
|
});
|
|
|
|
it("still renders when the list fails to load", async () => {
|
|
catalog.listCatalogRows.mockRejectedValue(new Error("down"));
|
|
render(<SupplierSelect value={null} onChange={vi.fn()} />);
|
|
|
|
expect(await screen.findByText("Couldn't load suppliers.")).toBeTruthy();
|
|
expect(screen.getByRole("combobox", { name: "Supplier" })).toBeTruthy();
|
|
});
|
|
});
|