mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-05 07:12:06 +00:00
Keep Flag, comments, and extra docs writable after completion, and hide the completed status menu.
97 lines
3 KiB
TypeScript
97 lines
3 KiB
TypeScript
import { screen } from "@testing-library/react";
|
|
import { describe, expect, it, vi } from "vitest";
|
|
import { SlideOverCommentsTab } from "@/app/(protected)/workorders/_components/detail/tabs/slide-over-comments-tab";
|
|
import { SlideOverExtrasTab } from "@/app/(protected)/workorders/_components/detail/tabs/slide-over-extras-tab";
|
|
import {
|
|
canMutateWorkOrderComments,
|
|
canMutateWorkOrderExtraDocs,
|
|
} from "@/domain/work-orders/utils/work-order-lock";
|
|
import { renderWithProviders } from "@/test/test-utils";
|
|
|
|
describe("Completed comments and extra docs remain writable", () => {
|
|
it("shows the comment composer when status is Completed", () => {
|
|
renderWithProviders(
|
|
<SlideOverCommentsTab
|
|
comments={[]}
|
|
isReadOnly={!canMutateWorkOrderComments("Completed")}
|
|
isPending={false}
|
|
onSubmit={vi.fn()}
|
|
/>,
|
|
{ withAuth: false },
|
|
);
|
|
|
|
expect(screen.getByPlaceholderText("Add comment…")).toBeInTheDocument();
|
|
expect(screen.getByRole("button", { name: /post/i })).toBeInTheDocument();
|
|
});
|
|
|
|
it("keeps edit on the author's own comment when status is Completed", () => {
|
|
renderWithProviders(
|
|
<SlideOverCommentsTab
|
|
comments={[
|
|
{
|
|
id: 11,
|
|
createdDate: "2026-07-20T12:00:00Z",
|
|
commenttext: "Need a flag on this",
|
|
commentType: "General",
|
|
userName: "Alex",
|
|
authorId: "u1",
|
|
commenter: "Alex",
|
|
recordType: "WorkOrder",
|
|
},
|
|
]}
|
|
isReadOnly={!canMutateWorkOrderComments("Completed")}
|
|
isPending={false}
|
|
currentUserId="u1"
|
|
onSubmit={vi.fn()}
|
|
onUpdateComment={vi.fn()}
|
|
/>,
|
|
{ withAuth: false },
|
|
);
|
|
|
|
expect(screen.getByRole("button", { name: /edit comment/i })).toBeInTheDocument();
|
|
});
|
|
|
|
it("hides the comment composer when status is Canceled", () => {
|
|
renderWithProviders(
|
|
<SlideOverCommentsTab
|
|
comments={[]}
|
|
isReadOnly={!canMutateWorkOrderComments("Canceled")}
|
|
isPending={false}
|
|
onSubmit={vi.fn()}
|
|
/>,
|
|
{ withAuth: false },
|
|
);
|
|
|
|
expect(screen.queryByPlaceholderText("Add comment…")).not.toBeInTheDocument();
|
|
});
|
|
|
|
it("shows extra-docs upload when status is Completed", () => {
|
|
renderWithProviders(
|
|
<SlideOverExtrasTab
|
|
uploads={[]}
|
|
isReadOnly={!canMutateWorkOrderExtraDocs("Completed")}
|
|
pending={false}
|
|
onUpload={vi.fn()}
|
|
onRemove={vi.fn()}
|
|
/>,
|
|
{ withAuth: false },
|
|
);
|
|
|
|
expect(screen.getByText(/upload documents/i)).toBeInTheDocument();
|
|
});
|
|
|
|
it("hides extra-docs upload when status is Canceled", () => {
|
|
renderWithProviders(
|
|
<SlideOverExtrasTab
|
|
uploads={[]}
|
|
isReadOnly={!canMutateWorkOrderExtraDocs("Canceled")}
|
|
pending={false}
|
|
onUpload={vi.fn()}
|
|
onRemove={vi.fn()}
|
|
/>,
|
|
{ withAuth: false },
|
|
);
|
|
|
|
expect(screen.queryByText(/upload documents/i)).not.toBeInTheDocument();
|
|
});
|
|
});
|