mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-02 15:33:12 +00:00
Keep Extra uploads uncategorized until the dispatcher picks Aveta. Drive the shield from hasAvetaDocument after reopen.
51 lines
1.8 KiB
TypeScript
51 lines
1.8 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import type { MediaFile } from "@/domain/work-orders/types/work-order-media";
|
|
import {
|
|
hasExplicitAvetaFile,
|
|
isAvetaDocumentAttached,
|
|
resolveExtraDocCategory,
|
|
} from "@/domain/work-orders/utils/extra-docs-aveta";
|
|
|
|
function file(category: MediaFile["category"]): MediaFile {
|
|
return {
|
|
id: "1",
|
|
name: "doc.pdf",
|
|
fileType: "pdf",
|
|
url: "blob:1",
|
|
category,
|
|
};
|
|
}
|
|
|
|
describe("extra-docs-aveta", () => {
|
|
it("does not label the first extra file as Aveta when the WO is flagged and none is Aveta", () => {
|
|
const files = [file("Photo"), file("Report")];
|
|
expect(resolveExtraDocCategory(files[0])).toBe("Photo");
|
|
expect(resolveExtraDocCategory(files[1])).toBe("Report");
|
|
expect(hasExplicitAvetaFile(files)).toBe(false);
|
|
});
|
|
|
|
it("keeps an explicit Aveta file and does not relabel others", () => {
|
|
const files = [file("Photo"), file("Aveta")];
|
|
expect(resolveExtraDocCategory(files[0])).toBe("Photo");
|
|
expect(resolveExtraDocCategory(files[1])).toBe("Aveta");
|
|
expect(hasExplicitAvetaFile(files)).toBe(true);
|
|
});
|
|
|
|
it("does not label extras as Aveta when the WO is not flagged", () => {
|
|
const files = [file("Photo")];
|
|
expect(resolveExtraDocCategory(files[0])).toBe("Photo");
|
|
expect(hasExplicitAvetaFile(files)).toBe(false);
|
|
});
|
|
|
|
it("treats purpose Aveta as an explicit Aveta file", () => {
|
|
const aveta: MediaFile = { ...file("Other"), purpose: "Aveta" };
|
|
expect(resolveExtraDocCategory(aveta)).toBe("Aveta");
|
|
expect(hasExplicitAvetaFile([aveta])).toBe(true);
|
|
expect(isAvetaDocumentAttached(false, [aveta])).toBe(true);
|
|
});
|
|
|
|
it("uses hasAvetaDocument from the board row after reopen", () => {
|
|
expect(isAvetaDocumentAttached(true, [])).toBe(true);
|
|
expect(isAvetaDocumentAttached(false, [file("Other")])).toBe(false);
|
|
});
|
|
});
|