-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add test for ProtocolDesignerAppFallback
- Loading branch information
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
protocol-designer/src/resources/__tests__/ProtocolDesignerAppFallback.test.tsx
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,46 @@ | ||
import { describe, it, expect, vi, beforeEach } from 'vitest' | ||
import { fireEvent, screen } from '@testing-library/react' | ||
|
||
import { i18n } from '../../assets/localization' | ||
import { renderWithProviders } from '../../__testing-utils__' | ||
import { ProtocolDesignerAppFallback } from '../ProtocolDesignerAppFallback' | ||
|
||
import type { FallbackProps } from 'react-error-boundary' | ||
|
||
const mockError = { | ||
message: 'mock error', | ||
} as Error | ||
|
||
const mockFunc = vi.fn() | ||
|
||
const render = (props: FallbackProps) => { | ||
return renderWithProviders(<ProtocolDesignerAppFallback {...props} />, { | ||
i18nInstance: i18n, | ||
}) | ||
} | ||
|
||
describe('ProtocolDesignerAppFallback', () => { | ||
let props: FallbackProps | ||
|
||
beforeEach(() => { | ||
props = { | ||
error: mockError, | ||
resetErrorBoundary: mockFunc, | ||
} as FallbackProps | ||
}) | ||
|
||
it('should render text and button', () => { | ||
render(props) | ||
screen.getByText('An unknown error has occurred') | ||
screen.getByText( | ||
'You need to reload the app. Contact support with the following error message:' | ||
) | ||
screen.getByText('Reload app') | ||
}) | ||
|
||
it('should call mock function when clicking the button', () => { | ||
render(props) | ||
fireEvent.click(screen.getByText('Reload app')) | ||
expect(mockFunc).toHaveBeenCalled() | ||
}) | ||
}) |