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

HAI-1814 Fix sending multiple application delete requests #383

Merged
merged 2 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
25 changes: 25 additions & 0 deletions src/domain/application/applicationView/ApplicationView.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { render, screen } from '../../../testUtils/render';
import ApplicationViewContainer from './ApplicationViewContainer';
import { waitForLoadingToFinish } from '../../../testUtils/helperFunctions';
import { server } from '../../mocks/test-server';
import * as applicationApi from '../utils';

test('Correct information about application should be displayed', async () => {
render(<ApplicationViewContainer id={4} />);
Expand Down Expand Up @@ -90,3 +91,27 @@ test('Should not be able to cancel application if it has moved to handling in Al

expect(screen.queryByRole('button', { name: 'Peru hakemus' })).not.toBeInTheDocument();
});

test('Should not send multiple requests if clicking application cancel confirm button many times', async () => {
server.use(
rest.delete('/api/hakemukset/:id', async (req, res, ctx) => {
return res(ctx.delay(200), ctx.status(200));
}),
);

const cancelApplication = jest.spyOn(applicationApi, 'cancelApplication');
const { user } = render(<ApplicationViewContainer id={1} />);

await waitForLoadingToFinish();

await user.click(screen.getByRole('button', { name: 'Peru hakemus' }));
const confirmCancelButton = screen.getByRole('button', { name: 'Vahvista' });
await user.click(confirmCancelButton);
await user.click(confirmCancelButton);
await user.click(confirmCancelButton);
await screen.findByText('Hakemus peruttiin onnistuneesti');

expect(cancelApplication).toHaveBeenCalledTimes(1);

cancelApplication.mockRestore();
});
1 change: 1 addition & 0 deletions src/domain/application/components/ApplicationCancel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export const ApplicationCancel: React.FC<Props> = ({
mainBtnLabel={t('common:confirmationDialog:confirmButton')}
variant="danger"
errorMsg={errorMessage}
isLoading={applicationCancelMutation.isLoading}
/>

<Button
Expand Down
Loading