Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/client/reader/export-dialog.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,25 @@ it("shows a failed local read and retries it without reopening or generating twi
expect(io.prepare).toHaveBeenCalledOnce();
});

it("uses the primary action to retry a failed PDF preparation", async () => {
io.read.mockResolvedValue(state);
io.prepare.mockReturnValueOnce({ promise: Promise.reject(new Error("PDF read failed")), destroy: vi.fn() });
render(<ExportDialog workspace={workspace} versionId="v1" fileName="score.pdf" authenticatedUserId="reader" onClose={() => {}} />);
expect(await screen.findByRole("alert")).toHaveTextContent("无法准备 PDF");
const retry = screen.getByRole("button", { name: "重试" });
expect(retry).toHaveClass("primary-button");
expect(screen.queryByRole("button", { name: "分享 PDF" })).not.toBeInTheDocument();
fireEvent.click(retry);
await waitFor(() => expect(screen.getByRole("button", { name: "下载 PDF" })).toBeEnabled());
expect(screen.queryByRole("alert")).not.toBeInTheDocument();
expect(io.prepare).toHaveBeenCalledTimes(2);
});

it("explains an invalidated owner instead of showing indefinite preparation", async () => {
io.read.mockRejectedValue(new LocalWorkspaceOwnerChangedError());
render(<ExportDialog workspace={workspace} versionId="v1" fileName="score.pdf" authenticatedUserId="reader" onClose={() => {}} />);
expect(await screen.findByRole("alert")).toHaveTextContent("登录状态已变化");
expect(screen.getByRole("button", { name: "分享 PDF" })).toBeDisabled();
expect(screen.queryByRole("button", { name: "分享 PDF" })).not.toBeInTheDocument();
expect(io.generate).not.toHaveBeenCalled();
});

Expand Down
13 changes: 10 additions & 3 deletions src/client/reader/export-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ function ExportDialogContent(props: Props) {
if (!current) return <LibraryTaskLoading title={t("sharePdf")} size="tall" onClose={onClose} />;
const { session, snapshot: { prepared, layers, selected, includeNotes, file, message, readError, sharing, shareFailed } } = current;
const canShare = file ? canSharePdf(file) : false;
const needsRetry = !file && Boolean(readError || message);
const primaryLabel = needsRetry ? t(readError ? "retryRead" : "retry")
: !file ? t("preparing") : sharing ? t("sharing") : t(canShare ? "sharePdf" : "downloadPdf");
const { shared, personal, memberShares } = groupReaderLayers(layers);
const layerGroups = [
{ id: "shared", title: t("sharedLayer"), layers: shared },
Expand Down Expand Up @@ -52,13 +55,17 @@ function ExportDialogContent(props: Props) {
</div>}
</>}
{includeNotes && selected.some(id => !layers.some(layer => layer.id === id)) && <p role="alert">{t("unavailableExportLayers")}<Button isDisabled={sharing} onPress={session.removeUnavailableLayers}>{t("removeUnavailableLayers")}</Button></p>}
{readError && <p role="alert">{readError}<Button className="text-button" onPress={session.retry}>{t("retryRead")}</Button></p>}
{message && <p role="alert">{message}{!file && <Button className="text-button" onPress={session.retry}>{t("retry")}</Button>}</p>}
{readError && <p role="alert">{readError}</p>}
{message && <p role="alert">{message}</p>}
{file && !sharing && <p className="export-help" role="status">{canShare ? t("preparedPdfShare") : t("preparedPdfDownload")}</p>}
<div className="export-actions">
<Button className="secondary-button" isDisabled={sharing} onPress={onClose}>{t("cancel")}</Button>
{file && canShare && shareFailed && <Button className="secondary-button" isDisabled={sharing} onPress={() => downloadPdf(file)}>{t("downloadPdf")}</Button>}
<Button className="primary-button" isDisabled={sharing || !file} onPress={() => { if (!file) return; if (canShare) void session.share(); else downloadPdf(file); }}>{!file ? message || readError ? t("sharePdf") : t("preparing") : sharing ? t("sharing") : file ? canShare ? t("sharePdf") : t("downloadPdf") : t("sharePdf")}</Button>
<Button className="primary-button" isDisabled={sharing || (!file && !needsRetry)} onPress={() => {
if (needsRetry) session.retry();
else if (file && canShare) void session.share();
else if (file) downloadPdf(file);
}}>{primaryLabel}</Button>
</div>
</div></LibraryTaskDialog>;
}
Expand Down
3 changes: 2 additions & 1 deletion visual-report/pdf-share.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ test("PDF generation separates sharing activation, preserves cancelled files, an
await localDatabase.system.put({ key: "local-workspace:active-owner", value: "user:other" });
});
await expect(dialog.getByRole("alert")).toContainText("登录状态已变化");
await expect(dialog.getByRole("button", { name: "分享 PDF", exact: true })).toBeDisabled();
await expect(dialog.getByRole("button", { name: "分享 PDF", exact: true })).toHaveCount(0);
await expect(dialog.getByRole("button", { name: "下载 PDF", exact: true })).toHaveCount(0);

});

Expand Down