Skip to content

Commit

Permalink
add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vegano1 committed Oct 29, 2024
1 parent d9f9175 commit 337b515
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 22 deletions.
24 changes: 11 additions & 13 deletions app/src/organisms/EmergencyStop/EstopTakeover.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState } from 'react'
import { useEffect, useState } from 'react'
import { useSelector } from 'react-redux'
import { useEstopQuery } from '@opentrons/react-api-client'

Expand All @@ -23,23 +23,21 @@ export function EstopTakeover({ robotName }: EstopTakeoverProps): JSX.Element {
setIsWatingForResumeOperation,
] = useState<boolean>(false)

const [estopState, setEstopState] = useState<EstopState>(DISENGAGED)
const [showEmergencyStopModal, setShowEmergencyStopModal] = useState<boolean>(
false
)
const [estopState, setEstopState] = useState<EstopState>()
const [showEmergencyStopModal, setShowEmergencyStopModal] = useState<boolean>(false)

// TODO: (ba, 2024-10-24): Use notifications instead of polling
useEstopQuery({
const { data: estopStatus } = useEstopQuery({
refetchInterval: showEmergencyStopModal
? ESTOP_CURRENTLY_ENGAGED_REFETCH_INTERVAL_MS
: ESTOP_CURRENTLY_DISENGAGED_REFETCH_INTERVAL_MS,
onSuccess: response => {
setEstopState(response?.data.status)
setShowEmergencyStopModal(
response.data.status !== DISENGAGED || isWaitingForResumeOperation
)
},
: ESTOP_CURRENTLY_DISENGAGED_REFETCH_INTERVAL_MS
})
useEffect(() => {
if (estopStatus) {
setEstopState(estopStatus.data.status)
setShowEmergencyStopModal(estopStatus.data.status != DISENGAGED || isWaitingForResumeOperation)

Check failure on line 38 in app/src/organisms/EmergencyStop/EstopTakeover.tsx

View workflow job for this annotation

GitHub Actions / js checks

Expected '!==' and instead saw '!='

Check failure on line 38 in app/src/organisms/EmergencyStop/EstopTakeover.tsx

View workflow job for this annotation

GitHub Actions / js checks

Expected '!==' and instead saw '!='
}
}, [estopStatus])

const isUnboxingFlowOngoing = useIsUnboxingFlowOngoing()
const closeModal = (): void => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import type * as React from 'react'
import { fireEvent, screen } from '@testing-library/react'
import '@testing-library/jest-dom/vitest'
import { describe, it, vi, beforeEach, expect } from 'vitest'
import { describe, it, vi, beforeEach, expect, Mock } from 'vitest'

Check failure on line 4 in app/src/organisms/EmergencyStop/__tests__/EstopPressedModal.test.tsx

View workflow job for this annotation

GitHub Actions / js checks

'Mock' is defined but never used

Check failure on line 4 in app/src/organisms/EmergencyStop/__tests__/EstopPressedModal.test.tsx

View workflow job for this annotation

GitHub Actions / js checks

'Mock' is defined but never used
import { renderWithProviders } from '/app/__testing-utils__'
import { useAcknowledgeEstopDisengageMutation } from '@opentrons/react-api-client'

import { i18n } from '/app/i18n'
import { getIsOnDevice } from '/app/redux/config'
import { EstopPressedModal } from '../EstopPressedModal'
import { usePlacePlateReaderLid } from '/app/resources/modules'

vi.mock('@opentrons/react-api-client')
vi.mock('/app/redux/config')
vi.mock('/app/resources/modules')

const render = (props: React.ComponentProps<typeof EstopPressedModal>) => {
return renderWithProviders(<EstopPressedModal {...props} />, {
Expand All @@ -25,13 +27,19 @@ describe('EstopPressedModal - Touchscreen', () => {
props = {
isEngaged: true,
closeModal: vi.fn(),
isWaitingForLogicalDisengage: false,
setShouldSeeLogicalDisengage: vi.fn(),
isWaitingForResumeOperation: false,
setIsWaitingForResumeOperation: vi.fn(),
}
vi.mocked(getIsOnDevice).mockReturnValue(true)
vi.mocked(useAcknowledgeEstopDisengageMutation).mockReturnValue({
setEstopPhysicalStatus: vi.fn(),
} as any)

vi.mocked(usePlacePlateReaderLid).mockReturnValue({
handlePlaceReaderLid: vi.fn(),
isValidPlateReaderMove: false,
isExecuting: false,
})
})

it('should render text and button', () => {
Expand Down Expand Up @@ -59,6 +67,20 @@ describe('EstopPressedModal - Touchscreen', () => {
render(props)
fireEvent.click(screen.getByText('Resume robot operations'))
expect(useAcknowledgeEstopDisengageMutation).toHaveBeenCalled()
expect(usePlacePlateReaderLid).toHaveBeenCalled()
})

it('should call a mock function to place the labware to a slot', () => {
vi.mocked(usePlacePlateReaderLid).mockReturnValue({
handlePlaceReaderLid: vi.fn(),
isValidPlateReaderMove: true,
isExecuting: true,
})

render(props)
fireEvent.click(screen.getByText('Resume robot operations'))
expect(useAcknowledgeEstopDisengageMutation).toHaveBeenCalled()
expect(usePlacePlateReaderLid).toHaveBeenCalled()
})
})

Expand All @@ -69,15 +91,19 @@ describe('EstopPressedModal - Desktop', () => {
props = {
isEngaged: true,
closeModal: vi.fn(),
isDismissedModal: false,
setIsDismissedModal: vi.fn(),
isWaitingForLogicalDisengage: false,
setShouldSeeLogicalDisengage: vi.fn(),
isWaitingForResumeOperation: false,
setIsWaitingForResumeOperation: vi.fn(),
}
vi.mocked(getIsOnDevice).mockReturnValue(false)
vi.mocked(useAcknowledgeEstopDisengageMutation).mockReturnValue({
setEstopPhysicalStatus: vi.fn(),
} as any)

vi.mocked(usePlacePlateReaderLid).mockReturnValue({
handlePlaceReaderLid: vi.fn(),
isValidPlateReaderMove: false,
isExecuting: false,
})
})
it('should render text and button', () => {
render(props)
Expand All @@ -99,10 +125,18 @@ describe('EstopPressedModal - Desktop', () => {
).not.toBeDisabled()
})

it('should resume robot operation button is disabled when waiting for labware plate to finish', () => {
props.isEngaged = false
props.isWaitingForResumeOperation = true
render(props)
expect(
screen.getByRole('button', { name: 'Resume robot operations' })
).toBeDisabled()
})

it('should call a mock function when clicking close icon', () => {
render(props)
fireEvent.click(screen.getByTestId('ModalHeader_icon_close_E-stop pressed'))
expect(props.setIsDismissedModal).toHaveBeenCalled()
expect(props.closeModal).toHaveBeenCalled()
})

Expand Down
1 change: 0 additions & 1 deletion shared-data/command/types/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ export type OnDeckLabwareLocation =
| { labwareId: string }
| { addressableAreaName: AddressableAreaName }


export type NonStackedLocation =
| 'offDeck'
| { slotName: string }
Expand Down

0 comments on commit 337b515

Please sign in to comment.