-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(app): "Cancel run" during Error Recovery (#15240)
Closes EXEC-462 Adds the ability to cancel a run during Error Recovery.
- Loading branch information
1 parent
0bd4a4b
commit 82e0459
Showing
16 changed files
with
292 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
app/src/organisms/ErrorRecoveryFlows/RecoveryOptions/CancelRun.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import * as React from 'react' | ||
import { useTranslation } from 'react-i18next' | ||
|
||
import { | ||
ALIGN_CENTER, | ||
DIRECTION_COLUMN, | ||
COLORS, | ||
Flex, | ||
Icon, | ||
JUSTIFY_SPACE_BETWEEN, | ||
SPACING, | ||
StyledText, | ||
} from '@opentrons/components' | ||
|
||
import { RECOVERY_MAP } from '../constants' | ||
import { RecoveryFooterButtons } from './shared' | ||
|
||
import type { RecoveryContentProps } from '../types' | ||
|
||
export function CancelRun({ | ||
isOnDevice, | ||
routeUpdateActions, | ||
recoveryCommands, | ||
}: RecoveryContentProps): JSX.Element | null { | ||
const { ROBOT_CANCELING } = RECOVERY_MAP | ||
const { t } = useTranslation('error_recovery') | ||
|
||
const { cancelRun } = recoveryCommands | ||
const { goBackPrevStep, setRobotInMotion } = routeUpdateActions | ||
|
||
const primaryBtnOnClick = (): Promise<void> => { | ||
return setRobotInMotion(true, ROBOT_CANCELING.ROUTE).then(() => cancelRun()) | ||
} | ||
|
||
if (isOnDevice) { | ||
return ( | ||
<Flex | ||
padding={SPACING.spacing32} | ||
gridGap={SPACING.spacing24} | ||
flexDirection={DIRECTION_COLUMN} | ||
justifyContent={JUSTIFY_SPACE_BETWEEN} | ||
alignItems={ALIGN_CENTER} | ||
height="100%" | ||
> | ||
<Flex | ||
flexDirection={DIRECTION_COLUMN} | ||
alignItems={ALIGN_CENTER} | ||
gridGap={SPACING.spacing24} | ||
height="100%" | ||
width="848px" | ||
> | ||
<Icon | ||
name="ot-alert" | ||
size="3.75rem" | ||
marginTop={SPACING.spacing24} | ||
color={COLORS.red50} | ||
/> | ||
<StyledText as="h3Bold"> | ||
{t('are_you_sure_you_want_to_cancel')} | ||
</StyledText> | ||
<StyledText as="h4" color={COLORS.grey60} textAlign={ALIGN_CENTER}> | ||
{t('if_tips_are_attached')} | ||
</StyledText> | ||
</Flex> | ||
<RecoveryFooterButtons | ||
isOnDevice={isOnDevice} | ||
primaryBtnOnClick={primaryBtnOnClick} | ||
secondaryBtnOnClick={goBackPrevStep} | ||
primaryBtnTextOverride={t('confirm')} | ||
/> | ||
</Flex> | ||
) | ||
} else { | ||
return null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
app/src/organisms/ErrorRecoveryFlows/RecoveryOptions/__tests__/CancelRun.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import * as React from 'react' | ||
import { vi, describe, it, expect, beforeEach } from 'vitest' | ||
import { screen, fireEvent, waitFor } from '@testing-library/react' | ||
|
||
import { renderWithProviders } from '../../../../__testing-utils__' | ||
import { i18n } from '../../../../i18n' | ||
import { CancelRun } from '../CancelRun' | ||
import { RECOVERY_MAP, ERROR_KINDS } from '../../constants' | ||
|
||
import type { Mock } from 'vitest' | ||
|
||
const render = (props: React.ComponentProps<typeof CancelRun>) => { | ||
return renderWithProviders(<CancelRun {...props} />, { | ||
i18nInstance: i18n, | ||
})[0] | ||
} | ||
|
||
describe('RecoveryFooterButtons', () => { | ||
const { CANCEL_RUN, ROBOT_CANCELING } = RECOVERY_MAP | ||
let props: React.ComponentProps<typeof CancelRun> | ||
let mockGoBackPrevStep: Mock | ||
|
||
beforeEach(() => { | ||
mockGoBackPrevStep = vi.fn() | ||
const mockRouteUpdateActions = { goBackPrevStep: mockGoBackPrevStep } as any | ||
|
||
props = { | ||
isOnDevice: true, | ||
recoveryCommands: {} as any, | ||
failedCommand: {} as any, | ||
errorKind: ERROR_KINDS.GENERAL_ERROR, | ||
routeUpdateActions: mockRouteUpdateActions, | ||
recoveryMap: { | ||
route: CANCEL_RUN.ROUTE, | ||
step: CANCEL_RUN.STEPS.CONFIRM_CANCEL, | ||
}, | ||
} | ||
}) | ||
|
||
it('renders appropriate copy and click behavior', async () => { | ||
render(props) | ||
|
||
screen.getByText('Are you sure you want to cancel?') | ||
screen.queryByText( | ||
'If tips are attached, you can choose to blowout any aspirated liquid and drop tips before the run is terminated.' | ||
) | ||
|
||
const secondaryBtn = screen.getByRole('button', { name: 'Go back' }) | ||
|
||
fireEvent.click(secondaryBtn) | ||
|
||
expect(mockGoBackPrevStep).toHaveBeenCalled() | ||
}) | ||
|
||
it('should call commands in the correct order for the primaryOnClick callback', async () => { | ||
const setRobotInMotionMock = vi.fn(() => Promise.resolve()) | ||
const cancelRunMock = vi.fn(() => Promise.resolve()) | ||
|
||
const mockRecoveryCommands = { | ||
cancelRun: cancelRunMock, | ||
} as any | ||
|
||
const mockRouteUpdateActions = { | ||
setRobotInMotion: setRobotInMotionMock, | ||
} as any | ||
|
||
render({ | ||
...props, | ||
recoveryCommands: mockRecoveryCommands, | ||
routeUpdateActions: mockRouteUpdateActions, | ||
}) | ||
|
||
const primaryBtn = screen.getByRole('button', { name: 'Confirm' }) | ||
fireEvent.click(primaryBtn) | ||
|
||
await waitFor(() => { | ||
expect(setRobotInMotionMock).toHaveBeenCalledTimes(1) | ||
}) | ||
await waitFor(() => { | ||
expect(setRobotInMotionMock).toHaveBeenCalledWith( | ||
true, | ||
ROBOT_CANCELING.ROUTE | ||
) | ||
}) | ||
await waitFor(() => { | ||
expect(cancelRunMock).toHaveBeenCalledTimes(1) | ||
}) | ||
|
||
expect(setRobotInMotionMock.mock.invocationCallOrder[0]).toBeLessThan( | ||
cancelRunMock.mock.invocationCallOrder[0] | ||
) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { SelectRecoveryOption } from './SelectRecoveryOption' | ||
export { ResumeRun } from './ResumeRun' | ||
export { CancelRun } from './CancelRun' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.