Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,12 @@ export function PhotoCapture({
const onLastSightTaken = () => {
setCurrentScreen(PhotoCaptureScreen.GALLERY);
};
const { currentTutorialStep, goToNextTutorialStep, closeTutorial } = usePhotoCaptureTutorial({
enableTutorial,
enableSightGuidelines,
enableSightTutorial,
});
const { showSightTutorial, toggleSightTutorial } = usePhotoCaptureSightTutorial();
const sightState = usePhotoCaptureSightState({
inspectionId,
captureSights: sights,
Expand All @@ -203,13 +209,8 @@ export function PhotoCapture({
tasksBySight,
complianceOptions,
setIsInitialInspectionFetched,
toggleSightTutorial,
});
const { currentTutorialStep, goToNextTutorialStep, closeTutorial } = usePhotoCaptureTutorial({
enableTutorial,
enableSightGuidelines,
enableSightTutorial,
});
const { showSightTutorial, toggleSightTutorial } = usePhotoCaptureSightTutorial();
const { showSightGuidelines, handleDisableSightGuidelines } = usePhotoCaptureSightGuidelines({
enableSightGuidelines,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
TaskName,
ImageStatus,
ProgressStatus,
CAR_COVERAGE_COMPLIANCE_ISSUES,
} from '@monkvision/types';
import { sights } from '@monkvision/sights';
import { useAnalytics } from '@monkvision/analytics';
Expand Down Expand Up @@ -114,6 +115,8 @@ export interface PhotoCaptureSightsParams {
* sight will be used.
*/
tasksBySight?: Record<string, TaskName[]>;
/** Callback called to show the tutorial when retaking a non Car Coverage compliant sight. */
toggleSightTutorial: () => void;
}

function getCaptureTasks(
Expand Down Expand Up @@ -209,6 +212,7 @@ export function usePhotoCaptureSightState({
tasksBySight,
setIsInitialInspectionFetched,
complianceOptions,
toggleSightTutorial,
}: PhotoCaptureSightsParams): PhotoCaptureSightState {
if (captureSights.length === 0) {
throw new Error('Empty sight list given to the Monk PhotoCapture component.');
Expand Down Expand Up @@ -334,6 +338,17 @@ export function usePhotoCaptureSightState({
if (sightToRetake) {
setSelectedSight(sightToRetake);
}

const hasCarCoverageComplianceIssues = state.images.some((image) => {
return (
image.sightId === id &&
image.complianceIssues &&
image.complianceIssues.some((issue) => CAR_COVERAGE_COMPLIANCE_ISSUES.includes(issue))
);
});
if (hasCarCoverageComplianceIssues) {
toggleSightTutorial();
}
},
[captureSights],
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ describe('PhotoCapture component', () => {
apiConfig: props.apiConfig,
loading,
onLastSightTaken: expect.any(Function),
toggleSightTutorial: expect.any(Function),
tasksBySight: props.tasksBySight,
complianceOptions: {
enableCompliance: props.enableCompliance,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ function createParams(): PhotoCaptureSightsParams {
useLiveCompliance: true,
},
setIsInitialInspectionFetched: jest.fn(),
toggleSightTutorial: jest.fn(),
};
}

Expand Down Expand Up @@ -332,6 +333,35 @@ describe('usePhotoCaptureSightState hook', () => {
unmount();
});

it('tutorial should not be triggered when a new sight is taken', () => {
const initialProps = createParams();
const { result, unmount } = renderHook(usePhotoCaptureSightState, { initialProps });

act(() => result.current.selectSight(initialProps.captureSights[0]));
expect((initialProps.toggleSightTutorial as jest.Mock).mock.calls.length).toBe(0);

unmount();
});

it('tutorial should be triggered only when retaking a non-compliant Car Coverage sight', () => {
const initialProps = createParams();
(useMonkState as jest.Mock).mockImplementationOnce(() => ({
state: {
images: [
{ sightId: 'test-sight-1', complianceIssues: [ComplianceIssue.NO_VEHICLE] }, // Car Coverage issue
{ sightId: 'test-sight-2', complianceIssues: [ComplianceIssue.TOO_ZOOMED] }, // Non Car Coverage issue
],
},
}));
const { result, unmount } = renderHook(usePhotoCaptureSightState, { initialProps });

act(() => result.current.retakeSight('test-sight-1'));
act(() => result.current.retakeSight('test-sight-2'));
expect((initialProps.toggleSightTutorial as jest.Mock).mock.calls.length).toBe(1);

unmount();
});

it('should change the sightSelected when retaking a sight', () => {
const initialProps = createParams();
const { result, unmount } = renderHook(usePhotoCaptureSightState, { initialProps });
Expand Down