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
60 lines
3.2 KiB
TypeScript
60 lines
3.2 KiB
TypeScript
import { render, screen, fireEvent, waitFor } from "@testing-library/react";
|
|
import { describe, it, expect, vi } from "vitest";
|
|
import { AddLocationDialog } from "./AddLocationDialog";
|
|
|
|
describe("AddLocationDialog", () => {
|
|
it("is closed until triggered", () => {
|
|
render(<AddLocationDialog parentName="Malaysia" onConfirm={vi.fn()} />);
|
|
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
|
|
});
|
|
|
|
it("opens on trigger and asks for confirmation naming the parent", () => {
|
|
render(<AddLocationDialog parentName="Malaysia" onConfirm={vi.fn()} />);
|
|
fireEvent.click(screen.getByRole("button", { name: "Add child location" }));
|
|
expect(screen.getByRole("dialog")).toBeInTheDocument();
|
|
// Title and body copy both name the parent; assert via the dialog heading to stay unambiguous.
|
|
expect(screen.getByRole("heading", { name: /under Malaysia/ })).toBeInTheDocument();
|
|
});
|
|
|
|
it("requires code, name and type before confirming", async () => {
|
|
const onConfirm = vi.fn();
|
|
render(<AddLocationDialog parentName="Malaysia" onConfirm={onConfirm} />);
|
|
fireEvent.click(screen.getByRole("button", { name: "Add child location" }));
|
|
fireEvent.click(screen.getByRole("button", { name: "Confirm" }));
|
|
expect(await screen.findByText("Code, name and type are required.")).toBeInTheDocument();
|
|
expect(onConfirm).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("calls onConfirm with the entered fields and closes on success", async () => {
|
|
const onConfirm = vi.fn().mockResolvedValue(undefined);
|
|
render(<AddLocationDialog parentName="Malaysia" onConfirm={onConfirm} />);
|
|
fireEvent.click(screen.getByRole("button", { name: "Add child location" }));
|
|
fireEvent.change(screen.getByLabelText("Code"), { target: { value: "WM" } });
|
|
fireEvent.change(screen.getByLabelText("Name"), { target: { value: "West Malaysia" } });
|
|
fireEvent.click(screen.getByRole("combobox", { name: "Type" }));
|
|
fireEvent.click(await screen.findByRole("option", { name: "Region" }));
|
|
fireEvent.click(screen.getByRole("button", { name: "Confirm" }));
|
|
await waitFor(() =>
|
|
expect(onConfirm).toHaveBeenCalledWith({ code: "WM", name: "West Malaysia", type: "R" }),
|
|
);
|
|
await waitFor(() => expect(screen.queryByRole("dialog")).not.toBeInTheDocument());
|
|
});
|
|
|
|
it("offers child types as options (no free text, no Global root)", async () => {
|
|
render(<AddLocationDialog parentName="Malaysia" onConfirm={vi.fn()} />);
|
|
fireEvent.click(screen.getByRole("button", { name: "Add child location" }));
|
|
fireEvent.click(screen.getByRole("combobox", { name: "Type" }));
|
|
expect(await screen.findByRole("option", { name: "Branch" })).toBeInTheDocument();
|
|
expect(screen.queryByRole("option", { name: "Global" })).not.toBeInTheDocument();
|
|
});
|
|
|
|
it("Cancel closes the dialog without submitting", async () => {
|
|
const onConfirm = vi.fn();
|
|
render(<AddLocationDialog parentName="Malaysia" onConfirm={onConfirm} />);
|
|
fireEvent.click(screen.getByRole("button", { name: "Add child location" }));
|
|
fireEvent.click(screen.getByRole("button", { name: "Cancel" }));
|
|
await waitFor(() => expect(screen.queryByRole("dialog")).not.toBeInTheDocument());
|
|
expect(onConfirm).not.toHaveBeenCalled();
|
|
});
|
|
});
|