mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-06 13:32:06 +00:00
Exit edit mode and refuse core Save when status becomes Completed; hide the footer even if unsaved.
70 lines
2.1 KiB
TypeScript
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();
|
|
});
|
|
});
|