Skip to content

Commit

Permalink
feat: disable handle button until CSV has been downloaded (hl-1433) (#…
Browse files Browse the repository at this point in the history
…3407)

* feat: do not allow for handling if csv is not downloaded

* test: make handle button active by downloading csv first
  • Loading branch information
sirtawast authored Oct 14, 2024
1 parent 415e2fe commit 20f005e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ const recoveryEndDate = Selector('#recovery-end-date');
const accordionItemTitle = 'div[role="heading"]';
const recoveryStartDateError = '#recovery-start-date-error';
const recoveryEndDateError = '#recovery-end-date-error';
const csvButton = Selector(
'button[data-testid="button-download-alteration-csv"]'
);
const handleButton = Selector('button').withText(
fi.applications.alterations.handling.actions.handle
);
Expand Down Expand Up @@ -110,16 +113,19 @@ test('Handler creates another alteration and tries to handle it with errors', as
)
);

// Attempt to submit the empty form, verify that validation fails
await t.click(handleButton);
// Verify that validation fails
await expectHandleButtonDisabled(t);
await t.click(csvButton);
await t.click(handleButton);

await t
.expect(
Selector('div').withText(
fi.applications.alterations.handling.error.calculationOutOfDate
).exists
)
.ok();

await t
.expect(
Selector('#recovery-justification-error').withText(
Expand Down Expand Up @@ -351,7 +357,9 @@ test('Handler handles the alteration from the last test properly', async (t: Tes
await t.typeText('#recovery-justification', 'Selvä kuin pläkki');

// Submit the handling form
await t.click(csvButton);
await t.click(handleButton);

const modal = Selector('div[role="dialog"]').withText(
fi.applications.alterations.handling.confirmation.recoverable.title
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const AlterationCsvButton: React.FC<AlterationCsvProps> = ({

return (
<Button
data-testid="button-download-alteration-csv"
theme={theme}
variant={secondary ? 'secondary' : 'primary'}
iconLeft={<IconDownload />}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ type Props = {
onClose: () => void;
};

const handleAlterationCsvDownload = (): void => {
// TODO add any necessary logic here after the CSV download
};

const AlterationHandlingForm = ({
application,
alteration,
Expand Down Expand Up @@ -83,6 +79,12 @@ const AlterationHandlingForm = ({
const [isMessagesDrawerVisible, toggleMessagesDrawerVisibility] =
useState<boolean>(false);

const [isCSVDownloadDone, setIsCSVDownloadDone] = useState<boolean>(false);

const handleAlterationCsvDownload = (): void => {
setIsCSVDownloadDone(true);
};

const getErrorMessage = (fieldName: string): string | undefined =>
getErrorText(formik.errors, formik.touched, fieldName, t, isSubmitted);

Expand Down Expand Up @@ -287,7 +289,9 @@ const AlterationHandlingForm = ({
onClick={openConfirmationModal}
theme="coat"
iconLeft={<IconCheck />}
disabled={isSubmitting || (isSubmitted && hasErrors)}
disabled={
isSubmitting || (isSubmitted && hasErrors) || !isCSVDownloadDone
}
isLoading={isSubmitting}
loadingText={t('common:utility.submitting')}
>
Expand Down

0 comments on commit 20f005e

Please sign in to comment.