Skip to content

Commit

Permalink
some cleanup and testing
Browse files Browse the repository at this point in the history
  • Loading branch information
mjhuff committed Aug 8, 2024
1 parent a87c6fc commit 2e5b348
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 89 deletions.
4 changes: 3 additions & 1 deletion app/src/organisms/Devices/ProtocolRun/ProtocolRunHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ import type { State } from '../../../redux/types'
import type { HeaterShakerModule } from '../../../redux/modules/types'

const EQUIPMENT_POLL_MS = 5000
const CURRENT_RUN_POLL_MS = 5000
const CANCELLABLE_STATUSES = [
RUN_STATUS_RUNNING,
RUN_STATUS_PAUSED,
Expand Down Expand Up @@ -167,7 +168,8 @@ export function ProtocolRunHeader({
const { analysisErrors } = useProtocolAnalysisErrors(runId)
const { data: attachedInstruments } = useInstrumentsQuery()
const isRunCurrent = Boolean(
useNotifyRunQuery(runId, { refetchInterval: 5000 })?.data?.data?.current
useNotifyRunQuery(runId, { refetchInterval: CURRENT_RUN_POLL_MS })?.data
?.data?.current
)
const mostRecentRunId = useMostRecentRunId()
const { closeCurrentRun, isClosingCurrentRun } = useCloseCurrentRun()
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,42 @@ import * as React from 'react'
import { describe, it, vi, expect, beforeEach } from 'vitest'
import { renderHook, act, screen, fireEvent } from '@testing-library/react'

import { FLEX_ROBOT_TYPE } from '@opentrons/shared-data'

import {
useProtocolDropTipModal,
ProtocolDropTipModal,
} from '../ProtocolDropTipModal'
import { renderWithProviders } from '../../../../__testing-utils__'
import { i18n } from '../../../../i18n'
import { mockLeftSpecs } from '../../../../redux/pipettes/__fixtures__'
import { useHomePipettes } from '../../../DropTipWizardFlows/hooks'

import type { Mock } from 'vitest'

vi.mock('../../../DropTipWizardFlows/hooks')

describe('useProtocolDropTipModal', () => {
let props: Parameters<typeof useProtocolDropTipModal>[0]
let mockHomePipettes: Mock

beforeEach(() => {
props = {
areTipsAttached: true,
toggleDTWiz: vi.fn(),
isRunCurrent: true,
onClose: vi.fn(),
currentRunId: 'MOCK_ID',
mount: 'left',
instrumentModelSpecs: mockLeftSpecs,
robotType: FLEX_ROBOT_TYPE,
}
mockHomePipettes = vi.fn()

vi.mocked(useHomePipettes).mockReturnValue({
homePipettes: mockHomePipettes,
isHomingPipettes: false,
})
})

it('should return initial values', () => {
Expand All @@ -27,6 +47,7 @@ describe('useProtocolDropTipModal', () => {
showDTModal: true,
onDTModalSkip: expect.any(Function),
onDTModalRemoval: expect.any(Function),
isDisabled: false,
})
})

Expand All @@ -43,13 +64,23 @@ describe('useProtocolDropTipModal', () => {
expect(result.current.showDTModal).toBe(false)
})

it('should not show modal when isMostRecentRunCurrent is false', () => {
it('should not show modal when isRunCurrent is false', () => {
props.isRunCurrent = false
const { result } = renderHook(() => useProtocolDropTipModal(props))

expect(result.current.showDTModal).toBe(false)
})

it('should call homePipettes when onDTModalSkip is called', () => {
const { result } = renderHook(() => useProtocolDropTipModal(props))

act(() => {
result.current.onDTModalSkip()
})

expect(mockHomePipettes).toHaveBeenCalled()
})

it('should call toggleDTWiz when onDTModalRemoval is called', () => {
const { result } = renderHook(() => useProtocolDropTipModal(props))

Expand All @@ -59,6 +90,17 @@ describe('useProtocolDropTipModal', () => {

expect(props.toggleDTWiz).toHaveBeenCalled()
})

it('should set isDisabled to true when isHomingPipettes is true', () => {
vi.mocked(useHomePipettes).mockReturnValue({
homePipettes: mockHomePipettes,
isHomingPipettes: true,
})

const { result } = renderHook(() => useProtocolDropTipModal(props))

expect(result.current.isDisabled).toBe(true)
})
})

const render = (props: React.ComponentProps<typeof ProtocolDropTipModal>) => {
Expand All @@ -75,6 +117,7 @@ describe('ProtocolDropTipModal', () => {
onSkip: vi.fn(),
onBeginRemoval: vi.fn(),
mount: 'left',
isDisabled: false,
}
})

Expand All @@ -86,13 +129,13 @@ describe('ProtocolDropTipModal', () => {
/Homing the .* pipette with liquid in the tips may damage it\. You must remove all tips before using the pipette again\./
)
screen.getByText('Begin removal')
screen.getByText('Skip')
screen.getByText('Skip and home pipette')
})

it('calls onSkip when skip button is clicked', () => {
render(props)

fireEvent.click(screen.getByText('Skip'))
fireEvent.click(screen.getByText('Skip and home pipette'))

expect(props.onSkip).toHaveBeenCalled()
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,8 @@ describe('ProtocolRunHeader', () => {
onDTModalRemoval: vi.fn(),
onDTModalSkip: vi.fn(),
showDTModal: false,
} as any)
isDisabled: false,
})
vi.mocked(ProtocolDropTipModal).mockReturnValue(
<div>MOCK_DROP_TIP_MODAL</div>
)
Expand Down Expand Up @@ -495,11 +496,9 @@ describe('ProtocolRunHeader', () => {
when(vi.mocked(useRunStatus))
.calledWith(RUN_ID)
.thenReturn(RUN_STATUS_STOPPED)
when(vi.mocked(useNotifyRunQuery))
.calledWith(RUN_ID)
.thenReturn({
data: { data: { ...mockIdleUnstartedRun, current: true } },
} as UseQueryResult<OpentronsApiClient.Run>)
vi.mocked(useNotifyRunQuery).mockReturnValue({
data: { data: { ...mockIdleUnstartedRun, current: true } },
} as UseQueryResult<OpentronsApiClient.Run>)
render()
expect(mockTrackProtocolRunEvent).toBeCalled()
expect(mockTrackProtocolRunEvent).toBeCalledWith({
Expand Down Expand Up @@ -848,11 +847,9 @@ describe('ProtocolRunHeader', () => {
})

it('renders a clear protocol banner when run has succeeded', async () => {
when(vi.mocked(useNotifyRunQuery))
.calledWith(RUN_ID)
.thenReturn({
data: { data: mockSucceededRun },
} as UseQueryResult<OpentronsApiClient.Run>)
vi.mocked(useNotifyRunQuery).mockReturnValue({
data: { data: mockSucceededRun },
} as UseQueryResult<OpentronsApiClient.Run>)
when(vi.mocked(useRunStatus))
.calledWith(RUN_ID)
.thenReturn(RUN_STATUS_SUCCEEDED)
Expand All @@ -861,11 +858,9 @@ describe('ProtocolRunHeader', () => {
screen.getByText('Run completed.')
})
it('clicking close on a terminal run banner closes the run context', async () => {
when(vi.mocked(useNotifyRunQuery))
.calledWith(RUN_ID)
.thenReturn({
data: { data: mockSucceededRun },
} as UseQueryResult<OpentronsApiClient.Run>)
vi.mocked(useNotifyRunQuery).mockReturnValue({
data: { data: mockSucceededRun },
} as UseQueryResult<OpentronsApiClient.Run>)
when(vi.mocked(useRunStatus))
.calledWith(RUN_ID)
.thenReturn(RUN_STATUS_SUCCEEDED)
Expand Down Expand Up @@ -987,11 +982,9 @@ describe('ProtocolRunHeader', () => {
})

it('renders banner with spinner if currently closing current run', async () => {
when(vi.mocked(useNotifyRunQuery))
.calledWith(RUN_ID)
.thenReturn({
data: { data: mockSucceededRun },
} as UseQueryResult<OpentronsApiClient.Run>)
vi.mocked(useNotifyRunQuery).mockReturnValue({
data: { data: mockSucceededRun },
} as UseQueryResult<OpentronsApiClient.Run>)
when(vi.mocked(useRunStatus))
.calledWith(RUN_ID)
.thenReturn(RUN_STATUS_SUCCEEDED)
Expand Down Expand Up @@ -1042,6 +1035,7 @@ describe('ProtocolRunHeader', () => {
onDTModalRemoval: vi.fn(),
onDTModalSkip: vi.fn(),
showDTModal: true,
isDisabled: false,
})

render()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export function useDropTipMaintenanceRun({

const { data: maintenanceRunData } = useNotifyCurrentMaintenanceRun({
refetchInterval: RUN_REFETCH_INTERVAL_MS,
forceHttpPolling: true,
})

const activeMaintenanceRunId = maintenanceRunData?.data.id
Expand Down Expand Up @@ -152,9 +151,10 @@ function useMonitorMaintenanceRunForDeletion({
monitorMaintenanceRunForDeletion,
setMonitorMaintenanceRunForDeletion,
] = React.useState<boolean>(false)
const [closedOnce, setClosedOnce] = React.useState<boolean>(false)

React.useEffect(() => {
if (isMaintenanceRunType) {
if (isMaintenanceRunType && !closedOnce) {
if (
createdMaintenanceRunId !== null &&
activeMaintenanceRunId === createdMaintenanceRunId
Expand All @@ -166,12 +166,8 @@ function useMonitorMaintenanceRunForDeletion({
monitorMaintenanceRunForDeletion
) {
closeFlow()
setClosedOnce(true)
}
}
}, [
isMaintenanceRunType,
createdMaintenanceRunId,
activeMaintenanceRunId,
closeFlow,
])
}, [isMaintenanceRunType, createdMaintenanceRunId, activeMaintenanceRunId])
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,22 +96,22 @@ describe('ManageTips', () => {
/Homing the .* pipette with liquid in the tips may damage it\. You must remove all tips before using the pipette again\./
)
screen.queryAllByText('Begin removal')
screen.queryAllByText('Skip')
screen.queryAllByText('Skip and home pipette')
})

it('routes correctly when continuing on BeginRemoval', () => {
render(props)

const beginRemovalBtn = screen.queryAllByText('Begin removal')[0]
const skipBtn = screen.queryAllByText('Skip')[0]
const skipBtn = screen.queryAllByText('Skip and home pipette')[0]

fireEvent.click(beginRemovalBtn)
clickButtonLabeled('Begin removal')

expect(mockProceedNextStep).toHaveBeenCalled()

fireEvent.click(skipBtn)
clickButtonLabeled('Skip')
clickButtonLabeled('Skip and home pipette')

expect(mockSetRobotInMotion).toHaveBeenCalled()
})
Expand All @@ -125,10 +125,10 @@ describe('ManageTips', () => {
}
render(props)

const skipBtn = screen.queryAllByText('Skip')[0]
const skipBtn = screen.queryAllByText('Skip and home pipette')[0]

fireEvent.click(skipBtn)
clickButtonLabeled('Skip')
clickButtonLabeled('Skip and home pipette')

expect(mockProceedToRouteAndStep).toHaveBeenCalledWith(
RETRY_NEW_TIPS.ROUTE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export function useCloseCurrentRun(): {
const closeCurrentRun = (
options?: UseDismissCurrentRunMutationOptions
): void => {
console.log('=>(useCloseCurrentRun.ts:24) currentRunId', currentRunId)
if (currentRunId != null) {
dismissCurrentRun(currentRunId, {
...options,
Expand Down
8 changes: 5 additions & 3 deletions app/src/pages/RunSummary/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ import { useRecoveryAnalytics } from '../../organisms/ErrorRecoveryFlows/hooks'
import type { OnDeviceRouteParams } from '../../App/types'
import type { PipetteWithTip } from '../../organisms/DropTipWizardFlows'

const CURRENT_RUN_POLL_MS = 5000

export function RunSummary(): JSX.Element {
const { runId } = useParams<
keyof OnDeviceRouteParams
Expand All @@ -81,7 +83,8 @@ export function RunSummary(): JSX.Element {
const host = useHost()
const { data: runRecord } = useNotifyRunQuery(runId, { staleTime: Infinity })
const isRunCurrent = Boolean(
useNotifyRunQuery(runId, { refetchInterval: 5000 })?.data?.data?.current
useNotifyRunQuery(runId, { refetchInterval: CURRENT_RUN_POLL_MS })?.data
?.data?.current
)
const { data: attachedInstruments } = useInstrumentsQuery()
const { deleteRun } = useDeleteRunMutation()
Expand Down Expand Up @@ -185,7 +188,6 @@ export function RunSummary(): JSX.Element {
// TODO(jh, 08-02-24): Revisit useCurrentRunRoute and top level redirects.
const queryClient = useQueryClient()
const returnToDash = (): void => {
closeCurrentRun()
// Eagerly clear the query cache to prevent top level redirecting back to this page.
queryClient.setQueryData([host, 'runs', runId, 'details'], () => undefined)
navigate('/')
Expand Down Expand Up @@ -242,6 +244,7 @@ export function RunSummary(): JSX.Element {
} else if (isQuickTransfer) {
returnToQuickTransfer()
} else {
closeCurrentRun()
returnToDash()
}
}
Expand All @@ -256,7 +259,6 @@ export function RunSummary(): JSX.Element {
mount: aPipetteWithTip.mount,
robotType: FLEX_ROBOT_TYPE,
onClose: () => {
closeCurrentRun()
runAgain()
},
})
Expand Down

0 comments on commit 2e5b348

Please sign in to comment.