Skip to content
Merged
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
10 changes: 3 additions & 7 deletions app/src/organisms/ErrorRecoveryFlows/constants.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { css } from 'styled-components'

import {
RESPONSIVENESS,
SPACING,
DIRECTION_COLUMN,
ALIGN_CENTER,
DIRECTION_COLUMN,
JUSTIFY_CENTER,
JUSTIFY_SPACE_BETWEEN,
RESPONSIVENESS,
SPACING,
TEXT_ALIGN_CENTER,
} from '@opentrons/components'

Expand Down Expand Up @@ -174,7 +174,6 @@ export const RECOVERY_MAP = {
RETRY: 'retry',
},
},
REFILL_AND_RESUME: { ROUTE: 'refill-and-resume', STEPS: {} },
RETRY_STEP: {
ROUTE: 'retry-step',
STEPS: { CONFIRM_RETRY: 'confirm-retry' },
Expand Down Expand Up @@ -224,7 +223,6 @@ const {
ROBOT_DOOR_OPEN,
ROBOT_DOOR_OPEN_SPECIAL,
DROP_TIP_FLOWS,
REFILL_AND_RESUME,
IGNORE_AND_SKIP,
CANCEL_RUN,
RETRY_NEW_TIPS,
Expand Down Expand Up @@ -274,7 +272,6 @@ export const STEP_ORDER: StepOrder = {
DROP_TIP_FLOWS.STEPS.CHOOSE_BLOWOUT,
DROP_TIP_FLOWS.STEPS.CHOOSE_TIP_DROP,
],
[REFILL_AND_RESUME.ROUTE]: [],
[IGNORE_AND_SKIP.ROUTE]: [
IGNORE_AND_SKIP.STEPS.SELECT_IGNORE_KIND,
IGNORE_AND_SKIP.STEPS.SKIP_STEP,
Expand Down Expand Up @@ -455,7 +452,6 @@ export const RECOVERY_MAP_METADATA: RecoveryRouteStepMetadata = {
[MANUAL_REPLACE_AND_RETRY.STEPS.MANUAL_REPLACE]: { allowDoorOpen: true },
[MANUAL_REPLACE_AND_RETRY.STEPS.RETRY]: { allowDoorOpen: true },
},
[REFILL_AND_RESUME.ROUTE]: {},
[RETRY_STEP.ROUTE]: {
[RETRY_STEP.STEPS.CONFIRM_RETRY]: {
allowDoorOpen: false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
import { vi, describe, it, expect, beforeEach } from 'vitest'
import { I18nextProvider } from 'react-i18next'
import { i18n } from '/app/i18n'
import { renderHook, render, screen } from '@testing-library/react'

import { FLEX_ROBOT_TYPE } from '@opentrons/shared-data'

import { render, renderHook, screen } from '@testing-library/react'
import { i18n } from '/app/i18n'
import { useCommandTextString } from '/app/local-resources/commands'
import type { ReactElement } from 'react'
import { I18nextProvider } from 'react-i18next'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import type { Mock } from 'vitest'
import { useToaster } from '../../../ToasterOven'
import { RECOVERY_MAP } from '../../constants'
import {
useRecoveryToasts,
useRecoveryToastText,
getStepNumber,
handleRecoveryOptionAction,
useRecoveryFullCommandText,
useRecoveryToasts,
useRecoveryToastText,
} from '../useRecoveryToasts'
import { RECOVERY_MAP } from '../../constants'
import { useToaster } from '../../../ToasterOven'
import { useCommandTextString } from '/app/local-resources/commands'

import type { ReactElement } from 'react'
import type { Mock } from 'vitest'
import type { BuildToast } from '../useRecoveryToasts'

vi.mock('../../../ToasterOven')
Expand Down Expand Up @@ -289,3 +287,104 @@ describe('useRecoveryFullCommandText', () => {
expect(result.current).toBe('tc starting profile of 1231231 element steps')
})
})

describe('handleRecoveryOptionAction', () => {
const CURRENT_STEP_VALUE = 'currentStepValue'
const NEXT_STEP_VALUE = 'nextStepValue'

// Routes that should return the nextStepReturnVal toasts.
const NEXT_STEP_ROUTES = [
RECOVERY_MAP.SKIP_STEP_WITH_SAME_TIPS.ROUTE,
RECOVERY_MAP.SKIP_STEP_WITH_NEW_TIPS.ROUTE,
RECOVERY_MAP.IGNORE_AND_SKIP.ROUTE,
RECOVERY_MAP.MANUAL_MOVE_AND_SKIP.ROUTE,
]

// Routes that should return the currentStepReturnVal toasts.
const CURRENT_STEP_ROUTES = [
RECOVERY_MAP.CANCEL_RUN.ROUTE,
RECOVERY_MAP.RETRY_SAME_TIPS.ROUTE,
RECOVERY_MAP.RETRY_NEW_TIPS.ROUTE,
RECOVERY_MAP.RETRY_STEP.ROUTE,
RECOVERY_MAP.MANUAL_REPLACE_AND_RETRY.ROUTE,
RECOVERY_MAP.HOME_AND_RETRY.ROUTE,
RECOVERY_MAP.MANUAL_FILL_AND_RETRY_NEW_TIPS.ROUTE,
RECOVERY_MAP.MANUAL_FILL_AND_RETRY_SAME_TIPS.ROUTE,
]

// Routes that should return no toasts.
const NULL_ROUTES = [
RECOVERY_MAP.DROP_TIP_FLOWS.ROUTE,
RECOVERY_MAP.ERROR_WHILE_RECOVERING.ROUTE,
RECOVERY_MAP.ROBOT_CANCELING.ROUTE,
RECOVERY_MAP.ROBOT_IN_MOTION.ROUTE,
RECOVERY_MAP.ROBOT_PICKING_UP_TIPS.ROUTE,
RECOVERY_MAP.ROBOT_RELEASING_LABWARE.ROUTE,
RECOVERY_MAP.ROBOT_RESUMING.ROUTE,
RECOVERY_MAP.ROBOT_RETRYING_STEP.ROUTE,
RECOVERY_MAP.ROBOT_SKIPPING_STEP.ROUTE,
RECOVERY_MAP.ROBOT_DOOR_OPEN.ROUTE,
RECOVERY_MAP.ROBOT_DOOR_OPEN_SPECIAL.ROUTE,
RECOVERY_MAP.OPTION_SELECTION.ROUTE,
]

it.each(NEXT_STEP_ROUTES)('should return nextStepReturnVal for %s', route => {
const result = handleRecoveryOptionAction(
route,
CURRENT_STEP_VALUE,
NEXT_STEP_VALUE
)
expect(result).toBe(NEXT_STEP_VALUE)
})

it.each(CURRENT_STEP_ROUTES)(
'should return currentStepReturnVal for %s',
route => {
const result = handleRecoveryOptionAction(
route,
CURRENT_STEP_VALUE,
NEXT_STEP_VALUE
)
expect(result).toBe(CURRENT_STEP_VALUE)
}
)

it.each(NULL_ROUTES)('should return null for %s', route => {
const result = handleRecoveryOptionAction(
route,
CURRENT_STEP_VALUE,
NEXT_STEP_VALUE
)
expect(result).toBeNull()
})

it('should return null for unknown recovery options', () => {
const result = handleRecoveryOptionAction(
'UNKNOWN_OPTION' as any,
CURRENT_STEP_VALUE,
NEXT_STEP_VALUE
)
expect(result).toBeNull()
})

it('should ensure all routes are tested and there are no duplicated routes', () => {
const allRoutes = Object.values(RECOVERY_MAP).map(item => item.ROUTE)

const testedRoutes = [
...NEXT_STEP_ROUTES,
...CURRENT_STEP_ROUTES,
...NULL_ROUTES,
]

const untestedRoutes = allRoutes.filter(
route => !testedRoutes.includes(route)
)

if (untestedRoutes.length > 0) {
throw new Error(`Untested routes: ${untestedRoutes.join(', ')}`)
}

const allTestedRoutesSet = new Set(testedRoutes)
expect(allTestedRoutesSet.size).toBe(testedRoutes.length)
})
})
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { useCommandTextString } from '/app/local-resources/commands'
import type { UseCommandTextStringParams } from '/app/local-resources/commands'
import type { StepCounts } from '/app/resources/protocols/hooks'
import { useTranslation } from 'react-i18next'

import { useToaster } from '../../ToasterOven'
import { RECOVERY_MAP } from '../constants'
import { useCommandTextString } from '/app/local-resources/commands'

import type { StepCounts } from '/app/resources/protocols/hooks'
import type { CurrentRecoveryOptionUtils } from './useRecoveryRouting'
import type { UseCommandTextStringParams } from '/app/local-resources/commands'

export type BuildToast = Omit<UseCommandTextStringParams, 'command'> & {
isOnDevice: boolean
Expand Down Expand Up @@ -158,13 +156,12 @@ export function getStepNumber(

// Recovery options can be categorized into broad categories of behavior, currently performing the same step again
// or skipping to the next step.
function handleRecoveryOptionAction<T>(
export function handleRecoveryOptionAction<T>(
selectedRecoveryOption: CurrentRecoveryOptionUtils['selectedRecoveryOption'],
currentStepReturnVal: T,
nextStepReturnVal: T
): T | null {
switch (selectedRecoveryOption) {
case RECOVERY_MAP.MANUAL_FILL_AND_RETRY_SAME_TIPS.ROUTE:
case RECOVERY_MAP.SKIP_STEP_WITH_SAME_TIPS.ROUTE:
case RECOVERY_MAP.SKIP_STEP_WITH_NEW_TIPS.ROUTE:
case RECOVERY_MAP.IGNORE_AND_SKIP.ROUTE:
Expand All @@ -176,8 +173,11 @@ function handleRecoveryOptionAction<T>(
case RECOVERY_MAP.RETRY_STEP.ROUTE:
case RECOVERY_MAP.MANUAL_REPLACE_AND_RETRY.ROUTE:
case RECOVERY_MAP.HOME_AND_RETRY.ROUTE:
case RECOVERY_MAP.MANUAL_FILL_AND_RETRY_NEW_TIPS.ROUTE:
case RECOVERY_MAP.MANUAL_FILL_AND_RETRY_SAME_TIPS.ROUTE:
return currentStepReturnVal
default: {
console.error('Unhandled recovery toast case. Handle explicitly.')
return null
}
}
Expand Down
Loading