feat(documents): open a PDF or image original in a new browser tab

The document sheet gains an Open in new tab action for the types the
browser renders itself (PDF, JPEG, PNG, WebP, GIF), so a long report
gets the browser's own zoom and search instead of the small preview. It
opens the object URL the sheet already fetched through the app transport:
a plain navigation to the serve route carries no record-session
assertion and would be refused inside a shared record. Every other type
keeps the download only, and the serve route's matrix now pins SVG and
HTML to attachment as well.
This commit is contained in:
Marc-André Bombeck committed 2026-10-11 12:37:57 +02:00
1 parent fca1260b20
commit 12a8ab7c63
10 files changed
+95 -2

No files matched your search

@@ -81,3 +81,41 @@ describe("the detail sheet's original-document transport", () => {
);
});
});
/**
* "Open in new tab" hands the browser the types it renders itself, so a long
* report gets the browser's zoom and search. It must open the object URL the
* sheet already holds (a bare navigation to the route carries no record-session
* assertion and is refused once the session has been inside a shared record),
* and it must never appear for a type outside the inline serving class.
*/
describe("the detail sheet's open-in-new-tab control", () => {
const control = SHEET.slice(
SHEET.indexOf("function DocumentOpenInTabButton("),
SHEET.indexOf("/** Inline preview for Class A documents"),
);
it("exists", () => {
expect(control.length).toBeGreaterThan(0);
expect(SHEET).toMatch(/<DocumentOpenInTabButton\s/);
});
it("renders only for the inline serving class", () => {
expect(SHEET).toMatch(
/doc\.servingClass === "inline" \? \(\s*\n\s*<DocumentOpenInTabButton\s+readyUrl=\{inlineSrc\}/,
);
expect([...SHEET.matchAll(/<DocumentOpenInTabButton\s/g)]).toHaveLength(1);
});
it("opens the fetched object URL, never the route, without an opener", () => {
expect(control).toContain('window.open(readyUrl, "_blank", "noopener")');
expect(control).not.toContain("/api/documents");
});
it("is disabled until the bytes are in hand, and when they failed", () => {
expect(control).toMatch(/disabled=\{readyUrl === null \|\| unavailable\}/);
expect(SHEET).toMatch(
/<DocumentOpenInTabButton\s+readyUrl=\{inlineSrc\}\s+unavailable=\{inlineFailed\}/,
);
});
});