Skip to content

Commit

Permalink
Merge pull request #236 from UgnisSoftware/UGN-426
Browse files Browse the repository at this point in the history
Fix modal not closing after submit
  • Loading branch information
masiulis committed Dec 18, 2023
2 parents e3c154f + 4d3951f commit e8f98f2
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 16 deletions.
37 changes: 21 additions & 16 deletions src/steps/ValidationStep/ValidationStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,23 +100,28 @@ export const ValidationStep = <T extends string>({ initialData, file, onBack }:
)
setShowSubmitAlert(false)
setSubmitting(true)
onSubmit(calculatedData, file)
?.then(() => {
onClose()
})
.catch((err: Error) => {
toast({
status: "error",
variant: "left-accent",
position: "bottom-left",
title: `${translations.alerts.submitError.title}`,
description: err?.message || `${translations.alerts.submitError.defaultMessage}`,
isClosable: true,
const response = onSubmit(calculatedData, file)
if (response?.then) {
response
.then(() => {
onClose()
})
})
.finally(() => {
setSubmitting(false)
})
.catch((err: Error) => {
toast({
status: "error",
variant: "left-accent",
position: "bottom-left",
title: `${translations.alerts.submitError.title}`,
description: err?.message || `${translations.alerts.submitError.defaultMessage}`,
isClosable: true,
})
})
.finally(() => {
setSubmitting(false)
})
} else {
onClose()
}
}
const onContinue = () => {
const invalidData = data.find((value) => {
Expand Down
29 changes: 29 additions & 0 deletions src/steps/ValidationStep/tests/ValidationStep.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,35 @@ describe("Validation step tests", () => {
})
})

test("Submit data without returning promise", async () => {
const onSuccess = jest.fn()
const onSubmit = jest.fn(() => {
onSuccess()
})
const onClose = jest.fn()
render(
<Providers theme={defaultTheme} rsiValues={{ ...mockValues, onSubmit, onClose }}>
<ModalWrapper isOpen={true} onClose={() => {}}>
<ValidationStep initialData={[]} file={file} />
</ModalWrapper>
</Providers>,
)

const finishButton = screen.getByRole("button", {
name: "Confirm",
})

await userEvent.click(finishButton)

await waitFor(() => {
expect(onSubmit).toBeCalledWith({ all: [], invalidData: [], validData: [] }, file)
})
await waitFor(() => {
expect(onSuccess).toBeCalled()
expect(onClose).toBeCalled()
})
})

test("Submit data with a successful async return", async () => {
const onSuccess = jest.fn()
const onSubmit = jest.fn(async (): Promise<void> => {
Expand Down

0 comments on commit e8f98f2

Please sign in to comment.