62 lines
2.0 KiB
TypeScript
62 lines
2.0 KiB
TypeScript
import React from "react";
|
|
import { describe, it, expect, vi } from "vitest";
|
|
import { render, fireEvent, waitFor } from "@testing-library/react";
|
|
|
|
const mockPost = vi.fn().mockResolvedValue({ data: { success: true } });
|
|
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(),
|
|
},
|
|
}));
|
|
|
|
import api from "../../lib/services/api";
|
|
import PrescriptionPageClient from "./PrescriptionPageClient";
|
|
|
|
describe("PrescriptionPageClient Suite (B2B-03)", () => {
|
|
it("renders online prescription portal and submits without requiring login", async () => {
|
|
const { container } = render(<PrescriptionPageClient />);
|
|
|
|
const phoneInput = container.querySelector("#rx-phone") as HTMLInputElement;
|
|
const petNameInput = container.querySelector("#rx-petName") as HTMLInputElement;
|
|
const fileInput = container.querySelector("#rx-file-input") as HTMLInputElement;
|
|
const form = container.querySelector("form") as HTMLFormElement;
|
|
|
|
expect(phoneInput).not.toBeNull();
|
|
expect(fileInput).not.toBeNull();
|
|
expect(form).not.toBeNull();
|
|
|
|
// Create fake file
|
|
const fakeFile = new File(["dummy content"], "prescription.jpg", { type: "image/jpeg" });
|
|
|
|
fireEvent.change(phoneInput, { target: { value: "09121114455" } });
|
|
fireEvent.change(petNameInput, { target: { value: "لئو" } });
|
|
fireEvent.change(fileInput, { target: { files: [fakeFile] } });
|
|
|
|
fireEvent.submit(form);
|
|
|
|
await waitFor(() => {
|
|
expect(api.post).toHaveBeenCalledWith(
|
|
"/b2b/inquire",
|
|
expect.objectContaining({
|
|
phone: "09121114455",
|
|
companyName: expect.stringContaining("لئو"),
|
|
})
|
|
);
|
|
});
|
|
});
|
|
});
|