Skip to content

Commit

Permalink
fix(app): enable doorSafetySwitch for OT-2 (#13627)
Browse files Browse the repository at this point in the history
* fix(app): enable doorSafetySwitch for OT-2
  • Loading branch information
koji authored Sep 22, 2023
1 parent 67eb2ec commit dc8d032
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 5 deletions.
21 changes: 18 additions & 3 deletions app/src/organisms/Devices/ProtocolRun/ProtocolRunHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import {
} from '@opentrons/components'

import { getRobotUpdateDisplayInfo } from '../../../redux/robot-update'
import { getRobotSettings } from '../../../redux/robot-settings'
import { ProtocolAnalysisErrorBanner } from './ProtocolAnalysisErrorBanner'
import { ProtocolAnalysisErrorModal } from './ProtocolAnalysisErrorModal'
import { Banner } from '../../../atoms/Banner'
Expand Down Expand Up @@ -83,6 +84,7 @@ import {
useIsRobotViewable,
useTrackProtocolRunEvent,
useRobotAnalyticsData,
useIsOT3,
} from '../hooks'
import { formatTimestamp } from '../utils'
import { RunTimer } from './RunTimer'
Expand Down Expand Up @@ -140,12 +142,25 @@ export function ProtocolRunHeader({
runRecord?.data.errors?.[0] != null
? getHighestPriorityError(runRecord?.data?.errors)
: null

const robotSettings = useSelector((state: State) =>
getRobotSettings(state, robotName)
)
const doorSafetySetting = robotSettings.find(
setting => setting.id === 'enableDoorSafetySwitch'
)
const isOT3 = useIsOT3(robotName)
const { data: doorStatus } = useDoorQuery({
refetchInterval: EQUIPMENT_POLL_MS,
})
const isDoorOpen =
doorStatus?.data.status === 'open' &&
doorStatus?.data.doorRequiredClosedForProtocol
let isDoorOpen = false
if (isOT3) {
isDoorOpen = doorStatus?.data.status === 'open'
} else if (!isOT3 && Boolean(doorSafetySetting?.value)) {
isDoorOpen = doorStatus?.data.status === 'open'
} else {
isDoorOpen = false
}

React.useEffect(() => {
if (protocolData != null && !isRobotViewable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import {
} from '../../../../redux/analytics'
import { getRobotUpdateDisplayInfo } from '../../../../redux/robot-update'
import { getIsHeaterShakerAttached } from '../../../../redux/config'
import { getRobotSettings } from '../../../../redux/robot-settings'

import {
useProtocolDetailsForRun,
Expand Down Expand Up @@ -111,6 +112,7 @@ jest.mock('../../../../redux/analytics')
jest.mock('../../../../redux/config')
jest.mock('../RunFailedModal')
jest.mock('../../../../redux/robot-update/selectors')
jest.mock('../../../../redux/robot-settings/selectors')

const mockGetIsHeaterShakerAttached = getIsHeaterShakerAttached as jest.MockedFunction<
typeof getIsHeaterShakerAttached
Expand Down Expand Up @@ -192,13 +194,23 @@ const mockUseIsOT3 = useIsOT3 as jest.MockedFunction<typeof useIsOT3>
const mockUseDoorQuery = useDoorQuery as jest.MockedFunction<
typeof useDoorQuery
>
const mockGetRobotSettings = getRobotSettings as jest.MockedFunction<
typeof getRobotSettings
>

const ROBOT_NAME = 'otie'
const RUN_ID = '95e67900-bc9f-4fbf-92c6-cc4d7226a51b'
const CREATED_AT = '03/03/2022 19:08:49'
const STARTED_AT = '2022-03-03T19:09:40.620530+00:00'
const COMPLETED_AT = '2022-03-03T19:39:53.620530+00:00'
const PROTOCOL_NAME = 'A Protocol for Otie'
const mockSettings = {
id: 'enableDoorSafetySwitch',
title: 'Enable Door Safety Switch',
description: '',
value: true,
restart_required: false,
}

const simpleV6Protocol = (_uncastedSimpleV6Protocol as unknown) as CompletedProtocolAnalysis

Expand Down Expand Up @@ -351,10 +363,11 @@ describe('ProtocolRunHeader', () => {
when(mockUseRunCalibrationStatus)
.calledWith(ROBOT_NAME, RUN_ID)
.mockReturnValue({ complete: true })
mockUseIsOT3.mockReturnValue(true)
when(mockUseIsOT3).calledWith(ROBOT_NAME).mockReturnValue(true)
mockRunFailedModal.mockReturnValue(<div>mock RunFailedModal</div>)
mockUseEstopQuery.mockReturnValue({ data: mockEstopStatus } as any)
mockUseDoorQuery.mockReturnValue({ data: mockDoorStatus } as any)
mockGetRobotSettings.mockReturnValue([mockSettings])
})

afterEach(() => {
Expand Down Expand Up @@ -849,12 +862,36 @@ describe('ProtocolRunHeader', () => {
getByLabelText('ot-spinner')
})

it('renders banner when the robot door is open', () => {
it('renders door close banner when the robot door is open', () => {
const mockOpenDoorStatus = {
data: { status: 'open', doorRequiredClosedForProtocol: true },
}
mockUseDoorQuery.mockReturnValue({ data: mockOpenDoorStatus } as any)
const [{ getByText }] = render()
getByText('Close the robot door before starting the run.')
})

it('should render door close banner when door is open and enabled safety door switch is on - OT-2', () => {
when(mockUseIsOT3).calledWith(ROBOT_NAME).mockReturnValue(false)
const mockOpenDoorStatus = {
data: { status: 'open', doorRequiredClosedForProtocol: true },
}
mockUseDoorQuery.mockReturnValue({ data: mockOpenDoorStatus } as any)
const [{ getByText }] = render()
getByText('Close the robot door before starting the run.')
})

it('should not render door close banner when door is open and enabled safety door switch is off - OT-2', () => {
when(mockUseIsOT3).calledWith(ROBOT_NAME).mockReturnValue(false)
const mockOffSettings = { ...mockSettings, value: false }
mockGetRobotSettings.mockReturnValue([mockOffSettings])
const mockOpenDoorStatus = {
data: { status: 'open', doorRequiredClosedForProtocol: true },
}
mockUseDoorQuery.mockReturnValue({ data: mockOpenDoorStatus } as any)
const [{ queryByText }] = render()
expect(
queryByText('Close the robot door before starting the run.')
).not.toBeInTheDocument()
})
})

0 comments on commit dc8d032

Please sign in to comment.