fix(workorders): retain completed service snapshot labels

This commit is contained in:
Alexandre Brandizzi 2026-09-30 17:16:41 -03:00
parent 18fefef9a3
commit e35bd2983e
3 changed files with 62 additions and 4 deletions

View file

@ -61,7 +61,7 @@ export function PMTypeCell({
? serviceNames.filter((p) => p.toLowerCase().includes(search.toLowerCase()))
: serviceNames;
const linkedService = services?.find((service) => String(service.id) === String(serviceId));
const displayValue = linkedService?.isActive ? linkedService.name : value;
const displayValue = !viewOnly && linkedService?.isActive ? linkedService.name : value;
const extras = extraServices ?? [];
const hasDetails = hasServiceNotesDetails(serviceNotes, extras, avetaRequired);

View file

@ -77,6 +77,34 @@ describe("Aveta Service & Notes", () => {
expect(screen.queryByRole("button", { name: /Renamed Service/i })).not.toBeInTheDocument();
});
it("keeps the completed work-order label when its active service is renamed", () => {
renderWithProviders(
<PMTypeCell
value="Saved Completed Label"
serviceId={701}
pmTypes={[]}
services={[
{
id: 701,
name: "Current Active Name",
trade: "Electrical",
iconKey: "wrench",
requiresCompletionDocument: false,
completionDocTemplate: null,
isActive: true,
supportedWorkOrderTypes: ["PM"],
},
]}
workOrderType="PM"
viewOnly
onSave={vi.fn()}
/>,
);
expect(screen.getByRole("button", { name: /Saved Completed Label/i })).toBeInTheDocument();
expect(screen.queryByRole("button", { name: /Current Active Name/i })).not.toBeInTheDocument();
});
it("preserves the historic identity when only service notes change", () => {
const onSaveDetails = vi.fn();
renderWithProviders(

View file

@ -65,9 +65,6 @@ vi.mock("@/app/(protected)/workorders/_components/list/table/cells/date-cell", (
vi.mock("@/app/(protected)/workorders/_components/list/table/cells/appt-time-cell", () => ({
ApptTimeCell: () => null,
}));
vi.mock("@/app/(protected)/workorders/_components/list/table/cells/pm-type-cell", () => ({
PMTypeCell: () => null,
}));
vi.mock("@/app/(protected)/workorders/_components/list/table/cells/vendor-cell", () => ({
VendorCell: () => null,
}));
@ -155,6 +152,39 @@ describe("SlideOverInfoTabEditView additional contacts", () => {
expect(screen.queryByText("Renamed Service")).not.toBeInTheDocument();
});
it("keeps a completed slide-over's saved label after its active service is renamed", () => {
renderWithProviders(
<SlideOverInfoTabDisplayView
source={baseRow({
status: "Completed",
pm: "Saved Completed Label",
serviceId: 701,
})}
isCancelled={false}
isCompleted
sites={[]}
vendors={[]}
pmTypes={[]}
services={[
{
id: 701,
name: "Current Active Name",
trade: "Electrical",
iconKey: "wrench",
requiresCompletionDocument: false,
completionDocTemplate: null,
isActive: true,
supportedWorkOrderTypes: ["PM"],
},
]}
/>,
{ withAuth: false },
);
expect(screen.getByText("Saved Completed Label")).toBeInTheDocument();
expect(screen.queryByText("Current Active Name")).not.toBeInTheDocument();
});
it("saves an incompatible type change only after clearing the registry service", () => {
const baseline = baseRow({ type: "PM", pm: "PM only", serviceId: 701 });
const onSave = vi.fn();