Skip to content

Commit

Permalink
Show loading when submitting download cart
Browse files Browse the repository at this point in the history
  • Loading branch information
kennethnym committed May 10, 2023
1 parent 1154804 commit e30aae0
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 e30aae0

Please sign in to comment.