diff --git a/app/src/pages/Devices/ProtocolRunDetails/__tests__/ProtocolRunDetails.test.tsx b/app/src/pages/Devices/ProtocolRunDetails/__tests__/ProtocolRunDetails.test.tsx index c5543f06d8c..e9091a07340 100644 --- a/app/src/pages/Devices/ProtocolRunDetails/__tests__/ProtocolRunDetails.test.tsx +++ b/app/src/pages/Devices/ProtocolRunDetails/__tests__/ProtocolRunDetails.test.tsx @@ -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' @@ -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' @@ -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' @@ -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, @@ -116,6 +116,7 @@ describe('ProtocolRunDetails', () => { vi.mocked(useMostRecentCompletedAnalysis).mockReturnValue( mockRobotSideAnalysis ) + when(vi.mocked(useRunHasStarted)).calledWith(RUN_ID).thenReturn(false) }) afterEach(() => { vi.resetAllMocks() @@ -219,8 +220,8 @@ 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') @@ -228,7 +229,6 @@ describe('ProtocolRunDetails', () => { }) 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') @@ -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') diff --git a/app/src/pages/Devices/ProtocolRunDetails/index.tsx b/app/src/pages/Devices/ProtocolRunDetails/index.tsx index 4823d431b81..a08ee28bdfc 100644 --- a/app/src/pages/Devices/ProtocolRunDetails/index.tsx +++ b/app/src/pages/Devices/ProtocolRunDetails/index.tsx @@ -26,6 +26,7 @@ import { useModuleRenderInfoForProtocolById, useRobot, useRobotType, + useRunHasStarted, useRunStatuses, useSyncRobotClock, } from '../../../organisms/Devices/hooks' @@ -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 ( { replace: true, }) } - }, [disabled, navigate, robotName, runId]) + }, [disabled, navigate, protocolRunDetailsTab, robotName, runId]) return ( { 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 : (