shoc-frontend-new/src/test/app/(protected)/workorders/slide-over-footer-completed.test.tsx
Arthur Bassi 260fe6c654 fix(work-orders): drop slide-over edit actions after complete
Exit edit mode and refuse core Save when status becomes Completed; hide the footer even if unsaved.
2026-08-24 12:06:42 -03:00

70 lines
2.1 KiB
TypeScript

import { screen } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";
import { SlideOverFooter } from "@/app/(protected)/workorders/_components/detail/slide-over-footer";
import { renderWithProviders } from "@/test/test-utils";
const footerHandlers = {
onCancelWO: vi.fn(),
onCancelEdit: vi.fn(),
onClose: vi.fn(),
onEdit: vi.fn(),
onSave: vi.fn(),
onDiscard: vi.fn(),
onKeepEditing: vi.fn(),
};
describe("SlideOverFooter completed lock", () => {
it("hides Edit and Cancel WO when the work order is completed", () => {
const { container } = renderWithProviders(
<SlideOverFooter
isCancelled={false}
isCompleted
editing={false}
isDirty={false}
showUnsaved={false}
{...footerHandlers}
/>,
{ withAuth: false },
);
expect(container).toBeEmptyDOMElement();
expect(screen.queryByRole("button", { name: /edit wo/i })).not.toBeInTheDocument();
expect(screen.queryByText(/cancel wo/i)).not.toBeInTheDocument();
});
it("hides Cancel WO and Save when completed while still in edit mode", () => {
const { container } = renderWithProviders(
<SlideOverFooter
isCancelled={false}
isCompleted
editing
isDirty
showUnsaved={false}
{...footerHandlers}
/>,
{ withAuth: false },
);
expect(container).toBeEmptyDOMElement();
expect(screen.queryByText(/cancel wo/i)).not.toBeInTheDocument();
expect(screen.queryByRole("button", { name: /^save$/i })).not.toBeInTheDocument();
});
it("hides the unsaved Save bar when the work order is completed", () => {
const { container } = renderWithProviders(
<SlideOverFooter
isCancelled={false}
isCompleted
editing
isDirty
showUnsaved
{...footerHandlers}
/>,
{ withAuth: false },
);
expect(container).toBeEmptyDOMElement();
expect(screen.queryByText(/unsaved changes/i)).not.toBeInTheDocument();
expect(screen.queryByRole("button", { name: /^save$/i })).not.toBeInTheDocument();
});
});