shoc-frontend-new/src/test/domain/work-orders/utils/partition-slide-over-media.test.ts
Codex Review Integration 8774b2e0a6 fix(work-orders): render PM extra media in the gallery (SH-371)
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-16 15:23:24 -03:00

109 lines
3.6 KiB
TypeScript

import { describe, expect, it } from "vitest";
import type { MediaFile } from "@/domain/work-orders/types/work-order-media";
import {
hasCompletionMediaGallery,
isCompletionSurfaceMedia,
isExtrasSurfaceMedia,
} from "@/domain/work-orders/utils/partition-slide-over-media";
function file(
overrides: Partial<MediaFile> & Pick<MediaFile, "id" | "fileType" | "purpose">,
): MediaFile {
return {
name: overrides.name ?? overrides.id,
url: "https://cdn.example.com/file",
category: "Photo",
uploadStatus: "done",
...overrides,
};
}
describe("partition-slide-over-media", () => {
it("keeps unowned Extra photos on Completion Doc, not Extra Docs", () => {
const photo = file({
id: "10",
fileType: "image",
purpose: "Extra",
name: "site.jpg",
});
expect(isCompletionSurfaceMedia(photo)).toBe(true);
expect(isExtrasSurfaceMedia(photo)).toBe(false);
});
it("keeps Extra PDFs on Extra Docs, not Completion Doc", () => {
const pdf = file({
id: "4",
fileType: "pdf",
purpose: "Extra",
name: "extra.pdf",
category: "Other",
});
expect(isCompletionSurfaceMedia(pdf)).toBe(false);
expect(isExtrasSurfaceMedia(pdf)).toBe(true);
});
it("moves Extra photo to Extra Docs after explicit Extra ownership", () => {
const photo = file({ id: "10", fileType: "image", purpose: "Extra" });
const ownership = {
completionOwnedIds: new Set<string>(),
extraOwnedIds: new Set(["10"]),
};
expect(isCompletionSurfaceMedia(photo, ownership)).toBe(false);
expect(isExtrasSurfaceMedia(photo, ownership)).toBe(true);
});
it("keeps Extra photo on Completion Doc while completion-owned", () => {
const photo = file({ id: "10", fileType: "image", purpose: "Extra" });
const ownership = {
completionOwnedIds: new Set(["10"]),
extraOwnedIds: new Set<string>(),
};
expect(isCompletionSurfaceMedia(photo, ownership)).toBe(true);
expect(isExtrasSurfaceMedia(photo, ownership)).toBe(false);
});
it("keeps Before/After/Completion and in-flight tiles on Completion Doc", () => {
expect(isCompletionSurfaceMedia(file({ id: "1", fileType: "image", purpose: "Before" }))).toBe(
true,
);
expect(
isCompletionSurfaceMedia({
...file({ id: "local-1", fileType: "image", purpose: null }),
uploadStatus: "uploading",
}),
).toBe(true);
});
it("renders a Completion gallery only for Reactive and Emergency work orders", () => {
expect(hasCompletionMediaGallery("Reactive")).toBe(true);
expect(hasCompletionMediaGallery("Emergency")).toBe(true);
expect(hasCompletionMediaGallery("PM")).toBe(false);
expect(hasCompletionMediaGallery("Overdue")).toBe(false);
expect(hasCompletionMediaGallery("")).toBe(false);
});
it("puts Extra photos and videos on Extra Docs when Completion has no gallery", () => {
const photo = file({ id: "10", fileType: "image", purpose: "Extra" });
const video = file({ id: "11", fileType: "video", purpose: "Extra", category: "Video" });
for (const item of [photo, video]) {
expect(isCompletionSurfaceMedia(item, undefined, false)).toBe(false);
expect(isExtrasSurfaceMedia(item, undefined, false)).toBe(true);
}
});
it("ignores stale completion ownership when Completion has no gallery", () => {
const photo = file({ id: "10", fileType: "image", purpose: "Extra" });
const ownership = {
completionOwnedIds: new Set(["10"]),
extraOwnedIds: new Set<string>(),
};
expect(isCompletionSurfaceMedia(photo, ownership, false)).toBe(false);
expect(isExtrasSurfaceMedia(photo, ownership, false)).toBe(true);
});
});