mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-07 06:59:01 +00:00
80 lines
2.4 KiB
TypeScript
80 lines
2.4 KiB
TypeScript
|
|
import { describe, expect, it } from "vitest";
|
||
|
|
import type { MediaFile } from "@/domain/work-orders/types/work-order-media";
|
||
|
|
import {
|
||
|
|
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);
|
||
|
|
});
|
||
|
|
});
|