|
1 | 1 | import { describe, expect, it } from "vitest"; |
2 | | -import { applyFontDelivery, applyGraphicDelivery, fontDelivery, graphicDelivery, graphicJobShips } from "./resourceDelivery"; |
| 2 | +import { applyFontDelivery, applyGraphicDelivery, draftGraphicIdentity, fontDelivery, graphicDelivery, graphicJobShips, graphicWayBlocks } from "./resourceDelivery"; |
3 | 3 | import type { ImageProps } from "../registry/image"; |
4 | 4 |
|
5 | 5 | const GFA = "^GFA,4,4,1,00FFFF00"; |
@@ -42,8 +42,8 @@ describe("fontDelivery", () => { |
42 | 42 | }); |
43 | 43 |
|
44 | 44 | describe("graphicDelivery", () => { |
45 | | - it("has no way to choose for an inline ^GF, and reads job while the design ships the bytes", () => { |
46 | | - expect(graphicDelivery(image(null), [entry])).toBeUndefined(); |
| 45 | + it("reads job for an inline ^GF and for a design that ships the bytes", () => { |
| 46 | + expect(graphicDelivery(image(null), [entry])).toBe("job"); |
47 | 47 | expect(graphicDelivery(image(), [entry])).toBe("job"); |
48 | 48 | expect(graphicDelivery(image({ embedInZpl: false }), [entry])).toBe("setup"); |
49 | 49 | expect(graphicDelivery(image({ embedInZpl: false }), undefined)).toBe("printer"); |
@@ -80,7 +80,39 @@ describe("graphicDelivery", () => { |
80 | 80 | expect(graphicJobShips(image({ embedInZpl: false }))).toBe(true); |
81 | 81 | expect(graphicJobShips({ ...image(), _gfaCache: undefined })).toBe(false); |
82 | 82 | expect(graphicJobShips({ ...image(), _gfaCache: "^GFA,4,4,1," })).toBe(false); |
83 | | - expect(graphicJobShips(image(null))).toBe(false); |
| 83 | + }); |
| 84 | + |
| 85 | + it("names an inline graphic only on the way off the job, and never opaque bytes", () => { |
| 86 | + const identity = { device: "R", name: "IMG_1" }; |
| 87 | + expect(applyGraphicDelivery("job", image(null), undefined, identity)).toEqual({ patch: null, setupGraphics: undefined }); |
| 88 | + expect(applyGraphicDelivery("printer", image(null), undefined, identity)).toEqual({ patch: { storedAs: { ...identity, embedInZpl: false } }, setupGraphics: undefined }); |
| 89 | + const provided = applyGraphicDelivery("setup", image(null), undefined, identity); |
| 90 | + expect(provided).toMatchObject({ patch: { storedAs: { ...identity, embedInZpl: false }, _gfaCache: expect.stringContaining("^GFA") }, setupGraphics: [{ path: "R:IMG_1.GRF", gfa: expect.stringContaining("^GFA") }] }); |
| 91 | + expect(applyGraphicDelivery("printer", { ...image(null), rawGf: "^GFA,4,4,1,00FFFF00" }, undefined, identity)).toBeUndefined(); |
| 92 | + }); |
| 93 | + |
| 94 | + it("names why a way is shut, in the order the delivery would refuse it", () => { |
| 95 | + const identity = { device: "R", name: "IMG_1" }; |
| 96 | + expect(graphicWayBlocks(image(null), identity, undefined, null)).toEqual({ job: undefined, setup: undefined }); |
| 97 | + expect(graphicWayBlocks({ ...image(null), _gfaCache: undefined }, identity, undefined, null)).toEqual({ job: "noJobBytes", setup: "noUploadBytes" }); |
| 98 | + expect(graphicWayBlocks({ ...image(), _gfaCache: undefined }, identity, undefined, null)).toEqual({ job: "noUploadBytes", setup: "noUploadBytes" }); |
| 99 | + expect(graphicWayBlocks({ ...image(null), _gfaCache: undefined, rawGf: GFA }, identity, undefined, null)).toEqual({ job: undefined, setup: "opaque", printer: "opaque" }); |
| 100 | + expect(graphicWayBlocks(image(null), identity, [{ path: "R:IMG_1.GRF", gfa: GFA }], null)).toEqual({ job: undefined }); |
| 101 | + expect(graphicWayBlocks(image(null), identity, undefined, "unshippable")).toEqual({ job: undefined, setup: "tooWide" }); |
| 102 | + expect(graphicWayBlocks(image(null), identity, undefined, "tooLarge")).toEqual({ job: undefined, setup: "tooLarge" }); |
| 103 | + }); |
| 104 | + |
| 105 | + it("drafts a printer name no profile entry holds", () => { |
| 106 | + const names = ["IMG_0000", "IMG_1111"]; |
| 107 | + const taken = names.map((n) => ({ path: `R:${n}.GRF`, gfa: GFA })); |
| 108 | + for (let i = 0; i < 50; i++) expect(names).not.toContain(draftGraphicIdentity(taken).name); |
| 109 | + }); |
| 110 | + |
| 111 | + it("ships an inline job from an upright cache or a raw ^GF and from nothing else", () => { |
| 112 | + expect(graphicJobShips(image(null))).toBe(true); |
| 113 | + expect(graphicJobShips({ ...image(null), rotation: "R" })).toBe(false); |
| 114 | + expect(graphicJobShips({ ...image(null), _gfaCache: undefined })).toBe(false); |
| 115 | + expect(graphicJobShips({ ...image(null), _gfaCache: undefined, rawGf: "^GFA,4,4,1,00FFFF00" })).toBe(true); |
84 | 116 | }); |
85 | 117 |
|
86 | 118 | it("refuses setup for bytes the script cannot carry, and does nothing without a printer name", () => { |
|
0 commit comments