63 lines
1.9 KiB
TypeScript
63 lines
1.9 KiB
TypeScript
import React from "react";
|
|
import { describe, it, expect, vi } from "vitest";
|
|
import { render, fireEvent, waitFor } from "@testing-library/react";
|
|
|
|
vi.mock("axios", () => {
|
|
const mAxios = {
|
|
post: vi.fn(() => Promise.resolve({ data: { success: true } })),
|
|
get: vi.fn(() => Promise.resolve({ data: { success: true } })),
|
|
interceptors: {
|
|
request: { use: vi.fn(), eject: vi.fn() },
|
|
response: { use: vi.fn(), eject: vi.fn() },
|
|
},
|
|
create: () => mAxios,
|
|
};
|
|
return { default: mAxios };
|
|
});
|
|
|
|
vi.mock("sonner", () => ({
|
|
toast: {
|
|
success: vi.fn(),
|
|
error: vi.fn(),
|
|
},
|
|
}));
|
|
|
|
vi.mock("../../lib/store/settingsStore", () => ({
|
|
useSettingsStore: (selector?: any) => {
|
|
const s = { getText: (k: string, d: string) => d };
|
|
return typeof selector === "function" ? selector(s) : s;
|
|
},
|
|
}));
|
|
|
|
import api from "../../lib/services/api";
|
|
import B2BLandingClient from "../B2BLandingClient";
|
|
|
|
describe("B2BLandingClient Suite (B2B-01)", () => {
|
|
it("renders B2B landing and correctly submits inquiry to /b2b/inquire", async () => {
|
|
const { container } = render(<B2BLandingClient />);
|
|
|
|
const businessInput = container.querySelector("#b2b-businessName") as HTMLInputElement;
|
|
const phoneInput = container.querySelector("#b2b-phone") as HTMLInputElement;
|
|
const form = container.querySelector("form") as HTMLFormElement;
|
|
|
|
expect(businessInput).not.toBeNull();
|
|
expect(phoneInput).not.toBeNull();
|
|
expect(form).not.toBeNull();
|
|
|
|
fireEvent.change(businessInput, { target: { value: "بیمارستان دامپزشکی پایتخت" } });
|
|
fireEvent.change(phoneInput, { target: { value: "09121112233" } });
|
|
|
|
fireEvent.submit(form);
|
|
|
|
await waitFor(() => {
|
|
expect(api.post).toHaveBeenCalledWith(
|
|
"/b2b/inquire",
|
|
expect.objectContaining({
|
|
companyName: "بیمارستان دامپزشکی پایتخت",
|
|
phone: "09121112233",
|
|
})
|
|
);
|
|
});
|
|
});
|
|
});
|