Skip to content

Commit

Permalink
fix(app): properly disable proceed button if no available robots (#14907
Browse files Browse the repository at this point in the history
)

closes RQA-2517
  • Loading branch information
ncdiehl11 authored Apr 15, 2024
1 parent 55f798a commit 8cc2fc7
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { vi, it, describe, expect, beforeEach } from 'vitest'

import { StaticRouter } from 'react-router-dom'
import { fireEvent, screen } from '@testing-library/react'
import { OT2_ROBOT_TYPE } from '@opentrons/shared-data'

import { renderWithProviders } from '../../../__testing-utils__'
import { i18n } from '../../../i18n'
Expand All @@ -22,7 +23,7 @@ import { useFeatureFlag } from '../../../redux/config'
import { getNetworkInterfaces } from '../../../redux/networking'
import { ChooseRobotSlideout } from '..'
import { useNotifyService } from '../../../resources/useNotifyService'
import { OT2_ROBOT_TYPE, RunTimeParameter } from '@opentrons/shared-data'
import type { RunTimeParameter } from '@opentrons/shared-data'

vi.mock('../../../redux/discovery')
vi.mock('../../../redux/robot-update')
Expand Down Expand Up @@ -295,4 +296,18 @@ describe('ChooseRobotSlideout', () => {
ip: 'otherIp',
})
})

it('sets selected robot to null if no available robots', () => {
vi.mocked(getConnectableRobots).mockReturnValue([])
render({
onCloseClick: vi.fn(),
isExpanded: true,
isSelectedRobotOnDifferentSoftwareVersion: false,
selectedRobot: null,
setSelectedRobot: mockSetSelectedRobot,
title: 'choose robot slideout title',
robotType: OT2_ROBOT_TYPE,
})
expect(mockSetSelectedRobot).toBeCalledWith(null)
})
})
9 changes: 6 additions & 3 deletions app/src/organisms/ChooseRobotSlideout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,18 @@ export function ChooseRobotSlideout(
{}
)

const reducerAvailableRobots = healthyReachableRobots.filter(robot =>
showIdleOnly ? !robotBusyStatusByName[robot.name] : robot
)
const reducerBusyCount = healthyReachableRobots.filter(
robot => robotBusyStatusByName[robot.name]
).length

// this useEffect sets the default selection to the first robot in the list. state is managed by the caller
React.useEffect(() => {
if (selectedRobot == null && healthyReachableRobots.length > 0) {
setSelectedRobot(healthyReachableRobots[0])
} else if (healthyReachableRobots.length === 0) {
if (selectedRobot == null && reducerAvailableRobots.length > 0) {
setSelectedRobot(reducerAvailableRobots[0])
} else if (reducerAvailableRobots.length === 0) {
setSelectedRobot(null)
}
}, [healthyReachableRobots, selectedRobot, setSelectedRobot])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,4 +390,17 @@ describe('ChooseRobotToRunProtocolSlideout', () => {
{}
)
})

it('disables proceed button if no available robots', () => {
vi.mocked(getConnectableRobots).mockReturnValue([])
render({
storedProtocolData: storedProtocolDataFixture,
onCloseClick: vi.fn(),
showSlideout: true,
})
const proceedButton = screen.getByRole('button', {
name: 'Continue to parameters',
})
expect(proceedButton).toBeDisabled()
})
})

0 comments on commit 8cc2fc7

Please sign in to comment.