diff --git a/ui-participant/src/hub/documents/DocumentLibrary.test.tsx b/ui-participant/src/hub/documents/DocumentLibrary.test.tsx
index 70a17f1256..a15bedc39d 100644
--- a/ui-participant/src/hub/documents/DocumentLibrary.test.tsx
+++ b/ui-participant/src/hub/documents/DocumentLibrary.test.tsx
@@ -1,7 +1,7 @@
import { asMockedFn, MockI18nProvider, setupRouterTest, mockParticipantFile } from '@juniper/ui-core'
import { usePortalEnv } from 'providers/PortalProvider'
-import { mockUsePortalEnv } from 'test-utils/test-portal-factory'
-import { render, screen, waitFor } from '@testing-library/react'
+import { mockPortal, mockUsePortalEnv } from 'test-utils/test-portal-factory'
+import { act, render, screen, waitFor } from '@testing-library/react'
import React from 'react'
import DocumentLibrary from './DocumentLibrary'
import { useActiveUser } from 'providers/ActiveUserProvider'
@@ -16,7 +16,8 @@ jest.mock('providers/ActiveUserProvider', () => ({
}))
jest.mock('api/api', () => ({
- listParticipantFiles: jest.fn()
+ listParticipantFiles: jest.fn(),
+ getPortal: jest.fn()
}))
beforeEach(() => {
@@ -58,6 +59,11 @@ describe('DocumentLibrary', () => {
expect(screen.getByText('file1.pdf')).toBeInTheDocument()
})
+ await act(async () => {
+ screen.getByText('Options').click()
+ })
+
+ expect(screen.getByText('Delete')).toBeInTheDocument()
expect(screen.getByText('{documentDownloadButton}')).toBeInTheDocument()
})
@@ -106,4 +112,71 @@ describe('DocumentLibrary', () => {
//note: this is looking at the i18n key for the task name
expect(screen.getByText('{researchSurvey1:1}')).toBeInTheDocument()
})
+
+ it('allows deleting documents that dont have any associated answers', async () => {
+ asMockedFn(Api.listParticipantFiles).mockResolvedValue([
+ mockParticipantFile('file1.pdf')
+ ])
+
+ asMockedFn(Api.getPortal).mockResolvedValue(mockPortal())
+
+ const { RoutedComponent } = setupRouterTest(
+
+ )
+ render(RoutedComponent)
+
+ await waitFor(() => {
+ expect(screen.getByText('file1.pdf')).toBeInTheDocument()
+ })
+
+ await act(async () => {
+ screen.getByText('Options').click()
+ })
+
+ await act(async () => {
+ screen.getByText('Delete').click()
+ })
+
+ await waitFor(() => {
+ expect(screen.queryByText('Are you sure you want to delete this document?', { exact: false })).toBeInTheDocument()
+ })
+ })
+
+ it('shows a warning message when trying to delete a document that has associated answers', async () => {
+ asMockedFn(Api.listParticipantFiles).mockResolvedValue([
+ mockParticipantFile('file1.pdf', [{
+ format: 'FILE_NAME',
+ surveyVersion: 1,
+ stringValue: 'file1.pdf',
+ questionStableId: 'question1',
+ surveyResponseId: 'taskId1'
+ }])
+ ])
+
+ asMockedFn(Api.getPortal).mockResolvedValue(mockPortal())
+
+ const { RoutedComponent } = setupRouterTest(
+
+ )
+ render(RoutedComponent)
+
+ await waitFor(() => {
+ expect(screen.getByText('file1.pdf')).toBeInTheDocument()
+ })
+
+ await act(async () => {
+ screen.getByText('Options').click()
+ })
+
+ await act(async () => {
+ screen.getByText('Delete').click()
+ })
+
+ await waitFor(() => {
+ expect(screen.queryByText('' +
+ 'This document is currently shared in response to at least one survey. ' +
+ 'Please remove it from the survey response(s) before deleting it.')
+ ).toBeInTheDocument()
+ })
+ })
})
diff --git a/ui-participant/src/hub/documents/DocumentLibrary.tsx b/ui-participant/src/hub/documents/DocumentLibrary.tsx
index ff5a38a0c0..4be19a50ba 100644
--- a/ui-participant/src/hub/documents/DocumentLibrary.tsx
+++ b/ui-participant/src/hub/documents/DocumentLibrary.tsx
@@ -203,7 +203,9 @@ const FileOptionsDropdown = ({ studyEnvParams, participantFile, enrollee, loadDo
onHide={() => setShowConfirmDelete(false)} size={'lg'} animation={true}>
- Are you sure?
+
+ {participantFile.associatedAnswers.length === 0 ? 'Are you sure?' : 'This document is in use'}
+
diff --git a/ui-participant/src/test-utils/test-portal-factory.tsx b/ui-participant/src/test-utils/test-portal-factory.tsx
index 37e41b6dae..3134fbf92e 100644
--- a/ui-participant/src/test-utils/test-portal-factory.tsx
+++ b/ui-participant/src/test-utils/test-portal-factory.tsx
@@ -108,7 +108,8 @@ export const mockLocalSiteContent = (): LocalSiteContent => {
landingPage: mockHtmlPage(),
navLogoCleanFileName: 'navLogo.png',
navLogoVersion: 1,
- languageTextOverrides: []
+ languageTextOverrides: [],
+ primaryBrandColor: '#000000'
}
}