Skip to content

Commit

Permalink
fix(app): always enable BackToTop button (#14103)
Browse files Browse the repository at this point in the history
* fix(app): always enable BackToTop button in ProtocolRun

closes RQA-1954
  • Loading branch information
ncdiehl11 authored Dec 6, 2023
1 parent 6227e63 commit 5ec4263
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 123 deletions.
46 changes: 2 additions & 44 deletions app/src/organisms/Devices/ProtocolRun/BackToTopButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,12 @@ import * as React from 'react'
import { useTranslation } from 'react-i18next'
import { Link } from 'react-router-dom'

import { useHoverTooltip, SecondaryButton } from '@opentrons/components'
import { SecondaryButton } from '@opentrons/components'

import { Tooltip } from '../../../atoms/Tooltip'
import {
useTrackEvent,
ANALYTICS_PROTOCOL_PROCEED_TO_RUN,
} from '../../../redux/analytics'
import {
useUnmatchedModulesForProtocol,
useRunCalibrationStatus,
useRunHasStarted,
} from '../hooks'

interface BackToTopButtonProps {
protocolRunHeaderRef: React.RefObject<HTMLDivElement> | null
Expand All @@ -29,34 +23,7 @@ export function BackToTopButton({
sourceLocation,
}: BackToTopButtonProps): JSX.Element | null {
const { t } = useTranslation('protocol_setup')
const [targetProps, tooltipProps] = useHoverTooltip()
const { missingModuleIds } = useUnmatchedModulesForProtocol(robotName, runId)
const trackEvent = useTrackEvent()
const { complete: isCalibrationComplete } = useRunCalibrationStatus(
robotName,
runId
)
const runHasStarted = useRunHasStarted(runId)

const calibrationIncomplete =
missingModuleIds.length === 0 && !isCalibrationComplete
const moduleSetupIncomplete =
missingModuleIds.length > 0 && isCalibrationComplete
const moduleAndCalibrationIncomplete =
missingModuleIds.length > 0 && !isCalibrationComplete

let proceedToRunDisabledReason = null
if (runHasStarted) {
proceedToRunDisabledReason = t('protocol_run_started')
} else if (moduleAndCalibrationIncomplete) {
proceedToRunDisabledReason = t(
'run_disabled_modules_and_calibration_not_complete'
)
} else if (calibrationIncomplete) {
proceedToRunDisabledReason = t('run_disabled_calibration_not_complete')
} else if (moduleSetupIncomplete) {
proceedToRunDisabledReason = t('run_disabled_modules_not_connected')
}

return (
<Link
Expand All @@ -71,18 +38,9 @@ export function BackToTopButton({
})
}}
>
<SecondaryButton
disabled={proceedToRunDisabledReason != null}
id="LabwareSetup_proceedToRunButton"
{...targetProps}
>
<SecondaryButton id="LabwareSetup_proceedToRunButton">
{t('back_to_top')}
</SecondaryButton>
{proceedToRunDisabledReason != null && (
<Tooltip tooltipProps={tooltipProps}>
{proceedToRunDisabledReason}
</Tooltip>
)}
</Link>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ import {
useTrackEvent,
ANALYTICS_PROTOCOL_PROCEED_TO_RUN,
} from '../../../../redux/analytics'
import {
useRunCalibrationStatus,
useRunHasStarted,
useUnmatchedModulesForProtocol,
} from '../../hooks'
import { BackToTopButton } from '../BackToTopButton'

jest.mock('@opentrons/components', () => {
Expand All @@ -24,17 +19,7 @@ jest.mock('@opentrons/components', () => {
}
})
jest.mock('../../../../redux/analytics')
jest.mock('../../hooks')

const mockUseUnmatchedModulesForProtocol = useUnmatchedModulesForProtocol as jest.MockedFunction<
typeof useUnmatchedModulesForProtocol
>
const mockUseRunCalibrationStatus = useRunCalibrationStatus as jest.MockedFunction<
typeof useRunCalibrationStatus
>
const mockUseRunHasStarted = useRunHasStarted as jest.MockedFunction<
typeof useRunHasStarted
>
const mockUseTrackEvent = useTrackEvent as jest.MockedFunction<
typeof useTrackEvent
>
Expand Down Expand Up @@ -62,20 +47,6 @@ let mockTrackEvent: jest.Mock

describe('BackToTopButton', () => {
beforeEach(() => {
when(mockUseUnmatchedModulesForProtocol)
.calledWith(ROBOT_NAME, RUN_ID)
.mockReturnValue({
missingModuleIds: [],
remainingAttachedModules: [],
})

when(mockUseRunCalibrationStatus)
.calledWith(ROBOT_NAME, RUN_ID)
.mockReturnValue({
complete: true,
})
when(mockUseRunHasStarted).calledWith(RUN_ID).mockReturnValue(false)

mockTrackEvent = jest.fn()
when(mockUseTrackEvent).calledWith().mockReturnValue(mockTrackEvent)
})
Expand All @@ -102,56 +73,9 @@ describe('BackToTopButton', () => {
})
})

it('should be disabled with modules not connected tooltip when there are missing moduleIds', () => {
when(mockUseUnmatchedModulesForProtocol)
.calledWith(ROBOT_NAME, RUN_ID)
.mockReturnValue({
missingModuleIds: ['temperatureModuleV1'],
remainingAttachedModules: [],
})
const { getByRole, getByText } = render()
const button = getByRole('button', { name: 'Back to top' })
expect(button).toBeDisabled()
getByText('Make sure all modules are connected before proceeding to run')
})
it('should be disabled with modules not connected and calibration not completed tooltip if missing cal and moduleIds', async () => {
when(mockUseUnmatchedModulesForProtocol)
.calledWith(ROBOT_NAME, RUN_ID)
.mockReturnValue({
missingModuleIds: ['temperatureModuleV1'],
remainingAttachedModules: [],
})
when(mockUseRunCalibrationStatus)
.calledWith(ROBOT_NAME, RUN_ID)
.mockReturnValue({
complete: false,
})
const { getByRole, getByText } = render()
const button = getByRole('button', { name: 'Back to top' })
expect(button).toBeDisabled()
getByText(
'Make sure robot calibration is complete and all modules are connected before proceeding to run'
)
})
it('should be disabled with calibration not complete tooltip when calibration not complete', async () => {
when(mockUseRunCalibrationStatus)
.calledWith(ROBOT_NAME, RUN_ID)
.mockReturnValue({
complete: false,
})
const { getByRole, getByText } = render()
const button = getByRole('button', { name: 'Back to top' })
expect(button).toBeDisabled()
getByText(
'Make sure robot calibration is complete before proceeding to run'
)
})
it('should be disabled with protocol run started tooltip when run has started', async () => {
when(mockUseRunHasStarted).calledWith(RUN_ID).mockReturnValue(true)

const { getByRole, getByText } = render()
it('should always be enabled', () => {
const { getByRole } = render()
const button = getByRole('button', { name: 'Back to top' })
expect(button).toBeDisabled()
getByText('Protocol run started.')
expect(button).not.toBeDisabled()
})
})

0 comments on commit 5ec4263

Please sign in to comment.