diff --git a/apps/drive-app/src/pages/PhotoCapturePage/PhotoCapturePage.tsx b/apps/drive-app/src/pages/PhotoCapturePage/PhotoCapturePage.tsx index 34f80f33d..fb614e249 100644 --- a/apps/drive-app/src/pages/PhotoCapturePage/PhotoCapturePage.tsx +++ b/apps/drive-app/src/pages/PhotoCapturePage/PhotoCapturePage.tsx @@ -1,16 +1,29 @@ import { useTranslation } from 'react-i18next'; +import { useMemo } from 'react'; import { getEnvOrThrow, useMonkAppParams } from '@monkvision/common'; -import { DeviceOrientation } from '@monkvision/types'; +import { DeviceOrientation, Sight, TaskName } from '@monkvision/types'; import { PhotoCapture } from '@monkvision/inspection-capture-web'; import { useNavigate } from 'react-router-dom'; import { getSights } from '../../config'; import styles from './PhotoCapturePage.module.css'; import { Page } from '../pages'; +function getTasksBySight(sights: Sight[]): Record { + return sights.reduce( + (tasksBySight, sight) => ({ + ...tasksBySight, + [sight.id]: [...sight.tasks, TaskName.HUMAN_IN_THE_LOOP], + }), + {}, + ); +} + export function PhotoCapturePage() { const { i18n } = useTranslation(); const navigate = useNavigate(); const { authToken, inspectionId, vehicleType } = useMonkAppParams({ required: true }); + const sights = getSights(vehicleType); + const tasksBySight = useMemo(() => getTasksBySight(sights), [vehicleType]); const handleComplete = () => { navigate(Page.INSPECTION_COMPLETE); @@ -22,6 +35,7 @@ export function PhotoCapturePage() { apiConfig={{ authToken, apiDomain: getEnvOrThrow('REACT_APP_API_DOMAIN') }} inspectionId={inspectionId} sights={getSights(vehicleType)} + tasksBySight={tasksBySight} onComplete={handleComplete} lang={i18n.language} enforceOrientation={DeviceOrientation.LANDSCAPE} diff --git a/apps/drive-app/test/pages/PhotoCapturePage.test.tsx b/apps/drive-app/test/pages/PhotoCapturePage.test.tsx index cbd116b12..7542d5a39 100644 --- a/apps/drive-app/test/pages/PhotoCapturePage.test.tsx +++ b/apps/drive-app/test/pages/PhotoCapturePage.test.tsx @@ -1,12 +1,16 @@ +import { Sight, TaskName, VehicleType } from '@monkvision/types'; + jest.mock('../../src/config', () => ({ - getSights: jest.fn(() => [{ id: 'test' }]), + getSights: jest.fn(() => [ + { id: 'test-1', tasks: [TaskName.DAMAGE_DETECTION] }, + { id: 'test-2', tasks: [TaskName.DAMAGE_DETECTION, TaskName.WHEEL_ANALYSIS] }, + ]), })); import { render } from '@testing-library/react'; import { expectPropsOnChildMock } from '@monkvision/test-utils'; import { PhotoCapture } from '@monkvision/inspection-capture-web'; import { useMonkAppParams } from '@monkvision/common'; -import { VehicleType } from '@monkvision/types'; import { useNavigate } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; import { Page, PhotoCapturePage } from '../../src/pages'; @@ -72,6 +76,21 @@ describe('PhotoCapture page', () => { unmount(); }); + it('should add human in the loop for every sight', () => { + const { unmount } = render(); + + expectPropsOnChildMock(PhotoCapture, { + sights: expect.any(Array), + tasksBySight: expect.any(Object), + }); + const { sights, tasksBySight } = (PhotoCapture as unknown as jest.Mock).mock.calls[0][0]; + sights.forEach((sight: Sight) => { + expect(tasksBySight[sight.id]).toEqual([...sight.tasks, TaskName.HUMAN_IN_THE_LOOP]); + }); + + unmount(); + }); + it('should redirect to the inspection complete page after the inspection', () => { (useMonkAppParams as jest.Mock).mockImplementation(() => appParams); const { unmount } = render();