Skip to content

Commit

Permalink
Added HinL task in Drive app
Browse files Browse the repository at this point in the history
  • Loading branch information
souyahia-monk committed Apr 29, 2024
1 parent d6d4259 commit dbd6e33
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
16 changes: 15 additions & 1 deletion apps/drive-app/src/pages/PhotoCapturePage/PhotoCapturePage.tsx
Original file line number Diff line number Diff line change
@@ -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<string, TaskName[]> {
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);
Expand All @@ -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}
Expand Down
23 changes: 21 additions & 2 deletions apps/drive-app/test/pages/PhotoCapturePage.test.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -72,6 +76,21 @@ describe('PhotoCapture page', () => {
unmount();
});

it('should add human in the loop for every sight', () => {
const { unmount } = render(<PhotoCapturePage />);

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(<PhotoCapturePage />);
Expand Down

0 comments on commit dbd6e33

Please sign in to comment.