diff --git a/src/components/DataSubmissions/ExportValidationButton.test.tsx b/src/components/DataSubmissions/ExportValidationButton.test.tsx index ec4da0a8..c8d21ef8 100644 --- a/src/components/DataSubmissions/ExportValidationButton.test.tsx +++ b/src/components/DataSubmissions/ExportValidationButton.test.tsx @@ -19,6 +19,29 @@ const TestParent: FC = ({ mocks, children } : ParentProps) => ( ); describe('ExportValidationButton cases', () => { + const baseSubmission: Submission = { + _id: '', + name: '', + submitterID: '', + submitterName: '', + organization: null, + dataCommons: '', + modelVersion: '', + studyAbbreviation: '', + dbGaPID: '', + bucketName: '', + rootPath: '', + status: 'New', + metadataValidationStatus: 'Error', + fileValidationStatus: 'Error', + fileErrors: [], + history: [], + conciergeName: '', + conciergeEmail: '', + createdAt: '', + updatedAt: '' + }; + const baseQCResult: Omit = { batchID: "", type: '', @@ -39,7 +62,7 @@ describe('ExportValidationButton cases', () => { it('should not have accessibility violations', async () => { const { container } = render( - + ); @@ -49,7 +72,7 @@ describe('ExportValidationButton cases', () => { it('should render without crashing', () => { const { getByText } = render( - + ); @@ -82,7 +105,7 @@ describe('ExportValidationButton cases', () => { const { getByText } = render( - + ); @@ -91,6 +114,54 @@ describe('ExportValidationButton cases', () => { }); }); + it.each([ + { ...baseSubmission, _id: "example-sub-id" }, + { ...baseSubmission, _id: "example-sub-id-2" }, + { ...baseSubmission, _id: "example-sub-id-3" }, + ])("should name the export file as [TODO]", async (submission) => { + // TODO: Implement per requirements + expect(false).toBeTruthy(); + }); + + it('should alert the user if there are no QC Results to export', async () => { + const submissionID = "example-no-results-to-export-id"; + + const mocks: MockedResponse[] = [{ + request: { + query: SUBMISSION_QC_RESULTS, + variables: { + id: submissionID, + sortDirection: "asc", + orderBy: "displayID", + first: 10000, // TODO: change to -1 + offset: 0, + }, + }, + result: { + data: { + submissionQCResults: { + total: 0, + results: [] + }, + }, + }, + }]; + + const { getByText } = render( + + + + ); + + act(() => { + fireEvent.click(getByText('Download QC Results')); + }); + + await waitFor(() => { + expect(mockEnqueue).toHaveBeenCalledWith("There are no validation results to export.", { variant: "error" }); + }); + }); + it('should call the field value callback function for each field', async () => { const submissionID = "formatter-callback-sub-id"; @@ -137,7 +208,7 @@ describe('ExportValidationButton cases', () => { const { getByText } = render( - + ); @@ -171,7 +242,7 @@ describe('ExportValidationButton cases', () => { const { getByText } = render( - + ); @@ -205,7 +276,7 @@ describe('ExportValidationButton cases', () => { const { getByText } = render( - + ); @@ -248,7 +319,7 @@ describe('ExportValidationButton cases', () => { const { getByText } = render( - + ); diff --git a/src/components/DataSubmissions/ExportValidationButton.tsx b/src/components/DataSubmissions/ExportValidationButton.tsx index edb9a774..62e0d4ee 100644 --- a/src/components/DataSubmissions/ExportValidationButton.tsx +++ b/src/components/DataSubmissions/ExportValidationButton.tsx @@ -9,11 +9,9 @@ import { downloadBlob, unpackQCResultSeverities } from '../../utils'; export type Props = { /** - * The `_id` (uuid) of the submission to build the QC Results for - * - * @example 9f9c5d6b-5ddb-4a02-8bd6-7bf0c15a169a + * The full Data Submission object to export validation results for */ - submissionId: Submission["_id"]; + submission: Submission; /** * The K:V pair of the fields that should be exported where * `key` is the column header and `value` is a function @@ -27,15 +25,13 @@ export type Props = { /** * Provides the button and supporting functionality to export the validation results of a submission. * - * @param submissionId The ID of the submission to export validation results for. * @returns {React.FC} The export validation button. */ -export const ExportValidationButton: React.FC = ({ submissionId, fields, ...buttonProps }: Props) => { +export const ExportValidationButton: React.FC = ({ submission, fields, ...buttonProps }: Props) => { const { enqueueSnackbar } = useSnackbar(); const [loading, setLoading] = useState(false); const [submissionQCResults] = useLazyQuery(SUBMISSION_QC_RESULTS, { - variables: { id: submissionId }, context: { clientName: 'backend' }, fetchPolicy: 'cache-and-network', }); @@ -45,7 +41,7 @@ export const ExportValidationButton: React.FC = ({ submissionId, fields, const { data: d, error } = await submissionQCResults({ variables: { - id: submissionId, + id: submission?._id, sortDirection: "asc", orderBy: "displayID", first: 10000, // TODO: change to -1 @@ -61,6 +57,12 @@ export const ExportValidationButton: React.FC = ({ submissionId, fields, return; } + if (!d?.submissionQCResults?.results.length) { + enqueueSnackbar("There are no validation results to export.", { variant: "error" }); + setLoading(false); + return; + } + try { const unpacked = unpackQCResultSeverities(d.submissionQCResults.results); const csvArray = [];