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
90 lines
3.9 KiB
TypeScript
90 lines
3.9 KiB
TypeScript
import { render, screen, waitFor, fireEvent } from "@testing-library/react";
|
|
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
import { GeoAddressTab } from "./GeoAddressTab";
|
|
|
|
const mockFetch = vi.fn();
|
|
beforeEach(() => {
|
|
mockFetch.mockReset();
|
|
vi.stubGlobal("fetch", mockFetch);
|
|
});
|
|
|
|
describe("GeoAddressTab", () => {
|
|
it("labels itself as a separate dataset from the business tree", async () => {
|
|
mockFetch.mockResolvedValue({ ok: true, json: async () => [] });
|
|
render(<GeoAddressTab />);
|
|
expect(screen.getByText("Member address geo-tree")).toBeInTheDocument();
|
|
expect(
|
|
screen.getByText(/separate from the business\/warehouse tree/i),
|
|
).toBeInTheDocument();
|
|
});
|
|
|
|
it("shows a loading indicator, then the first-level rows", async () => {
|
|
mockFetch.mockResolvedValue({
|
|
ok: true,
|
|
json: async () => [{ id: 2, name: "Malaysia", parentId: 1, status: "Y", type: "C" }],
|
|
});
|
|
render(<GeoAddressTab />);
|
|
expect(screen.getByRole("status")).toBeInTheDocument();
|
|
await waitFor(() => expect(screen.getByText("Malaysia")).toBeInTheDocument());
|
|
});
|
|
|
|
it("lazy-loads a node's children on expand, with its own loading indicator", async () => {
|
|
mockFetch
|
|
.mockResolvedValueOnce({
|
|
ok: true,
|
|
json: async () => [{ id: 2, name: "Malaysia", parentId: 1, status: "Y", type: "C" }],
|
|
})
|
|
.mockResolvedValueOnce({
|
|
ok: true,
|
|
json: async () => [{ id: 21, name: "West Malaysia", parentId: 2, status: "Y", type: "S" }],
|
|
});
|
|
render(<GeoAddressTab />);
|
|
await waitFor(() => expect(screen.getByText("Malaysia")).toBeInTheDocument());
|
|
fireEvent.click(screen.getByLabelText("Expand Malaysia"));
|
|
expect(screen.getByLabelText("Loading Malaysia's children")).toBeInTheDocument();
|
|
await waitFor(() => expect(screen.getByText("West Malaysia")).toBeInTheDocument());
|
|
expect(mockFetch).toHaveBeenCalledWith("/api/geo-locations?parentId=2");
|
|
});
|
|
|
|
it("shows a fetch-error state with a retry option", async () => {
|
|
mockFetch.mockResolvedValue({ ok: false, json: async () => ({ error: "boom" }) });
|
|
render(<GeoAddressTab />);
|
|
expect(await screen.findByText(/couldn't load/i)).toBeInTheDocument();
|
|
expect(screen.getByRole("button", { name: "Retry" })).toBeInTheDocument();
|
|
});
|
|
|
|
it("shows an inline error with retry when a row's children fail to load", async () => {
|
|
mockFetch
|
|
.mockResolvedValueOnce({
|
|
ok: true,
|
|
json: async () => [{ id: 2, name: "Malaysia", parentId: 1, status: "Y", type: "C" }],
|
|
})
|
|
.mockResolvedValueOnce({ ok: false, json: async () => ({ error: "boom" }) });
|
|
render(<GeoAddressTab />);
|
|
await waitFor(() => expect(screen.getByText("Malaysia")).toBeInTheDocument());
|
|
fireEvent.click(screen.getByLabelText("Expand Malaysia"));
|
|
expect(await screen.findByText(/couldn't load malaysia's children/i)).toBeInTheDocument();
|
|
expect(screen.getAllByRole("button", { name: "Retry" }).length).toBeGreaterThanOrEqual(1);
|
|
});
|
|
|
|
it("clears a row's error and shows children after Retry succeeds", async () => {
|
|
mockFetch
|
|
.mockResolvedValueOnce({
|
|
ok: true,
|
|
json: async () => [{ id: 2, name: "Malaysia", parentId: 1, status: "Y", type: "C" }],
|
|
})
|
|
.mockResolvedValueOnce({ ok: false, json: async () => ({ error: "boom" }) })
|
|
.mockResolvedValueOnce({
|
|
ok: true,
|
|
json: async () => [{ id: 21, name: "West Malaysia", parentId: 2, status: "Y", type: "S" }],
|
|
});
|
|
render(<GeoAddressTab />);
|
|
await waitFor(() => expect(screen.getByText("Malaysia")).toBeInTheDocument());
|
|
fireEvent.click(screen.getByLabelText("Expand Malaysia"));
|
|
await screen.findByText(/couldn't load malaysia's children/i);
|
|
fireEvent.click(screen.getByRole("button", { name: "Retry" }));
|
|
await waitFor(() => expect(screen.getByText("West Malaysia")).toBeInTheDocument());
|
|
expect(screen.queryByText(/couldn't load malaysia's children/i)).not.toBeInTheDocument();
|
|
});
|
|
});
|