Skip to content

Commit

Permalink
pick the test
Browse files Browse the repository at this point in the history
  • Loading branch information
sfoster1 committed Aug 6, 2024
1 parent 366428f commit 1c96798
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 25 deletions.
126 changes: 115 additions & 11 deletions app/src/pages/ProtocolSetup/__tests__/ProtocolSetup.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,13 @@ import { ANALYTICS_PROTOCOL_RUN_ACTION } from '../../../redux/analytics'
import { ProtocolSetupLiquids } from '../../../organisms/ProtocolSetupLiquids'
import { getProtocolModulesInfo } from '../../../organisms/Devices/ProtocolRun/utils/getProtocolModulesInfo'
import { ProtocolSetupModulesAndDeck } from '../../../organisms/ProtocolSetupModulesAndDeck'
import { ProtocolSetupLabware } from '../../../organisms/ProtocolSetupLabware'
import { ProtocolSetupOffsets } from '../../../organisms/ProtocolSetupOffsets'
import { getUnmatchedModulesForProtocol } from '../../../organisms/ProtocolSetupModulesAndDeck/utils'
import { useLaunchLPC } from '../../../organisms/LabwarePositionCheck/useLaunchLPC'
import { ConfirmCancelRunModal } from '../../../organisms/OnDeviceDisplay/RunningProtocol'
import { mockProtocolModuleInfo } from '../../../organisms/ProtocolSetupInstruments/__fixtures__'
import { getIncompleteInstrumentCount } from '../../../organisms/ProtocolSetupInstruments/utils'
import {
useProtocolHasRunTimeParameters,
useRunControls,
Expand All @@ -51,6 +54,7 @@ import {
import { useIsHeaterShakerInProtocol } from '../../../organisms/ModuleCard/hooks'
import { useDeckConfigurationCompatibility } from '../../../resources/deck_configuration/hooks'
import { ConfirmAttachedModal } from '../../../pages/ProtocolSetup/ConfirmAttachedModal'
import { ConfirmSetupStepsCompleteModal } from '../../../pages/ProtocolSetup/ConfirmSetupStepsCompleteModal'
import { ProtocolSetup } from '../../../pages/ProtocolSetup'
import { useNotifyRunQuery } from '../../../resources/runs'
import { ViewOnlyParameters } from '../../../organisms/ProtocolSetupParameters/ViewOnlyParameters'
Expand Down Expand Up @@ -99,19 +103,23 @@ vi.mock('../../../organisms/ProtocolSetupParameters/ViewOnlyParameters')
vi.mock(
'../../../organisms/LabwarePositionCheck/useMostRecentCompletedAnalysis'
)
vi.mock('../../../organisms/ProtocolSetupInstruments/utils')
vi.mock('../../../organisms/Devices/ProtocolRun/utils/getProtocolModulesInfo')
vi.mock('../../../organisms/ProtocolSetupModulesAndDeck')
vi.mock('../../../organisms/ProtocolSetupModulesAndDeck/utils')
vi.mock('../../../organisms/OnDeviceDisplay/RunningProtocol')
vi.mock('../../../organisms/RunTimeControl/hooks')
vi.mock('../../../organisms/ProtocolSetupLiquids')
vi.mock('../../../organisms/ProtocolSetupLabware')
vi.mock('../../../organisms/ProtocolSetupOffsets')
vi.mock('../../../organisms/ModuleCard/hooks')
vi.mock('../../../redux/discovery/selectors')
vi.mock('../ConfirmAttachedModal')
vi.mock('../../../organisms/ToasterOven')
vi.mock('../../../resources/deck_configuration/hooks')
vi.mock('../../../resources/runs')
vi.mock('../../../resources/deck_configuration')
vi.mock('../ConfirmSetupStepsCompleteModal')

const render = (path = '/') => {
return renderWithProviders(
Expand All @@ -126,6 +134,12 @@ const render = (path = '/') => {
)
}

const MockProtocolSetupLabware = vi.mocked(ProtocolSetupLabware)
const MockProtocolSetupLiquids = vi.mocked(ProtocolSetupLiquids)
const MockProtocolSetupOffsets = vi.mocked(ProtocolSetupOffsets)
const MockConfirmSetupStepsCompleteModal = vi.mocked(
ConfirmSetupStepsCompleteModal
)
const ROBOT_NAME = 'fake-robot-name'
const RUN_ID = 'my-run-id'
const ROBOT_SERIAL_NUMBER = 'OT123'
Expand Down Expand Up @@ -192,6 +206,30 @@ describe('ProtocolSetup', () => {
beforeEach(() => {
mockLaunchLPC = vi.fn()
mockNavigate = vi.fn()
MockProtocolSetupLiquids.mockImplementation(
vi.fn(({ setIsConfirmed, setSetupScreen }) => {
setIsConfirmed(true)
setSetupScreen('prepare to run')
return <div>Mock ProtocolSetupLiquids</div>
})
)
MockProtocolSetupLabware.mockImplementation(
vi.fn(({ setIsConfirmed, setSetupScreen }) => {
setIsConfirmed(true)
setSetupScreen('prepare to run')
return <div>Mock ProtocolSetupLabware</div>
})
)
MockProtocolSetupOffsets.mockImplementation(
vi.fn(({ setIsConfirmed, setSetupScreen }) => {
setIsConfirmed(true)
setSetupScreen('prepare to run')
return <div>Mock ProtocolSetupOffsets</div>
})
)
MockConfirmSetupStepsCompleteModal.mockReturnValue(
<div>Mock ConfirmSetupStepsCompleteModal</div>
)
vi.mocked(useLPCDisabledReason).mockReturnValue(null)
vi.mocked(useAttachedModules).mockReturnValue([])
vi.mocked(useModuleCalibrationStatus).mockReturnValue({ complete: true })
Expand Down Expand Up @@ -290,10 +328,6 @@ describe('ProtocolSetup', () => {
.thenReturn({ trackProtocolRunEvent: mockTrackProtocolRunEvent })
})

afterEach(() => {
vi.resetAllMocks()
})

it('should render text, image, and buttons', () => {
render(`/runs/${RUN_ID}/setup/`)
screen.getByText('Prepare to run')
Expand All @@ -305,9 +339,47 @@ describe('ProtocolSetup', () => {
})

it('should play protocol when click play button', () => {
vi.mocked(useProtocolAnalysisAsDocumentQuery).mockReturnValue({
data: { ...mockRobotSideAnalysis, liquids: mockLiquids },
} as any)
when(vi.mocked(getProtocolModulesInfo))
.calledWith(
{ ...mockRobotSideAnalysis, liquids: mockLiquids },
flexDeckDefV5 as any
)
.thenReturn(mockProtocolModuleInfo)
when(vi.mocked(getUnmatchedModulesForProtocol))
.calledWith([], mockProtocolModuleInfo)
.thenReturn({ missingModuleIds: [], remainingAttachedModules: [] })
vi.mocked(getIncompleteInstrumentCount).mockReturnValue(0)
MockProtocolSetupLiquids.mockImplementation(
vi.fn(({ setIsConfirmed, setSetupScreen }) => {
setIsConfirmed(true)
setSetupScreen('prepare to run')
return <div>Mock ProtocolSetupLiquids</div>
})
)
MockProtocolSetupLabware.mockImplementation(
vi.fn(({ setIsConfirmed, setSetupScreen }) => {
setIsConfirmed(true)
setSetupScreen('prepare to run')
return <div>Mock ProtocolSetupLabware</div>
})
)
MockProtocolSetupOffsets.mockImplementation(
vi.fn(({ setIsConfirmed, setSetupScreen }) => {
setIsConfirmed(true)
setSetupScreen('prepare to run')
return <div>Mock ProtocolSetupOffsets</div>
})
)
render(`/runs/${RUN_ID}/setup/`)
fireEvent.click(screen.getByText('Labware Position Check'))
fireEvent.click(screen.getByText('Labware'))
fireEvent.click(screen.getByText('Liquids'))
expect(mockPlay).toBeCalledTimes(0)
fireEvent.click(screen.getByRole('button', { name: 'play' }))
expect(MockConfirmSetupStepsCompleteModal).toBeCalledTimes(0)
expect(mockPlay).toBeCalledTimes(1)
})

Expand Down Expand Up @@ -348,7 +420,25 @@ describe('ProtocolSetup', () => {
render(`/runs/${RUN_ID}/setup/`)
screen.getByText('1 initial liquid')
fireEvent.click(screen.getByText('Liquids'))
expect(vi.mocked(ProtocolSetupLiquids)).toHaveBeenCalled()
expect(MockProtocolSetupLiquids).toHaveBeenCalled()
})

it('should launch protocol setup labware screen when click labware', () => {
vi.mocked(useProtocolAnalysisAsDocumentQuery).mockReturnValue({
data: { ...mockRobotSideAnalysis, liquids: mockLiquids },
} as any)
when(vi.mocked(getProtocolModulesInfo))
.calledWith(
{ ...mockRobotSideAnalysis, liquids: mockLiquids },
flexDeckDefV5 as any
)
.thenReturn(mockProtocolModuleInfo)
when(vi.mocked(getUnmatchedModulesForProtocol))
.calledWith([], mockProtocolModuleInfo)
.thenReturn({ missingModuleIds: [], remainingAttachedModules: [] })
render(`/runs/${RUN_ID}/setup`)
fireEvent.click(screen.getByTestId('SetupButton_Labware'))
expect(MockProtocolSetupLabware).toHaveBeenCalled()
})

it('should launch view only parameters screen when click parameters', () => {
Expand Down Expand Up @@ -376,14 +466,14 @@ describe('ProtocolSetup', () => {
expect(vi.mocked(ViewOnlyParameters)).toHaveBeenCalled()
})

it('should launch LPC when clicked', () => {
vi.mocked(useLPCDisabledReason).mockReturnValue(null)
it('should launch offsets screen when click offsets', () => {
MockProtocolSetupOffsets.mockImplementation(
vi.fn(() => <div>Mock ProtocolSetupOffsets</div>)
)
render(`/runs/${RUN_ID}/setup/`)
screen.getByText(/Recommended/)
screen.getByText(/1 offset applied/)
fireEvent.click(screen.getByText('Labware Position Check'))
expect(mockLaunchLPC).toHaveBeenCalled()
screen.getByText('mock LPC Wizard')
expect(MockProtocolSetupOffsets).toHaveBeenCalled()
screen.getByText(/Mock ProtocolSetupOffsets/)
})

it('should render a confirmation modal when heater-shaker is in a protocol and it is not shaking', () => {
Expand Down Expand Up @@ -416,7 +506,21 @@ describe('ProtocolSetup', () => {
})

it('calls trackProtocolRunEvent when tapping play button', () => {
vi.mocked(useProtocolAnalysisAsDocumentQuery).mockReturnValue({
data: { ...mockRobotSideAnalysis, liquids: mockLiquids },
} as any)
when(vi.mocked(getProtocolModulesInfo))
.calledWith(
{ ...mockRobotSideAnalysis, liquids: mockLiquids },
flexDeckDefV5 as any
)
.thenReturn(mockProtocolModuleInfo)
when(vi.mocked(getUnmatchedModulesForProtocol))
.calledWith([], mockProtocolModuleInfo)
.thenReturn({ missingModuleIds: [], remainingAttachedModules: [] })
vi.mocked(getIncompleteInstrumentCount).mockReturnValue(0)
render(`/runs/${RUN_ID}/setup/`)

fireEvent.click(screen.getByRole('button', { name: 'play' }))
expect(mockTrackProtocolRunEvent).toBeCalledTimes(1)
expect(mockTrackProtocolRunEvent).toHaveBeenCalledWith({
Expand Down
28 changes: 14 additions & 14 deletions app/src/pages/ProtocolSetup/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ export function ProtocolSetupStep({
: makeDisabledReasonSnackbar()
}}
width="100%"
data-testid={`SetupButton_${title}`}
>
<Flex
alignItems={ALIGN_CENTER}
Expand Down Expand Up @@ -519,25 +520,25 @@ function PrepareToRun({
if (isDoorOpen) {
makeSnackbar(t('shared:close_robot_door') as string)
} else {
if (isReadyToRun && runStatus === RUN_STATUS_IDLE) {
if (!(labwareConfirmed && offsetsConfirmed && liquidsConfirmed)) {
confirmStepsComplete()
}
if (isHeaterShakerInProtocol) {
if (isReadyToRun) {
if (runStatus === RUN_STATUS_IDLE && isHeaterShakerInProtocol) {
confirmAttachment()
}
} else {
if (isReadyToRun) {
} else if (
runStatus === RUN_STATUS_IDLE &&
!(labwareConfirmed && offsetsConfirmed && liquidsConfirmed)
) {
confirmStepsComplete()
} else {
play()
trackProtocolRunEvent({
name: ANALYTICS_PROTOCOL_RUN_ACTION.START,
properties: robotAnalyticsData ?? {},
})
} else {
makeSnackbar(
i18n.format(t('complete_setup_before_proceeding'), 'capitalize')
)
}
} else {
makeSnackbar(
i18n.format(t('complete_setup_before_proceeding'), 'capitalize')
)
}
}
}
Expand Down Expand Up @@ -787,7 +788,7 @@ function PrepareToRun({
onClickSetupStep={() => {
setSetupScreen('labware')
}}
title={t('labware')}
title={i18n.format(t('labware'), 'capitalize')}
detail={labwareDetail}
subDetail={labwareSubDetail}
status={labwareConfirmed ? 'ready' : 'general'}
Expand Down Expand Up @@ -948,7 +949,6 @@ export function ProtocolSetup(): JSX.Element {
!labwareConfirmed ? t('labware_placement') : null,
!liquidsConfirmed ? t('liquids') : null,
].filter(s => s != null)
console.log(missingSteps)
const {
confirm: confirmMissingSteps,
showConfirmation: showMissingStepsConfirmation,
Expand Down

0 comments on commit 1c96798

Please sign in to comment.