Skip to content

Commit

Permalink
fix(app): show usb icon for OT-2 usb connection (#13605)
Browse files Browse the repository at this point in the history
fixes a reversion introduced by the Flex icon priority changes. since an OT-2 usb connection is
actually an ethernet connection inside the frame of the OT-2, we need to only render the ethernet
icon for the Flex.

closes RQA-1556
  • Loading branch information
brenthagen authored Sep 20, 2023
1 parent 2637a15 commit ae74b67
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
11 changes: 8 additions & 3 deletions app/src/organisms/Devices/RobotStatusHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
import { QuaternaryButton } from '../../atoms/buttons'
import { StyledText } from '../../atoms/text'
import { Tooltip } from '../../atoms/Tooltip'
import { useIsOT3 } from '../../organisms/Devices/hooks'
import { useCurrentRunId } from '../../organisms/ProtocolUpload/hooks'
import { useCurrentRunStatus } from '../../organisms/RunTimeControl/hooks'
import {
Expand Down Expand Up @@ -51,6 +52,7 @@ export function RobotStatusHeader(props: RobotStatusHeaderProps): JSX.Element {
const [targetProps, tooltipProps] = useHoverTooltip()
const dispatch = useDispatch<Dispatch>()

const isOT3 = useIsOT3(name)
const currentRunId = useCurrentRunId()
const currentRunStatus = useCurrentRunStatus()
const { data: runRecord } = useRunQuery(currentRunId, { staleTime: Infinity })
Expand Down Expand Up @@ -94,14 +96,17 @@ export function RobotStatusHeader(props: RobotStatusHeaderProps): JSX.Element {
)

const wifiAddress = addresses.find(addr => addr.ip === wifi?.ipAddress)
const isOT3ConnectedViaWifi =
const isConnectedViaWifi =
wifiAddress != null && wifiAddress.healthStatus === HEALTH_STATUS_OK

const ethernetAddress = addresses.find(
addr => addr.ip === ethernet?.ipAddress
)
// do not show ethernet connection for OT-2
const isOT3ConnectedViaEthernet =
ethernetAddress != null && ethernetAddress.healthStatus === HEALTH_STATUS_OK
isOT3 &&
ethernetAddress != null &&
ethernetAddress.healthStatus === HEALTH_STATUS_OK

const usbAddress = addresses.find(addr => addr.ip === OPENTRONS_USB)
const isOT3ConnectedViaUSB =
Expand All @@ -112,7 +117,7 @@ export function RobotStatusHeader(props: RobotStatusHeaderProps): JSX.Element {
if (isOT3ConnectedViaEthernet) {
iconName = 'ethernet'
tooltipTranslationKey = 'device_settings:ethernet'
} else if (isOT3ConnectedViaWifi) {
} else if (isConnectedViaWifi) {
iconName = 'wifi'
tooltipTranslationKey = 'device_settings:wifi'
} else if ((local != null && local) || isOT3ConnectedViaUSB) {
Expand Down
16 changes: 16 additions & 0 deletions app/src/organisms/Devices/__tests__/RobotStatusHeader.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
} from '../../../redux/discovery'
import { getNetworkInterfaces } from '../../../redux/networking'

import { useIsOT3 } from '../hooks'
import { RobotStatusHeader } from '../RobotStatusHeader'

import type { DiscoveryClientRobotAddress } from '../../../redux/discovery/types'
Expand Down Expand Up @@ -45,6 +46,7 @@ const mockGetNetworkInterfaces = getNetworkInterfaces as jest.MockedFunction<
const mockGetRobotAddressesByName = getRobotAddressesByName as jest.MockedFunction<
typeof getRobotAddressesByName
>
const mockUseIsOT3 = useIsOT3 as jest.MockedFunction<typeof useIsOT3>

const MOCK_OTIE = {
name: 'otie',
Expand Down Expand Up @@ -118,6 +120,7 @@ describe('RobotStatusHeader', () => {
healthStatus: HEALTH_STATUS_OK,
} as DiscoveryClientRobotAddress,
])
when(mockUseIsOT3).calledWith('otie').mockReturnValue(true)
})
afterEach(() => {
resetAllWhenMocks()
Expand Down Expand Up @@ -203,6 +206,19 @@ describe('RobotStatusHeader', () => {
getByLabelText('wifi')
})

it('renders a usb icon when OT-2 connected locally via USB-ethernet adapter', () => {
when(mockGetNetworkInterfaces)
.calledWith({} as State, 'otie')
.mockReturnValue({
wifi: null,
ethernet: { ipAddress: ETHERNET_IP } as SimpleInterfaceStatus,
})
when(mockUseIsOT3).calledWith('otie').mockReturnValue(false)
const [{ getByLabelText }] = render(props)

getByLabelText('usb')
})

it('renders a usb icon when only connected locally', () => {
const [{ getByLabelText }] = render(props)

Expand Down

0 comments on commit ae74b67

Please sign in to comment.