-
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): Add StepInfo to ErrorRecovery (#15447)
Closes EXEC-550 Add the StepInfo component, a wrapper around "At step <xxx/yyy>: [CommandText]", which is used in several places in Error Recovery flows.
- Loading branch information
Showing
10 changed files
with
186 additions
and
39 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
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
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,54 @@ | ||
import * as React from 'react' | ||
|
||
import { useTranslation } from 'react-i18next' | ||
|
||
import { Flex, StyledText, DISPLAY_INLINE } from '@opentrons/components' | ||
|
||
import { CommandText } from '../../../molecules/Command' | ||
|
||
import type { StyleProps } from '@opentrons/components' | ||
import type { RecoveryContentProps } from '../types' | ||
|
||
interface StepInfoProps extends StyleProps { | ||
as: React.ComponentProps<typeof StyledText>['as'] | ||
stepCounts: RecoveryContentProps['stepCounts'] | ||
failedCommand: RecoveryContentProps['failedCommand'] | ||
robotType: RecoveryContentProps['robotType'] | ||
protocolAnalysis: RecoveryContentProps['protocolAnalysis'] | ||
} | ||
|
||
export function StepInfo({ | ||
as, | ||
stepCounts, | ||
failedCommand, | ||
robotType, | ||
protocolAnalysis, | ||
...styleProps | ||
}: StepInfoProps): JSX.Element { | ||
const { t } = useTranslation('error_recovery') | ||
const { currentStepNumber, totalStepCount } = stepCounts | ||
|
||
const analysisCommand = protocolAnalysis?.commands.find( | ||
command => command.key === failedCommand?.key | ||
) | ||
|
||
const currentCopy = currentStepNumber ?? '?' | ||
const totalCopy = totalStepCount ?? '?' | ||
|
||
// TODO(jh 06-17-24): Once design decides what to do with CommandText, update it here. | ||
return ( | ||
<Flex display={DISPLAY_INLINE} {...styleProps}> | ||
<StyledText as={as} display={DISPLAY_INLINE}> | ||
{`${t('at_step')} ${currentCopy}/${totalCopy}: `} | ||
</StyledText> | ||
{analysisCommand != null && protocolAnalysis != null ? ( | ||
<CommandText | ||
command={analysisCommand} | ||
commandTextData={protocolAnalysis} | ||
robotType={robotType} | ||
display={DISPLAY_INLINE} | ||
/> | ||
) : null} | ||
</Flex> | ||
) | ||
} |
73 changes: 73 additions & 0 deletions
73
app/src/organisms/ErrorRecoveryFlows/shared/__tests__/StepInfo.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,73 @@ | ||
import * as React from 'react' | ||
import { describe, it, expect, beforeEach, vi } from 'vitest' | ||
import { screen } from '@testing-library/react' | ||
|
||
import { renderWithProviders } from '../../../../__testing-utils__' | ||
import { mockRecoveryContentProps } from '../../__fixtures__' | ||
import { i18n } from '../../../../i18n' | ||
import { StepInfo } from '../StepInfo' | ||
import { CommandText } from '../../../../molecules/Command' | ||
|
||
vi.mock('../../../../molecules/Command') | ||
|
||
const render = (props: React.ComponentProps<typeof StepInfo>) => { | ||
return renderWithProviders(<StepInfo {...props} />, { | ||
i18nInstance: i18n, | ||
})[0] | ||
} | ||
|
||
describe('StepInfo', () => { | ||
let props: React.ComponentProps<typeof StepInfo> | ||
|
||
beforeEach(() => { | ||
props = { | ||
...mockRecoveryContentProps, | ||
as: 'h4', | ||
stepCounts: { | ||
currentStepNumber: 5, | ||
totalStepCount: 10, | ||
hasRunDiverged: false, | ||
}, | ||
} | ||
|
||
vi.mocked(CommandText).mockReturnValue(<div>MOCK COMMAND TEXT</div>) | ||
}) | ||
|
||
it('renders the step information with the current step and total steps', () => { | ||
render(props) | ||
|
||
screen.getByText('At step 5/10:') | ||
}) | ||
|
||
it('renders "?" for current step and total steps when they are not available', () => { | ||
props = { | ||
...props, | ||
stepCounts: { | ||
currentStepNumber: null, | ||
totalStepCount: null, | ||
} as any, | ||
} | ||
render(props) | ||
|
||
screen.getByText('At step ?/?:') | ||
}) | ||
|
||
it('renders the CommandText component when the analysis command is found', () => { | ||
render(props) | ||
|
||
screen.getByText('MOCK COMMAND TEXT') | ||
}) | ||
|
||
it('does not render the CommandText component when the analysis command is not found', () => { | ||
render(props) | ||
|
||
expect(screen.queryByText('Failed Command')).not.toBeInTheDocument() | ||
}) | ||
|
||
it('does not render the CommandText component when protocolAnalysis is not available', () => { | ||
props.protocolAnalysis = null | ||
render(props) | ||
|
||
expect(screen.queryByText('Failed Command')).not.toBeInTheDocument() | ||
}) | ||
}) |
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