Skip to content

Commit 32bb804

Browse files
gabrieltmonkaiGabriel Tira
andauthored
Implemented useShowImageReference logic (#953)
* Implemented useShowImageReference logic * Added TS doc and improved naming * Added sight as dependency for toggle * Changed hook logic to onRetake * Fixed naming of test cases * Merge commit '918df5a9fde358ba94029e23a2b38eb9304adeaa' --------- Co-authored-by: Gabriel Tira <gtira@acvautions.com>
1 parent 918df5a commit 32bb804

File tree

4 files changed

+53
-6
lines changed

4 files changed

+53
-6
lines changed

packages/inspection-capture-web/src/PhotoCapture/PhotoCapture.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,12 @@ export function PhotoCapture({
194194
const onLastSightTaken = () => {
195195
setCurrentScreen(PhotoCaptureScreen.GALLERY);
196196
};
197+
const { currentTutorialStep, goToNextTutorialStep, closeTutorial } = usePhotoCaptureTutorial({
198+
enableTutorial,
199+
enableSightGuidelines,
200+
enableSightTutorial,
201+
});
202+
const { showSightTutorial, toggleSightTutorial } = usePhotoCaptureSightTutorial();
197203
const sightState = usePhotoCaptureSightState({
198204
inspectionId,
199205
captureSights: sights,
@@ -203,13 +209,8 @@ export function PhotoCapture({
203209
tasksBySight,
204210
complianceOptions,
205211
setIsInitialInspectionFetched,
212+
toggleSightTutorial,
206213
});
207-
const { currentTutorialStep, goToNextTutorialStep, closeTutorial } = usePhotoCaptureTutorial({
208-
enableTutorial,
209-
enableSightGuidelines,
210-
enableSightTutorial,
211-
});
212-
const { showSightTutorial, toggleSightTutorial } = usePhotoCaptureSightTutorial();
213214
const { showSightGuidelines, handleDisableSightGuidelines } = usePhotoCaptureSightGuidelines({
214215
enableSightGuidelines,
215216
});

packages/inspection-capture-web/src/PhotoCapture/hooks/usePhotoCaptureSightState.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
TaskName,
2323
ImageStatus,
2424
ProgressStatus,
25+
CAR_COVERAGE_COMPLIANCE_ISSUES,
2526
} from '@monkvision/types';
2627
import { sights } from '@monkvision/sights';
2728
import { useAnalytics } from '@monkvision/analytics';
@@ -114,6 +115,8 @@ export interface PhotoCaptureSightsParams {
114115
* sight will be used.
115116
*/
116117
tasksBySight?: Record<string, TaskName[]>;
118+
/** Callback called to show the tutorial when retaking a non Car Coverage compliant sight. */
119+
toggleSightTutorial: () => void;
117120
}
118121

119122
function getCaptureTasks(
@@ -209,6 +212,7 @@ export function usePhotoCaptureSightState({
209212
tasksBySight,
210213
setIsInitialInspectionFetched,
211214
complianceOptions,
215+
toggleSightTutorial,
212216
}: PhotoCaptureSightsParams): PhotoCaptureSightState {
213217
if (captureSights.length === 0) {
214218
throw new Error('Empty sight list given to the Monk PhotoCapture component.');
@@ -334,6 +338,17 @@ export function usePhotoCaptureSightState({
334338
if (sightToRetake) {
335339
setSelectedSight(sightToRetake);
336340
}
341+
342+
const hasCarCoverageComplianceIssues = state.images.some((image) => {
343+
return (
344+
image.sightId === id &&
345+
image.complianceIssues &&
346+
image.complianceIssues.some((issue) => CAR_COVERAGE_COMPLIANCE_ISSUES.includes(issue))
347+
);
348+
});
349+
if (hasCarCoverageComplianceIssues) {
350+
toggleSightTutorial();
351+
}
337352
},
338353
[captureSights],
339354
);

packages/inspection-capture-web/test/PhotoCapture/PhotoCapture.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ describe('PhotoCapture component', () => {
234234
apiConfig: props.apiConfig,
235235
loading,
236236
onLastSightTaken: expect.any(Function),
237+
toggleSightTutorial: expect.any(Function),
237238
tasksBySight: props.tasksBySight,
238239
complianceOptions: {
239240
enableCompliance: props.enableCompliance,

packages/inspection-capture-web/test/PhotoCapture/hooks/usePhotoCaptureSightState.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ function createParams(): PhotoCaptureSightsParams {
4848
useLiveCompliance: true,
4949
},
5050
setIsInitialInspectionFetched: jest.fn(),
51+
toggleSightTutorial: jest.fn(),
5152
};
5253
}
5354

@@ -332,6 +333,35 @@ describe('usePhotoCaptureSightState hook', () => {
332333
unmount();
333334
});
334335

336+
it('should not trigger tutorial when a new sight is taken', () => {
337+
const initialProps = createParams();
338+
const { result, unmount } = renderHook(usePhotoCaptureSightState, { initialProps });
339+
340+
act(() => result.current.selectSight(initialProps.captureSights[0]));
341+
expect((initialProps.toggleSightTutorial as jest.Mock).mock.calls.length).toBe(0);
342+
343+
unmount();
344+
});
345+
346+
it('should trigger tutorial only when retaking a non-compliant Car Coverage sight', () => {
347+
const initialProps = createParams();
348+
(useMonkState as jest.Mock).mockImplementationOnce(() => ({
349+
state: {
350+
images: [
351+
{ sightId: 'test-sight-1', complianceIssues: [ComplianceIssue.NO_VEHICLE] }, // Car Coverage issue
352+
{ sightId: 'test-sight-2', complianceIssues: [ComplianceIssue.TOO_ZOOMED] }, // Non Car Coverage issue
353+
],
354+
},
355+
}));
356+
const { result, unmount } = renderHook(usePhotoCaptureSightState, { initialProps });
357+
358+
act(() => result.current.retakeSight('test-sight-1'));
359+
act(() => result.current.retakeSight('test-sight-2'));
360+
expect((initialProps.toggleSightTutorial as jest.Mock).mock.calls.length).toBe(1);
361+
362+
unmount();
363+
});
364+
335365
it('should change the sightSelected when retaking a sight', () => {
336366
const initialProps = createParams();
337367
const { result, unmount } = renderHook(usePhotoCaptureSightState, { initialProps });

0 commit comments

Comments
 (0)