Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DG download "remove all" button disables once pressed #1177 #1184

Merged
merged 3 commits into from
Mar 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,37 @@ describe('Download cart table component', () => {
expect(wrapper.exists('[data-testid="no-selections-message"]')).toBe(true);
});

it('disables remove all button while request is processing', async () => {
(removeAllDownloadCartItems as jest.Mock).mockImplementation(() => {
return new Promise((resolve) => setTimeout(resolve, 2000));
});

const wrapper = createWrapper();

await act(async () => {
await flushPromises();
wrapper.update();
await flushPromises();
wrapper.update();
});

await act(async () => {
wrapper.find('button#removeAllButton').simulate('click');
await flushPromises();
wrapper.update();
});
expect(
wrapper.find('button#removeAllButton').prop('disabled')
).toBeTruthy();

await act(async () => {
await new Promise((r) => setTimeout(r, 2001));
wrapper.update();
});

expect(wrapper.exists('[data-testid="no-selections-message"]')).toBe(true);
});

it("removes an item when said item's remove button is clicked", async () => {
const wrapper = createWrapper();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
makeStyles,
Theme,
Link,
CircularProgress,
} from '@material-ui/core';
import { RemoveCircle } from '@material-ui/icons';
import {
Expand Down Expand Up @@ -66,6 +67,7 @@ const DownloadCartTable: React.FC<DownloadCartTableProps> = (
const [dataLoaded, setDataLoaded] = React.useState(false);
const [sizesLoaded, setSizesLoaded] = React.useState(true);
const [sizesFinished, setSizesFinished] = React.useState(true);
const [removingAll, setRemovingAll] = React.useState(false);

const fileCountMax = settings.fileCountMax;
const totalSizeMax = settings.totalSizeMax;
Expand Down Expand Up @@ -416,17 +418,24 @@ const DownloadCartTable: React.FC<DownloadCartTableProps> = (
style={{ marginRight: '1em' }}
>
<Grid item>
{/* Request to remove all selections is in progress. To prevent excessive requests, disable button during request */}
<Button
className="tour-download-remove-button"
id="removeAllButton"
variant="contained"
color="primary"
onClick={() =>
disabled={removingAll}
startIcon={removingAll && <CircularProgress size={20} />}
onClick={() => {
setRemovingAll(true);
removeAllDownloadCartItems({
facilityName: settings.facilityName,
downloadApiUrl: settings.downloadApiUrl,
}).then(() => setData([]))
}
}).then(() => {
setData([]);
setRemovingAll(false);
});
}}
>
{t('downloadCart.remove_all')}
</Button>
Expand Down