Skip to content

Commit

Permalink
address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
koji committed Aug 20, 2024
1 parent ee29cf8 commit 6d1d4c6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as React from 'react'
import { vi, it, describe, expect, beforeEach, afterEach } from 'vitest'
import { Route, MemoryRouter, Routes } from 'react-router-dom'
import { fireEvent, screen } from '@testing-library/react'
import { when } from 'vitest-when'

import { renderWithProviders } from '../../../../__testing-utils__'
import { i18n } from '../../../../i18n'
Expand All @@ -11,6 +12,7 @@ import {
useRobot,
useRunStatuses,
useSyncRobotClock,
useRunHasStarted,
} from '../../../../organisms/Devices/hooks'
import { useMostRecentCompletedAnalysis } from '../../../../organisms/LabwarePositionCheck/useMostRecentCompletedAnalysis'
import { ProtocolRunHeader } from '../../../../organisms/Devices/ProtocolRun/ProtocolRunHeader'
Expand All @@ -20,7 +22,6 @@ import { RunPreviewComponent } from '../../../../organisms/RunPreview'
import { ProtocolRunRuntimeParameters } from '../../../../organisms/Devices/ProtocolRun/ProtocolRunRunTimeParameters'
import { useCurrentRunId } from '../../../../resources/runs'
import { mockRobotSideAnalysis } from '../../../../molecules/Command/__fixtures__'
import { useFeatureFlag } from '../../../../redux/config'
import { ProtocolRunDetails } from '..'

import type { ModuleModel, ModuleType } from '@opentrons/shared-data'
Expand Down Expand Up @@ -78,7 +79,6 @@ const RUN_ID = '95e67900-bc9f-4fbf-92c6-cc4d7226a51b'

describe('ProtocolRunDetails', () => {
beforeEach(() => {
vi.mocked(useFeatureFlag).mockReturnValue(false)
vi.mocked(useRobot).mockReturnValue(mockConnectableRobot)
vi.mocked(useRunStatuses).mockReturnValue({
isRunRunning: false,
Expand Down Expand Up @@ -116,6 +116,7 @@ describe('ProtocolRunDetails', () => {
vi.mocked(useMostRecentCompletedAnalysis).mockReturnValue(
mockRobotSideAnalysis
)
when(vi.mocked(useRunHasStarted)).calledWith(RUN_ID).thenReturn(false)
})
afterEach(() => {
vi.resetAllMocks()
Expand Down Expand Up @@ -219,16 +220,15 @@ describe('ProtocolRunDetails', () => {
expect(screen.queryByText('Mock RunPreview')).toBeFalsy()
})

it('redirects to the run tab when the run is not current', () => {
vi.mocked(useCurrentRunId).mockReturnValue(null)
it('redirects to the run tab when the run is started by ODD or another Desktop app', () => {
when(vi.mocked(useRunHasStarted)).calledWith(RUN_ID).thenReturn(true)
render(`/devices/otie/protocol-runs/${RUN_ID}/setup`)

screen.getByText('Mock RunPreview')
expect(screen.queryByText('Mock ProtocolRunSetup')).toBeFalsy()
})

it('renders Parameters tab when runtime parameters ff is on', () => {
vi.mocked(useFeatureFlag).mockReturnValue(true)
render(`/devices/otie/protocol-runs/${RUN_ID}/setup`)

screen.getByText('Setup')
Expand All @@ -238,7 +238,6 @@ describe('ProtocolRunDetails', () => {
})

it('renders protocol run parameters when the parameters tab is clicked', () => {
vi.mocked(useFeatureFlag).mockReturnValue(true)
render(`/devices/otie/protocol-runs/${RUN_ID}`)

const parametersTab = screen.getByText('Parameters')
Expand Down
11 changes: 6 additions & 5 deletions app/src/pages/Devices/ProtocolRunDetails/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
useModuleRenderInfoForProtocolById,
useRobot,
useRobotType,
useRunHasStarted,
useRunStatuses,
useSyncRobotClock,
} from '../../../organisms/Devices/hooks'
Expand Down Expand Up @@ -315,17 +316,17 @@ const SetupTab = (props: SetupTabProps): JSX.Element | null => {
const { t } = useTranslation('run_details')
const currentRunId = useCurrentRunId()
const navigate = useNavigate()

const runHasStarted = useRunHasStarted(currentRunId)
const disabled = currentRunId !== runId
const tabDisabledReason = `${t('setup')} ${t(
'not_available_for_a_completed_run'
)}`

React.useEffect(() => {
if (currentRunId === null && protocolRunDetailsTab === 'setup') {
if (runHasStarted && protocolRunDetailsTab === 'setup') {
navigate(`/devices/${robotName}/protocol-runs/${runId}/run-preview`)
}
}, [disabled, navigate, protocolRunDetailsTab, robotName, runId])
}, [runHasStarted, navigate, protocolRunDetailsTab, robotName, runId])

return (
<RoundTab
Expand Down Expand Up @@ -356,7 +357,7 @@ const ParametersTab = (props: ParametersTabProps): JSX.Element | null => {
replace: true,
})
}
}, [disabled, navigate, robotName, runId])
}, [disabled, navigate, protocolRunDetailsTab, robotName, runId])

return (
<RoundTab
Expand Down Expand Up @@ -395,7 +396,7 @@ const ModuleControlsTab = (
React.useEffect(() => {
if (disabled && protocolRunDetailsTab === 'module-controls')
navigate(`/devices/${robotName}/protocol-runs/${runId}/run-preview`)
}, [disabled, navigate, robotName, runId])
}, [disabled, navigate, protocolRunDetailsTab, robotName, runId])

return isEmpty(moduleRenderInfoForProtocolById) ? null : (
<RoundTab
Expand Down

0 comments on commit 6d1d4c6

Please sign in to comment.