Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(app): properly disable proceed button if no available robots #14907

Merged
merged 4 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
})
})
Loading