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
87 lines
4.3 KiB
TypeScript
87 lines
4.3 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
import { render, screen, fireEvent, waitFor } from "@testing-library/react";
|
|
|
|
const ship = vi.hoisted(() => ({ listRateCards: vi.fn(), saveRateCard: vi.fn(), listZones: vi.fn() }));
|
|
vi.mock("@/app/lib/services/adminShipping", () => ship);
|
|
const xl = vi.hoisted(() => ({ toXlsx: vi.fn(), downloadXlsx: vi.fn() }));
|
|
vi.mock("@/app/lib/xlsx", () => xl);
|
|
vi.mock("./RateCardEditor", () => ({ RateCardEditor: ({ cardId }: { cardId: number }) => <p>{`editor ${cardId}`}</p> }));
|
|
|
|
import { RateCardsTab } from "./RateCardsTab";
|
|
import { MessagesProvider } from "@/app/lib/i18n/MessagesProvider";
|
|
import { pickDate } from "@/test/pickDate";
|
|
import { pickTime } from "@/test/pickTime";
|
|
|
|
beforeEach(() => {
|
|
ship.listRateCards.mockReset().mockResolvedValue([
|
|
{ id: 3, name: "2026 rates", effectiveFrom: "2026-11-01T00:00:00", status: "DRAFT", warehouseId: null, freeShippingThreshold: 150 },
|
|
]);
|
|
ship.listZones.mockReset().mockResolvedValue([
|
|
{ id: 1, code: "WM", name: "West", status: "Y", geoLocationIds: [50] },
|
|
{ id: 2, code: "OLD", name: "Old", status: "N", geoLocationIds: [] },
|
|
]);
|
|
xl.toXlsx.mockReset().mockResolvedValue(new Uint8Array([1]));
|
|
xl.downloadXlsx.mockReset();
|
|
ship.saveRateCard.mockReset().mockResolvedValue({ id: 4, name: "2027", effectiveFrom: "2027-01-01T00:00:00", status: "DRAFT" });
|
|
});
|
|
|
|
describe("RateCardsTab (add-shipping-rates)", () => {
|
|
it("lists the cards", async () => {
|
|
render(<RateCardsTab />);
|
|
expect(await screen.findByText("2026 rates")).toBeInTheDocument();
|
|
expect(screen.getByText("DRAFT")).toBeInTheDocument();
|
|
expect(screen.getByText("All warehouses")).toBeInTheDocument();
|
|
expect(screen.getByText("2026-11-01 00:00")).toBeInTheDocument();
|
|
});
|
|
|
|
it("labels the effective-from date through the message catalog", async () => {
|
|
render(<MessagesProvider locale="en_US" messages={{ EffectiveFrom: "Starts on" }}><RateCardsTab /></MessagesProvider>);
|
|
await screen.findByText("2026 rates");
|
|
fireEvent.click(screen.getByRole("button", { name: "New card" }));
|
|
expect(screen.getByText("Starts on")).toBeInTheDocument();
|
|
});
|
|
|
|
it("creates a draft card and opens its editor", async () => {
|
|
render(<RateCardsTab />);
|
|
await screen.findByText("2026 rates");
|
|
fireEvent.click(screen.getByRole("button", { name: "New card" }));
|
|
fireEvent.change(screen.getByLabelText("Name"), { target: { value: "2027" } });
|
|
pickDate(/^effective from$/i, "2027-01-01");
|
|
await pickTime(/^effective from time$/i, "00:00");
|
|
fireEvent.click(screen.getByRole("button", { name: "Create" }));
|
|
|
|
await waitFor(() => expect(ship.saveRateCard).toHaveBeenCalledWith({
|
|
name: "2027", effectiveFrom: "2027-01-01T00:00:00", freeShippingThreshold: null, warehouseId: null,
|
|
}));
|
|
expect(await screen.findByText("editor 4")).toBeInTheDocument();
|
|
});
|
|
|
|
it("the New card dialog has no volumetric divisor field", async () => {
|
|
render(<RateCardsTab />);
|
|
await screen.findByText("2026 rates");
|
|
fireEvent.click(screen.getByRole("button", { name: "New card" }));
|
|
expect(screen.getByLabelText("Name")).toBeInTheDocument();
|
|
expect(screen.queryByLabelText("Volumetric divisor")).toBeNull();
|
|
expect(screen.queryByText("Volumetric divisor")).toBeNull();
|
|
});
|
|
|
|
it("downloads the rates template for the active zones from the list, and says where to import it", async () => {
|
|
render(<RateCardsTab />);
|
|
await screen.findByText("2026 rates");
|
|
expect(screen.getByText("Download the template, fill in the fees, then open a card and use Import rates.")).toBeInTheDocument();
|
|
fireEvent.click(screen.getByRole("button", { name: "Download template" }));
|
|
|
|
await waitFor(() => expect(xl.downloadXlsx).toHaveBeenCalledWith("shipping-rates-template.xlsx", expect.anything()));
|
|
expect(xl.toXlsx.mock.calls[0][0]).toEqual([
|
|
{ zoneCode: "WM", type: "BRACKET", toKg: 1, maxLengthCm: 20, maxWidthCm: 15, maxHeightCm: 10, stepKg: null, fee: 0 },
|
|
{ zoneCode: "WM", type: "OVERFLOW", toKg: null, maxLengthCm: null, maxWidthCm: null, maxHeightCm: null, stepKg: 1, fee: 0 },
|
|
]);
|
|
});
|
|
|
|
it("opens an existing card", async () => {
|
|
render(<RateCardsTab />);
|
|
fireEvent.click(await screen.findByRole("button", { name: "Open" }));
|
|
expect(screen.getByText("editor 3")).toBeInTheDocument();
|
|
});
|
|
});
|