-
Notifications
You must be signed in to change notification settings - Fork 314
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: move default error components to separate components (#680)
* chore: move default error components to separate components * chore: update unit tests * fix: remove unused variable
- Loading branch information
Showing
10 changed files
with
203 additions
and
71 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
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 |
---|---|---|
@@ -1 +1,3 @@ | ||
export * from './FaceLivenessDetector'; | ||
export * from './shared/FaceLivenessErrorModal'; | ||
export * from './shared/FaceLivenessFailureModal'; |
52 changes: 52 additions & 0 deletions
52
packages/react/src/components/Liveness/shared/FaceLivenessErrorModal.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,52 @@ | ||
import * as React from 'react'; | ||
import { | ||
translate, | ||
LivenessErrorState, | ||
LivenessErrorStateStringMap, | ||
} from '@aws-amplify/ui'; | ||
|
||
import { Toast } from './Toast'; | ||
import { Overlay } from './Overlay'; | ||
import { Flex, Button } from '../../../primitives'; | ||
|
||
export interface FaceLivenessErrorModalProps { | ||
error: Error; | ||
onRetry: () => void; | ||
} | ||
|
||
export const FaceLivenessErrorModal: React.FC<FaceLivenessErrorModalProps> = ( | ||
props | ||
) => { | ||
const { error, onRetry } = props; | ||
const { name: errorState } = error; | ||
|
||
let heading: string = null; | ||
|
||
switch (errorState) { | ||
case LivenessErrorState.TIMEOUT: | ||
heading = translate('Time out'); | ||
break; | ||
case LivenessErrorState.SERVER_ERROR: | ||
heading = translate('Server Issue'); | ||
break; | ||
case LivenessErrorState.RUNTIME_ERROR: | ||
case LivenessErrorState.FACE_DISTANCE_ERROR: | ||
heading = translate('Client error'); | ||
break; | ||
default: | ||
heading = null; | ||
} | ||
|
||
return ( | ||
<Overlay backgroundColor="overlay.40"> | ||
<Toast heading={heading} variation="error"> | ||
{errorState && LivenessErrorStateStringMap[errorState]} | ||
<Flex justifyContent="center"> | ||
<Button variation="primary" type="button" onClick={onRetry}> | ||
{translate('Try again')} | ||
</Button> | ||
</Flex> | ||
</Toast> | ||
</Overlay> | ||
); | ||
}; |
27 changes: 27 additions & 0 deletions
27
packages/react/src/components/Liveness/shared/FaceLivenessFailureModal.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,27 @@ | ||
import * as React from 'react'; | ||
import { translate } from '@aws-amplify/ui'; | ||
|
||
import { Toast } from './Toast'; | ||
import { Overlay } from './Overlay'; | ||
import { Flex, Button } from '../../../primitives'; | ||
|
||
export interface FaceLivenessFailureModalProps { | ||
onRetry: () => void; | ||
} | ||
|
||
export const FaceLivenessFailureModal: React.FC<FaceLivenessFailureModalProps> = | ||
(props) => { | ||
const { onRetry } = props; | ||
|
||
return ( | ||
<Overlay backgroundColor="overlay.40"> | ||
<Toast heading={translate('Check unsuccessful')} variation="error"> | ||
<Flex justifyContent="center"> | ||
<Button variation="primary" type="button" onClick={onRetry}> | ||
{translate('Try again')} | ||
</Button> | ||
</Flex> | ||
</Toast> | ||
</Overlay> | ||
); | ||
}; |
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
61 changes: 61 additions & 0 deletions
61
packages/react/src/components/Liveness/shared/__tests__/FaceLivenessErrorModal.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,61 @@ | ||
import * as React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
|
||
import { FaceLivenessErrorModal } from '../FaceLivenessErrorModal'; | ||
import { | ||
LivenessErrorState, | ||
LivenessErrorStateStringMap, | ||
} from '@aws-amplify/ui'; | ||
|
||
describe('FaceLivenessErrorModal', () => { | ||
it('should render the component content appropriately', () => { | ||
const error = new Error(); | ||
error.name = LivenessErrorState.SERVER_ERROR; | ||
render(<FaceLivenessErrorModal error={error} onRetry={() => {}} />); | ||
|
||
expect( | ||
screen.getByText( | ||
LivenessErrorStateStringMap[LivenessErrorState.SERVER_ERROR] | ||
) | ||
).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render the timeout message appropriately', () => { | ||
const error = new Error(); | ||
error.name = LivenessErrorState.TIMEOUT; | ||
render(<FaceLivenessErrorModal error={error} onRetry={() => {}} />); | ||
|
||
expect( | ||
screen.getByText(LivenessErrorStateStringMap[LivenessErrorState.TIMEOUT]) | ||
).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render the runtime error message appropriately', () => { | ||
const error = new Error(); | ||
error.name = LivenessErrorState.RUNTIME_ERROR; | ||
render(<FaceLivenessErrorModal error={error} onRetry={() => {}} />); | ||
|
||
expect( | ||
screen.getByText( | ||
LivenessErrorStateStringMap[LivenessErrorState.RUNTIME_ERROR] | ||
) | ||
).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render the timeout message appropriately', () => { | ||
const error = new Error(); | ||
error.name = LivenessErrorState.TIMEOUT; | ||
render(<FaceLivenessErrorModal error={error} onRetry={() => {}} />); | ||
|
||
expect( | ||
screen.getByText(LivenessErrorStateStringMap[LivenessErrorState.TIMEOUT]) | ||
).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render the null error type message appropriately', () => { | ||
const error = new Error(); | ||
render(<FaceLivenessErrorModal error={error} onRetry={() => {}} />); | ||
|
||
expect(screen.getByText('Try again')).toBeInTheDocument(); | ||
}); | ||
}); |
12 changes: 12 additions & 0 deletions
12
packages/react/src/components/Liveness/shared/__tests__/FaceLivenessFailureModal.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,12 @@ | ||
import * as React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
|
||
import { FaceLivenessFailureModal } from '../FaceLivenessFailureModal'; | ||
|
||
describe('FaceLivenessFailureModal', () => { | ||
it('should render the component content appropriately', () => { | ||
render(<FaceLivenessFailureModal onRetry={() => {}} />); | ||
|
||
expect(screen.getByText('Check unsuccessful')).toBeInTheDocument(); | ||
}); | ||
}); |
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