diff --git a/client/src/api/attachments/attachmentsAPI.spec.ts b/client/src/api/attachments/attachmentsAPI.spec.ts index d7242eb806e55873f54eb4c581f696206b3d3c42..fa7b590fd68753552509e24724c5aa7dfeb97784 100644 --- a/client/src/api/attachments/attachmentsAPI.spec.ts +++ b/client/src/api/attachments/attachmentsAPI.spec.ts @@ -66,7 +66,7 @@ describe("Attachments API tests", () => { }); test("attachment download success", async () => { const mockDownloadAttachment = jest.spyOn(axios, "get").mockReturnValue(Promise.resolve({ data: "asdf" })); - const result = await downloadAttachment("1", "2"); + const result = await downloadAttachment("1", "2", "3"); console.log("what", result); const resultText = await result.text(); expect(resultText).toEqual("asdf"); @@ -74,7 +74,7 @@ describe("Attachments API tests", () => { }); test("attachment download error", async () => { const mockDownloadAttachment = jest.spyOn(axios, "get").mockRejectedValue("some network error"); - await expect(downloadAttachment("1", "2")).rejects.toEqual(Error("attachments.error.network")); + await expect(downloadAttachment("1", "2", "3")).rejects.toEqual(Error("attachments.error.network")); expect(mockDownloadAttachment).toBeCalledTimes(1); }); test("trigger file save for downloaded file", () => { diff --git a/client/src/api/attachments/attachmentsAPI.ts b/client/src/api/attachments/attachmentsAPI.ts index 2c38d8e96a261ec9f891142e87e9a821f07b50a6..c83bbc72d0911f0a7030485f58ceac9e0466f4e7 100644 --- a/client/src/api/attachments/attachmentsAPI.ts +++ b/client/src/api/attachments/attachmentsAPI.ts @@ -69,9 +69,9 @@ export async function uploadAttachment(vorgangId: string, nachrichtEventId: stri * @returns a Promise that resolves on successful download (with the file) and rejects on download * errors (with a localization key as the Error's message) */ -export async function downloadAttachment(nachrichtEventId: string, fileId: string): Promise<Blob> { +export async function downloadAttachment(nachrichtEventId: string, nachrichtId: string, fileId: string): Promise<Blob> { try { - const response = await axios.get(`/api/file/${nachrichtEventId}/${fileId}`, { + const response = await axios.get(`/api/file/${nachrichtEventId}/${nachrichtId}/${fileId}`, { responseType: "blob", timeout: 300000 }); diff --git a/client/src/components/Compositions/MessageBody/MessageBody.test.tsx b/client/src/components/Compositions/MessageBody/MessageBody.test.tsx index 0a926d7c8dd65ca0ef73d197f19f2cab0fa411b0..3590a0aa5fb5bbb4e487a9ace91c5812bba5ada3 100644 --- a/client/src/components/Compositions/MessageBody/MessageBody.test.tsx +++ b/client/src/components/Compositions/MessageBody/MessageBody.test.tsx @@ -28,6 +28,7 @@ describe("Message body tests", () => { render( <MessageBody nachrichtEventId="1" + nachrichtId="2" message="Message of clerk" attachments={[]} ariaLabel="message body" @@ -40,6 +41,7 @@ describe("Message body tests", () => { render( <MessageBody nachrichtEventId="1" + nachrichtId="2" message={`Message with\nline breaks`} attachments={[]} ariaLabel="message body" @@ -54,6 +56,7 @@ describe("Message body tests", () => { render( <MessageBody nachrichtEventId="1" + nachrichtId="2" message="Message of clerk with attachments" attachments={[ { id: "1", fileName: "file1.pdf", fileSize: 512000, contentType: "application/pdf" }, @@ -78,6 +81,7 @@ describe("Message body tests", () => { render( <MessageBody nachrichtEventId="1" + nachrichtId="2" index={2} message={"message"} attachments={[]} diff --git a/client/src/components/Compositions/MessageBody/MessageBody.tsx b/client/src/components/Compositions/MessageBody/MessageBody.tsx index ed7d3a55a0df0248235c0b185cc36e35810c6101..74a2acbe5c7a2decc0200e784706adebf44a4ace 100644 --- a/client/src/components/Compositions/MessageBody/MessageBody.tsx +++ b/client/src/components/Compositions/MessageBody/MessageBody.tsx @@ -30,6 +30,7 @@ const cyIdsPrefix = "message-body-"; interface MessageBodyProps extends React.HTMLAttributes<HTMLDivElement> { nachrichtEventId: string; + nachrichtId: string; message: string; attachments: AttachmentItem[]; // optionally pass an index that will be included in this component's data-cy attributes @@ -45,6 +46,7 @@ interface MessageBodyProps extends React.HTMLAttributes<HTMLDivElement> { */ export function MessageBody({ nachrichtEventId, + nachrichtId, message, attachments, index, @@ -73,6 +75,7 @@ export function MessageBody({ {attachments && !!attachments.length && ( <AttachmentList nachrichtEventId={nachrichtEventId} + nachrichtId={nachrichtId} attachments={attachments} closeIconLabel={closeIconLabel} /> diff --git a/client/src/components/Data Display/AttachmentList/AttachmentList.test.tsx b/client/src/components/Data Display/AttachmentList/AttachmentList.test.tsx index 997f9f1fbbe0be98d6be62973c7a329add167c72..4499e1a36c16d9ffc6bff4d98a59ea0e9947b69c 100644 --- a/client/src/components/Data Display/AttachmentList/AttachmentList.test.tsx +++ b/client/src/components/Data Display/AttachmentList/AttachmentList.test.tsx @@ -28,6 +28,7 @@ describe("Attachment tests", () => { render( <AttachmentList nachrichtEventId="1" + nachrichtId="2" attachments={[{ id: "1", fileName: "file.pdf", fileSize: 1572864, contentType: "application/pdf" }]} /> ); @@ -40,6 +41,7 @@ describe("Attachment tests", () => { render( <AttachmentList nachrichtEventId="1" + nachrichtId="2" attachments={[{ id: "2", fileName: "file.pdf", fileSize: 1572864, contentType: "application/pdf" }]} /> ); @@ -51,6 +53,7 @@ describe("Attachment tests", () => { render( <AttachmentList nachrichtEventId="1" + nachrichtId="2" attachments={[ { id: "3", @@ -69,6 +72,7 @@ describe("Attachment tests", () => { render( <AttachmentList nachrichtEventId="1" + nachrichtId="2" attachments={[ { id: "4", @@ -87,6 +91,7 @@ describe("Attachment tests", () => { render( <AttachmentList nachrichtEventId="1" + nachrichtId="2" attachments={[{ id: "5", fileName: "file.png", fileSize: 1572864, contentType: "image/png" }]} /> ); @@ -98,6 +103,7 @@ describe("Attachment tests", () => { render( <AttachmentList nachrichtEventId="1" + nachrichtId="2" attachments={[ { id: "6", fileName: "file1.png", fileSize: 1572864, contentType: "image/png" }, { id: "7", fileName: "file2.png", fileSize: 1572864, contentType: "image/png" }, @@ -119,7 +125,7 @@ describe("Attachment tests", () => { const onRemove = (fileId: string) => { attachments = attachments.filter((a) => a.id !== fileId); }; - render(<AttachmentList nachrichtEventId="1" attachments={attachments} onRemove={onRemove} />); + render(<AttachmentList nachrichtEventId="1" nachrichtId="2" attachments={attachments} onRemove={onRemove} />); fireEvent.click(screen.getAllByTestId("close").at(0)!!); expect(attachments).toHaveLength(1); @@ -134,7 +140,7 @@ describe("Attachment tests", () => { const onRemove = (fileId: string) => { attachments = attachments.filter((a) => a.id !== fileId); }; - render(<AttachmentList nachrichtEventId="1" attachments={attachments} onRemove={onRemove} />); + render(<AttachmentList nachrichtEventId="1" nachrichtId="2" attachments={attachments} onRemove={onRemove} />); fireEvent.keyDown(screen.getAllByTestId("close").at(0)!!, { key: "Enter", code: 13, charCode: 13 }); expect(attachments).toHaveLength(1); diff --git a/client/src/components/Data Display/AttachmentList/AttachmentList.tsx b/client/src/components/Data Display/AttachmentList/AttachmentList.tsx index efea1d4634ba8a47728f989dcf3558547afccb6d..6caedded21dd772b95595bfa7a1058ba4910e958 100644 --- a/client/src/components/Data Display/AttachmentList/AttachmentList.tsx +++ b/client/src/components/Data Display/AttachmentList/AttachmentList.tsx @@ -44,6 +44,8 @@ interface AttachmentListProps { attachments: AttachmentItem[]; /** The id of the nachricht event the nachricht header belongs to */ nachrichtEventId?: string; + /** The id of the nachricht the attachment belongs to */ + nachrichtId?: string; /** If this function is defined the attachments can be removed. */ onRemove?: (fileName: string) => void; /** Accessibility label for the close icon */ @@ -53,6 +55,7 @@ interface AttachmentListProps { interface AttachmentProps extends React.HTMLAttributes<HTMLDivElement> { nachrichtEventId?: string; + nachrichtId?: string; attachment: AttachmentItem; onRemove?: (fileId: string) => void; hasBorder?: boolean; @@ -78,6 +81,7 @@ export function AttachmentList(props: AttachmentListProps) { key={attachment.fileName} closeIconLabel={props.closeIconLabel} nachrichtEventId={props.nachrichtEventId} + nachrichtId={props.nachrichtId} disableDeleteButton={props.disableDeleteButton || attachment.isUploading} /> ))} @@ -97,6 +101,7 @@ function Attachment({ hasBorder, closeIconLabel, nachrichtEventId, + nachrichtId, disableDeleteButton, ...props }: AttachmentProps) { @@ -148,13 +153,13 @@ function Attachment({ return ( <> - {nachrichtEventId ? ( + {nachrichtEventId && nachrichtId ? ( <StyledLink $disabled={isDownloading} onClick={() => { if (!isDownloading) { setIsDownloading(true); - downloadAttachment(nachrichtEventId, attachment.id) + downloadAttachment(nachrichtEventId, nachrichtId, attachment.id) .then((blob) => saveDownloadedAttachmentToFile(blob, attachment.fileName)) .catch(() => {}) // TODO: no error handling is specified .finally(() => setIsDownloading(false)); diff --git a/client/src/routes/detail/DetailPage.tsx b/client/src/routes/detail/DetailPage.tsx index c27753b5995a9ffad307376eaaec157da7761c7c..a771e989eabf8e550d12df0f73c7eae949f1ba14 100644 --- a/client/src/routes/detail/DetailPage.tsx +++ b/client/src/routes/detail/DetailPage.tsx @@ -226,6 +226,7 @@ export function DetailPage() { </GridDiv> <MessageBody nachrichtEventId={selectedRueckfrage.nachricht.nachrichtEventId} + nachrichtId={selectedRueckfrage.id!} closeIconLabel={translate("common.close")} data-cy={`${cyIdsPrefix}clerk-message`} ariaLabel={translate("detailPage.messageBody")} @@ -240,6 +241,7 @@ export function DetailPage() { </Heading> <MessageBody nachrichtEventId={response.nachrichtEventId} + nachrichtId={response.id} closeIconLabel={translate("common.close")} data-cy={`${cyIdsPrefix}user-message-${i}`} ariaLabel={translate("detailPage.messageBody")}