Skip to content

Commit

Permalink
CRDCDH-882 Change props to Submission
Browse files Browse the repository at this point in the history
  • Loading branch information
amattu2 committed Mar 21, 2024
1 parent 5f38817 commit 60646c4
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 15 deletions.
85 changes: 78 additions & 7 deletions src/components/DataSubmissions/ExportValidationButton.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,29 @@ const TestParent: FC<ParentProps> = ({ 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<QCResult, "submissionID"> = {
batchID: "",
type: '',
Expand All @@ -39,7 +62,7 @@ describe('ExportValidationButton cases', () => {
it('should not have accessibility violations', async () => {
const { container } = render(
<TestParent mocks={[]}>
<ExportValidationButton submissionId="example-sub-id" fields={{}} />
<ExportValidationButton submission={{ ...baseSubmission, _id: "example-sub-id" }} fields={{}} />
</TestParent>
);

Expand All @@ -49,7 +72,7 @@ describe('ExportValidationButton cases', () => {
it('should render without crashing', () => {
const { getByText } = render(
<TestParent mocks={[]}>
<ExportValidationButton submissionId="example-sub-id" fields={{}} />
<ExportValidationButton submission={{ ...baseSubmission, _id: "test-rendering-id" }} fields={{}} />
</TestParent>
);

Expand Down Expand Up @@ -82,7 +105,7 @@ describe('ExportValidationButton cases', () => {

const { getByText } = render(
<TestParent mocks={mocks}>
<ExportValidationButton submissionId={submissionID} fields={{}} />
<ExportValidationButton submission={{ ...baseSubmission, _id: submissionID }} fields={{}} />
</TestParent>
);

Expand All @@ -91,6 +114,54 @@ describe('ExportValidationButton cases', () => {
});
});

it.each<Submission>([
{ ...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<SubmissionQCResultsResp>[] = [{
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(
<TestParent mocks={mocks}>
<ExportValidationButton submission={{ ...baseSubmission, _id: submissionID }} fields={{}} />
</TestParent>
);

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";

Expand Down Expand Up @@ -137,7 +208,7 @@ describe('ExportValidationButton cases', () => {

const { getByText } = render(
<TestParent mocks={mocks}>
<ExportValidationButton submissionId={submissionID} fields={fields} />
<ExportValidationButton submission={{ ...baseSubmission, _id: submissionID }} fields={fields} />
</TestParent>
);

Expand Down Expand Up @@ -171,7 +242,7 @@ describe('ExportValidationButton cases', () => {

const { getByText } = render(
<TestParent mocks={mocks}>
<ExportValidationButton submissionId={submissionID} fields={{}} />
<ExportValidationButton submission={{ ...baseSubmission, _id: submissionID }} fields={{}} />
</TestParent>
);

Expand Down Expand Up @@ -205,7 +276,7 @@ describe('ExportValidationButton cases', () => {

const { getByText } = render(
<TestParent mocks={mocks}>
<ExportValidationButton submissionId={submissionID} fields={{}} />
<ExportValidationButton submission={{ ...baseSubmission, _id: submissionID }} fields={{}} />
</TestParent>
);

Expand Down Expand Up @@ -248,7 +319,7 @@ describe('ExportValidationButton cases', () => {

const { getByText } = render(
<TestParent mocks={mocks}>
<ExportValidationButton submissionId={submissionID} fields={{}} />
<ExportValidationButton submission={{ ...baseSubmission, _id: submissionID }} fields={{}} />
</TestParent>
);

Expand Down
18 changes: 10 additions & 8 deletions src/components/DataSubmissions/ExportValidationButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<Props> = ({ submissionId, fields, ...buttonProps }: Props) => {
export const ExportValidationButton: React.FC<Props> = ({ submission, fields, ...buttonProps }: Props) => {
const { enqueueSnackbar } = useSnackbar();
const [loading, setLoading] = useState<boolean>(false);

const [submissionQCResults] = useLazyQuery<SubmissionQCResultsResp>(SUBMISSION_QC_RESULTS, {
variables: { id: submissionId },
context: { clientName: 'backend' },
fetchPolicy: 'cache-and-network',
});
Expand All @@ -45,7 +41,7 @@ export const ExportValidationButton: React.FC<Props> = ({ submissionId, fields,

const { data: d, error } = await submissionQCResults({
variables: {
id: submissionId,
id: submission?._id,
sortDirection: "asc",
orderBy: "displayID",
first: 10000, // TODO: change to -1
Expand All @@ -61,6 +57,12 @@ export const ExportValidationButton: React.FC<Props> = ({ 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 = [];
Expand Down

0 comments on commit 60646c4

Please sign in to comment.