Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(liveness): Update state machine flow for no lights #5273

Merged
merged 14 commits into from
May 30, 2024
5 changes: 5 additions & 0 deletions .changeset/cyan-spiders-dream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@aws-amplify/ui-react-liveness": patch
---

chore(liveness): Update state machine flow for no lights
2 changes: 1 addition & 1 deletion packages/react-liveness/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"name": "FaceLivenessDetector",
"path": "dist/esm/index.mjs",
"import": "{ FaceLivenessDetector }",
"limit": "280 kB"
"limit": "281 kB"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ import {
DefaultCancelButton,
DefaultRecordingIcon,
} from '../shared/DefaultStartScreenComponents';
import { FACE_MOVEMENT_CHALLENGE } from '../service/utils/constants';

export const selectChallengeType = createLivenessSelector(
(state) => state.context.parsedSessionInformation?.Challenge?.Name
);
export const selectVideoConstraints = createLivenessSelector(
(state) => state.context.videoAssociatedParams?.videoConstraints
);
Expand Down Expand Up @@ -109,6 +113,9 @@ export const LivenessCameraModule = (

const [state, send] = useLivenessActor();

const isFaceMovementChallenge =
useLivenessSelector(selectChallengeType) === FACE_MOVEMENT_CHALLENGE.type;

const videoStream = useLivenessSelector(selectVideoStream);
const videoConstraints = useLivenessSelector(selectVideoConstraints);
const selectedDeviceId = useLivenessSelector(selectSelectedDeviceId);
Expand Down Expand Up @@ -290,13 +297,11 @@ export const LivenessCameraModule = (

// We don't show full screen camera on the pre check screen (isStartView/isWaitingForCamera)
const shouldShowFullScreenCamera =
isMobileScreen &&
!isStartView &&
!shouldShowCenteredLoader;
isMobileScreen && !isStartView && !shouldShowCenteredLoader;

return (
<>
{photoSensitivityWarning}
{!isFaceMovementChallenge && photoSensitivityWarning}

{shouldShowCenteredLoader && (
<Flex className={LivenessClassNames.ConnectingLoader}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,52 @@ describe('LivenessCameraModule', () => {
expect(matchIndicator).toHaveLength(0);
});

it('should render photosensitivity warning when challenge is FaceMovementAndLightChallenge and isNotRecording is true', async () => {
isNotRecording = true;
mockStateMatchesAndSelectors();
mockUseLivenessSelector.mockReturnValue('FaceMovementAndLightChallenge');

renderWithLivenessProvider(
<LivenessCameraModule
isMobileScreen={false}
isRecordingStopped={false}
hintDisplayText={hintDisplayText}
streamDisplayText={streamDisplayText}
errorDisplayText={errorDisplayText}
cameraDisplayText={cameraDisplayText}
instructionDisplayText={instructionDisplayText}
/>
);

const photosensitivityWarning = screen.queryByText(
instructionDisplayText.photosensitivityWarningHeadingText
);
expect(photosensitivityWarning).toBeInTheDocument();
});

it('should not render photosensitivity warning when challenge is FaceMovementChallenge and isNotRecording is true', async () => {
isNotRecording = true;
mockStateMatchesAndSelectors();
mockUseLivenessSelector.mockReturnValue('FaceMovementChallenge');

renderWithLivenessProvider(
<LivenessCameraModule
isMobileScreen={false}
isRecordingStopped={false}
hintDisplayText={hintDisplayText}
streamDisplayText={streamDisplayText}
errorDisplayText={errorDisplayText}
cameraDisplayText={cameraDisplayText}
instructionDisplayText={instructionDisplayText}
/>
);

const photosensitivityWarning = screen.queryByText(
instructionDisplayText.photosensitivityWarningHeadingText
);
expect(photosensitivityWarning).not.toBeInTheDocument();
});

it('should create appropriate selectors', () => {
const expectedConstraints = { width: 100 };
const expectedStream = { getTracks: () => [] };
Expand Down Expand Up @@ -470,7 +516,6 @@ describe('LivenessCameraModule', () => {
});

it('should show a full screen camera', async () => {
isStart = false;
isInitCamera = false;
isInitWebsocket = false;
isWaitingForCamera = false;
Expand Down
Loading
Loading