import { describe, it, expect, vi, beforeEach } from "vitest";
import { render, screen, waitFor } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import type { User } from "@/lib/api/auth";
import type {
CheckinDetails,
CheckinDetailsUpdate,
} from "@/lib/api/checkin-details";
import type { PictureEdit } from "@/lib/picture-edits";
import { CheckinDetailsForm } from "./checkin-details-form";
import { UserFieldsSubmitButton } from "@/components/user/user-fields-form";
// The portrait rides on About You's Save as the avatar does on Profile Information's
// (see `user-fields-form.render.test.tsx`); what is particular here is the dialog: a
// picture that failed must not close it, or the pick it keeps goes with it.
const auth = vi.hoisted(() => ({
user: { uuid: "user-1", name: "Jane Doe", email: "jane@example.com" } as User,
refreshUser: vi.fn(),
}));
vi.mock("@/contexts/AuthContext", () => ({ useAuth: () => auth }));
const checkin = vi.hoisted(() => ({
details: {
email: null,
phone: null,
date_of_birth: null,
emergency_contacts: [],
insurance_policies: [],
} as CheckinDetails,
loadFailed: false,
reload: vi.fn(),
save: vi.fn(),
}));
vi.mock("@/contexts/CheckinDetailsContext", () => ({
useCheckinDetails: () => checkin,
}));
vi.mock("@/lib/api/auth", () => ({
authAPI: { updateProfile: vi.fn(), removePicture: vi.fn() },
}));
// The field's own picking and cropping is `UserFieldsForm`'s test; here it only has to
// hand the form an edit and show which one it holds.
vi.mock("@/components/user/picture-field", () => ({
PictureField: ({
edit,
onChange,
}: {
edit: PictureEdit | null;
onChange: (edit: PictureEdit | null) => void;
}) => (