-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
117 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
'use client'; | ||
|
||
import { | ||
AlertDialog, | ||
AlertDialogHeader, | ||
AlertDialogContent, | ||
AlertDialogDescription, | ||
AlertDialogTitle, | ||
AlertDialogFooter, | ||
AlertDialogAction, | ||
AlertDialogCancel | ||
} from '@/components/ui/alert-dialog'; | ||
import Link from 'next/link'; | ||
import { useState } from 'react'; | ||
|
||
const ApiErrorModal = ({ open }: { open: boolean }) => { | ||
const [openApiErrorModal, setOpenApiErrorModal] = useState(open); | ||
|
||
/** | ||
* Closes the modal. | ||
*/ | ||
const close = () => { | ||
setOpenApiErrorModal(false); | ||
}; | ||
return ( | ||
<AlertDialog open={openApiErrorModal}> | ||
<AlertDialogContent> | ||
<AlertDialogHeader> | ||
<AlertDialogTitle>Error</AlertDialogTitle> | ||
<AlertDialogDescription> | ||
There was an unexpected communications problem. Please use your browser to refresh the page and | ||
try again. | ||
<br /> | ||
<br /> | ||
If the error persists please refer to our | ||
<Link className="text-text-color" href={'/feedback'} onClick={() => close()}> | ||
{' '} | ||
feedback page. | ||
</Link> | ||
</AlertDialogDescription> | ||
</AlertDialogHeader> | ||
<AlertDialogFooter> | ||
<AlertDialogCancel onClick={() => close()}>OK</AlertDialogCancel> | ||
<Link href={'/feedback'}> | ||
<AlertDialogAction onClick={() => close()}>Feedback</AlertDialogAction> | ||
</Link> | ||
</AlertDialogFooter> | ||
</AlertDialogContent> | ||
</AlertDialog> | ||
); | ||
}; | ||
|
||
export default ApiErrorModal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { fireEvent, render, screen } from '@testing-library/react'; | ||
import ApiErrorModal from '@/components/modal/api-error-modal'; | ||
|
||
jest.mock('@/access/authentication'); | ||
|
||
describe('ApiErrorModal', () => { | ||
it('should open the API Error modal', () => { | ||
render(<ApiErrorModal open={true} />); | ||
fireEvent.focus(document); | ||
|
||
expect(screen.getByRole('alertdialog', { name: 'Error' })).toBeInTheDocument(); | ||
expect(screen.getByRole('link', { name: 'feedback page.' })).toHaveAttribute('href', '/feedback'); | ||
expect(screen.getByRole('link', { name: 'Feedback' })).toHaveAttribute('href', '/feedback'); | ||
expect(screen.getByRole('button', { name: 'OK' })); | ||
expect(screen.getByRole('button', { name: 'Feedback' })); | ||
}); | ||
|
||
it('should close the API Error modal if open evaluates to false', () => { | ||
render(<ApiErrorModal open={false} />); | ||
fireEvent.focus(document); | ||
|
||
expect(screen.queryByRole('alertdialog', { name: 'Error' })).not.toBeInTheDocument(); | ||
}); | ||
|
||
it('should close the modal after clicking the Feedback button', () => { | ||
render(<ApiErrorModal open={true} />); | ||
fireEvent.focus(document); | ||
|
||
expect(screen.getByRole('alertdialog', { name: 'Error' })).toBeInTheDocument(); | ||
fireEvent.click(screen.getByRole('button', { name: 'Feedback' })); | ||
expect(screen.queryByRole('alertdialog', { name: 'Error' })).not.toBeInTheDocument(); | ||
}); | ||
|
||
it('should close the modal after clicking the provided link', () => { | ||
render(<ApiErrorModal open={true} />); | ||
fireEvent.focus(document); | ||
|
||
expect(screen.getByRole('alertdialog', { name: 'Error' })).toBeInTheDocument(); | ||
fireEvent.click(screen.getByRole('link', { name: 'feedback page.' })); | ||
expect(screen.queryByRole('alertdialog', { name: 'Error' })).not.toBeInTheDocument(); | ||
}); | ||
|
||
it('should close the modal after clicking the OK button', () => { | ||
render(<ApiErrorModal open={true} />); | ||
fireEvent.focus(document); | ||
|
||
expect(screen.getByRole('alertdialog', { name: 'Error' })).toBeInTheDocument(); | ||
fireEvent.click(screen.getByRole('button', { name: 'OK' })); | ||
expect(screen.queryByRole('alertdialog', { name: 'Error' })).not.toBeInTheDocument(); | ||
}); | ||
}); |