mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-07 16:19:01 +00:00
81 lines
2.7 KiB
TypeScript
81 lines
2.7 KiB
TypeScript
import { fireEvent, screen } from "@testing-library/react";
|
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
import type { UpliftQueueItem } from "@/domain/uplifts/types/uplift";
|
|
import { renderWithProviders } from "@/test/test-utils";
|
|
|
|
const rejectMutate = vi.fn();
|
|
const approveMutate = vi.fn();
|
|
const requestChangesMutate = vi.fn();
|
|
const refetch = vi.fn();
|
|
|
|
const pendingItem: UpliftQueueItem = {
|
|
id: 41,
|
|
status: "Pending",
|
|
currentNTE: 100,
|
|
requestedNTE: 250,
|
|
delta: 150,
|
|
vendorReason: "Extra parts",
|
|
requestedAt: "2026-01-15T10:00:00Z",
|
|
requestedByVendorName: "Gateway",
|
|
decidedAt: "",
|
|
decidedByName: "",
|
|
decisionNote: "",
|
|
requiredTier: 1,
|
|
canDecide: true,
|
|
expiresAt: "",
|
|
notificationStatus: "",
|
|
notificationError: "",
|
|
evidenceDocumentId: null,
|
|
evidenceFileName: "",
|
|
evidenceContentType: "",
|
|
evidenceSizeBytes: null,
|
|
dispatchNumber: "DSP-41",
|
|
poNumber: "PO-41",
|
|
vendorCompanyName: "Gateway Plumbing",
|
|
workOrderId: 99,
|
|
dispatchId: 7,
|
|
};
|
|
|
|
vi.mock("@/domain/uplifts/use-cases/use-uplifts-queue", () => ({
|
|
useUpliftsQueue: () => ({
|
|
data: { items: [pendingItem], totalCount: 1, page: 1, pageSize: 25 },
|
|
isLoading: false,
|
|
isFetching: false,
|
|
error: null,
|
|
refetch,
|
|
}),
|
|
}));
|
|
|
|
vi.mock("@/domain/uplifts/use-cases/use-uplift-actions", () => ({
|
|
useApproveUplift: () => ({ isPending: false, mutate: approveMutate }),
|
|
useRejectUplift: () => ({ isPending: false, mutate: rejectMutate }),
|
|
useRequestChangesUplift: () => ({ isPending: false, mutate: requestChangesMutate }),
|
|
}));
|
|
|
|
describe("Uplift queue decision dialogs", () => {
|
|
beforeEach(() => {
|
|
rejectMutate.mockReset();
|
|
approveMutate.mockReset();
|
|
requestChangesMutate.mockReset();
|
|
refetch.mockReset();
|
|
});
|
|
|
|
it("opens RejectDialog from Reject and does not reject on Cancel", async () => {
|
|
const { default: UpliftQueuePage } = await import("@/app/(protected)/uplifts/index");
|
|
renderWithProviders(<UpliftQueuePage />);
|
|
|
|
fireEvent.click(screen.getByRole("button", { name: "Reject" }));
|
|
expect(screen.getByRole("heading", { name: /reject uplift of \$250/i })).toBeInTheDocument();
|
|
fireEvent.click(screen.getByRole("button", { name: "Cancel" }));
|
|
expect(rejectMutate).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("keeps Approve on the generic confirm dialog", async () => {
|
|
const { default: UpliftQueuePage } = await import("@/app/(protected)/uplifts/index");
|
|
renderWithProviders(<UpliftQueuePage />);
|
|
|
|
fireEvent.click(screen.getByRole("button", { name: "Approve" }));
|
|
expect(screen.getByRole("button", { name: "Confirm" })).toBeInTheDocument();
|
|
expect(screen.queryByRole("button", { name: "Reject uplift" })).not.toBeInTheDocument();
|
|
});
|
|
});
|