From 337b515d05f7b13ae9d3adf5b795d57d618380d4 Mon Sep 17 00:00:00 2001 From: vegano1 Date: Tue, 29 Oct 2024 11:27:53 -0400 Subject: [PATCH] add unit tests --- .../organisms/EmergencyStop/EstopTakeover.tsx | 24 ++++----- .../__tests__/EstopPressedModal.test.tsx | 50 ++++++++++++++++--- shared-data/command/types/setup.ts | 1 - 3 files changed, 53 insertions(+), 22 deletions(-) diff --git a/app/src/organisms/EmergencyStop/EstopTakeover.tsx b/app/src/organisms/EmergencyStop/EstopTakeover.tsx index 8512b6c29ec..cf447ae2283 100644 --- a/app/src/organisms/EmergencyStop/EstopTakeover.tsx +++ b/app/src/organisms/EmergencyStop/EstopTakeover.tsx @@ -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' @@ -23,23 +23,21 @@ export function EstopTakeover({ robotName }: EstopTakeoverProps): JSX.Element { setIsWatingForResumeOperation, ] = useState(false) - const [estopState, setEstopState] = useState(DISENGAGED) - const [showEmergencyStopModal, setShowEmergencyStopModal] = useState( - false - ) + const [estopState, setEstopState] = useState() + const [showEmergencyStopModal, setShowEmergencyStopModal] = useState(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) + } + }, [estopStatus]) const isUnboxingFlowOngoing = useIsUnboxingFlowOngoing() const closeModal = (): void => { diff --git a/app/src/organisms/EmergencyStop/__tests__/EstopPressedModal.test.tsx b/app/src/organisms/EmergencyStop/__tests__/EstopPressedModal.test.tsx index 124ea72b3ed..1c1e6a3712d 100644 --- a/app/src/organisms/EmergencyStop/__tests__/EstopPressedModal.test.tsx +++ b/app/src/organisms/EmergencyStop/__tests__/EstopPressedModal.test.tsx @@ -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' 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) => { return renderWithProviders(, { @@ -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', () => { @@ -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() }) }) @@ -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) @@ -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() }) diff --git a/shared-data/command/types/setup.ts b/shared-data/command/types/setup.ts index 493d55c349c..13d29c682b4 100644 --- a/shared-data/command/types/setup.ts +++ b/shared-data/command/types/setup.ts @@ -112,7 +112,6 @@ export type OnDeckLabwareLocation = | { labwareId: string } | { addressableAreaName: AddressableAreaName } - export type NonStackedLocation = | 'offDeck' | { slotName: string }