Skip to content

Commit

Permalink
Merge pull request #1525 from ral-facilities/enhancement/download-pro…
Browse files Browse the repository at this point in the history
…gress-indicator

Shows loadings status when submitting download card in download confirm dialog
  • Loading branch information
kennethnym authored May 15, 2023
2 parents 1154804 + e30aae0 commit 945f2de
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/datagateway-download/public/res/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@
"confirmation_download_name": "Download Name",
"confirmation_access_method": "Access Method",
"confirmation_email": "Email Address",
"view_my_downloads": "View My Downloads"
"view_my_downloads": "View My Downloads",
"submitting_cart": "Preparing..."
},
"downloadCart": {
"name": "Name",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,29 @@ describe('DownloadConfirmDialog', () => {

expect(closeFunction).toHaveBeenCalled();
});

it('shows loading status when submitting cart', async () => {
(submitCart as jest.Mock).mockReturnValue(
new Promise((_) => {
// never resolve the promise to simulate loading state
})
);

renderWrapper(100, false, true);

// click on download button to begin download
await user.click(
await screen.findByRole('button', {
name: 'downloadConfirmDialog.download',
})
);

const downloadButton = await screen.findByRole('button', {
name: 'downloadConfirmDialog.submitting_cart',
});
expect(downloadButton).toBeInTheDocument();
expect(downloadButton).toBeDisabled();
});
});

describe('DownloadConfirmDialog - renders the estimated download speed/time table with varying values', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ const DownloadConfirmDialog: React.FC<DownloadConfirmDialogProps> = (
const {
data: downloadId,
mutate: submitCart,
isLoading: isSubmittingCart,
isSuccess: isCartSubmittedSuccessfully,
isError: hasSubmitCartFailed,
reset: resetSubmitCartMutation,
Expand Down Expand Up @@ -558,13 +559,16 @@ const DownloadConfirmDialog: React.FC<DownloadConfirmDialogProps> = (
!emailValid ||
(!downloadTypeInfoMap?.has(selectedMethod) ?? true) ||
downloadTypeInfoMap?.get(selectedMethod)?.disabled ||
methodsUnavailable
methodsUnavailable ||
isSubmittingCart
}
onClick={processDownload}
color="primary"
variant="contained"
>
{t('downloadConfirmDialog.download')}
{isSubmittingCart
? t('downloadConfirmDialog.submitting_cart')
: t('downloadConfirmDialog.download')}
</Button>
</DialogActions>
</div>
Expand Down

0 comments on commit 945f2de

Please sign in to comment.