mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-03 01:03:21 +00:00
109 lines
3.6 KiB
TypeScript
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);
|
|
});
|
|
});
|