diff --git a/app/src/organisms/Devices/ProtocolRun/__tests__/SetupDeckCalibration.test.tsx b/app/src/organisms/Devices/ProtocolRun/__tests__/SetupDeckCalibration.test.tsx index 52eb5e76cc4..b1462eb9cbd 100644 --- a/app/src/organisms/Devices/ProtocolRun/__tests__/SetupDeckCalibration.test.tsx +++ b/app/src/organisms/Devices/ProtocolRun/__tests__/SetupDeckCalibration.test.tsx @@ -1,19 +1,16 @@ import * as React from 'react' -import { when, resetAllWhenMocks } from 'jest-when' +import { when } from 'vitest-when' import { MemoryRouter } from 'react-router-dom' +import { describe, it, beforeEach, afterEach, vi, expect } from 'vitest' +import { screen } from '@testing-library/react' -import { renderWithProviders } from '@opentrons/components' - +import { renderWithProviders } from '../../../../__testing-utils__' import { i18n } from '../../../../i18n' import { mockDeckCalData } from '../../../../redux/calibration/__fixtures__' import { useDeckCalibrationData } from '../../hooks' import { SetupDeckCalibration } from '../SetupDeckCalibration' -jest.mock('../../hooks') - -const mockUseDeckCalibrationData = useDeckCalibrationData as jest.MockedFunction< - typeof useDeckCalibrationData -> +vi.mock('../../hooks') const ROBOT_NAME = 'otie' const RUN_ID = '1' @@ -31,32 +28,34 @@ const render = () => { describe('SetupDeckCalibration', () => { beforeEach(() => { - when(mockUseDeckCalibrationData).calledWith(ROBOT_NAME).mockReturnValue({ + when(vi.mocked(useDeckCalibrationData)).calledWith(ROBOT_NAME).thenReturn({ deckCalibrationData: mockDeckCalData, isDeckCalibrated: true, }) }) afterEach(() => { - resetAllWhenMocks() + vi.resetAllMocks() }) it('renders last calibrated content when deck is calibrated', () => { - const { getByText, queryByText } = render() - getByText('Deck Calibration') - queryByText('Last calibrated:') + render() + screen.getByText('Deck Calibration') + screen.queryByText('Last calibrated:') }) it('renders a link to the calibration dashboard if deck is not calibrated', () => { - when(mockUseDeckCalibrationData).calledWith(ROBOT_NAME).mockReturnValue({ + when(vi.mocked(useDeckCalibrationData)).calledWith(ROBOT_NAME).thenReturn({ deckCalibrationData: null, isDeckCalibrated: false, }) - const { getByRole, getByText } = render() + render() - getByText('Not calibrated yet') + screen.getByText('Not calibrated yet') expect( - getByRole('link', { - name: 'Calibrate now', - }).getAttribute('href') + screen + .getByRole('link', { + name: 'Calibrate now', + }) + .getAttribute('href') ).toBe('/devices/otie/robot-settings/calibration/dashboard') }) }) diff --git a/app/src/organisms/Devices/ProtocolRun/__tests__/SetupFlexPipetteCalibrationItem.test.tsx b/app/src/organisms/Devices/ProtocolRun/__tests__/SetupFlexPipetteCalibrationItem.test.tsx index e7f439e2f3b..65dfccbf6a4 100644 --- a/app/src/organisms/Devices/ProtocolRun/__tests__/SetupFlexPipetteCalibrationItem.test.tsx +++ b/app/src/organisms/Devices/ProtocolRun/__tests__/SetupFlexPipetteCalibrationItem.test.tsx @@ -1,11 +1,11 @@ import * as React from 'react' -import { resetAllWhenMocks } from 'jest-when' import { MemoryRouter } from 'react-router-dom' -import { fireEvent } from '@testing-library/react' +import { fireEvent, screen } from '@testing-library/react' +import { describe, it, beforeEach, vi, afterEach } from 'vitest' -import { renderWithProviders } from '@opentrons/components' import { useInstrumentsQuery } from '@opentrons/react-api-client' +import { renderWithProviders } from '../../../../__testing-utils__' import { i18n } from '../../../../i18n' import { useMostRecentCompletedAnalysis } from '../../../LabwarePositionCheck/useMostRecentCompletedAnalysis' import { PipetteWizardFlows } from '../../../PipetteWizardFlows' @@ -13,20 +13,10 @@ import { SetupFlexPipetteCalibrationItem } from '../SetupFlexPipetteCalibrationI import _uncastedModifiedSimpleV6Protocol from '../../hooks/__fixtures__/modifiedSimpleV6.json' import { CompletedProtocolAnalysis } from '@opentrons/shared-data' -jest.mock('@opentrons/react-api-client') -jest.mock('../../../PipetteWizardFlows') -jest.mock('../../../LabwarePositionCheck/useMostRecentCompletedAnalysis') -jest.mock('../../hooks') - -const mockUseInstrumentsQuery = useInstrumentsQuery as jest.MockedFunction< - typeof useInstrumentsQuery -> -const mockUseMostRecentCompletedAnalysis = useMostRecentCompletedAnalysis as jest.MockedFunction< - typeof useMostRecentCompletedAnalysis -> -const mockPipetteWizardFlows = PipetteWizardFlows as jest.MockedFunction< - typeof PipetteWizardFlows -> +vi.mock('@opentrons/react-api-client') +vi.mock('../../../PipetteWizardFlows') +vi.mock('../../../LabwarePositionCheck/useMostRecentCompletedAnalysis') +vi.mock('../../hooks') const RUN_ID = '1' const modifiedSimpleV6Protocol = ({ @@ -60,34 +50,39 @@ describe('SetupFlexPipetteCalibrationItem', () => { } beforeEach(() => { - mockPipetteWizardFlows.mockReturnValue(
pipette wizard flows
) - mockUseMostRecentCompletedAnalysis.mockReturnValue(modifiedSimpleV6Protocol) - mockUseInstrumentsQuery.mockReturnValue({ + vi.mocked(PipetteWizardFlows).mockReturnValue( +
pipette wizard flows
+ ) + vi.mocked(useMostRecentCompletedAnalysis).mockReturnValue( + modifiedSimpleV6Protocol + ) + vi.mocked(useInstrumentsQuery).mockReturnValue({ data: { data: [], }, } as any) }) afterEach(() => { - resetAllWhenMocks() + vi.clearAllMocks() }) it('renders the mount and pipette name', () => { - const { getByText } = render() - getByText('Left Mount') - getByText('P10 Single-Channel GEN1') + render() + screen.getByText('Left Mount') + screen.getByText('P10 Single-Channel GEN1') }) it('renders an attach button if on a Flex and pipette is not attached', () => { - const { getByText, getByRole } = render() - getByText('Left Mount') - getByText('P10 Single-Channel GEN1') - const attach = getByRole('button', { name: 'Attach Pipette' }) + render() + screen.getByText('Left Mount') + screen.getByText('P10 Single-Channel GEN1') + const attach = screen.getByRole('button', { name: 'Attach Pipette' }) fireEvent.click(attach) - getByText('pipette wizard flows') + screen.getByText('pipette wizard flows') }) + it('renders a calibrate button if on a Flex and pipette is not calibrated', () => { - mockUseInstrumentsQuery.mockReturnValue({ + vi.mocked(useInstrumentsQuery).mockReturnValue({ data: { data: [ { @@ -101,15 +96,16 @@ describe('SetupFlexPipetteCalibrationItem', () => { ], }, } as any) - const { getByText, getByRole } = render() - getByText('Left Mount') - getByText('P10 Single-Channel GEN1') - const attach = getByRole('button', { name: 'Calibrate now' }) + render() + screen.getByText('Left Mount') + screen.getByText('P10 Single-Channel GEN1') + const attach = screen.getByRole('button', { name: 'Calibrate now' }) fireEvent.click(attach) - getByText('pipette wizard flows') + screen.getByText('pipette wizard flows') }) + it('renders calibrated text if on a Flex and pipette is calibrated', () => { - mockUseInstrumentsQuery.mockReturnValue({ + vi.mocked(useInstrumentsQuery).mockReturnValue({ data: { data: [ { @@ -127,9 +123,9 @@ describe('SetupFlexPipetteCalibrationItem', () => { ], }, } as any) - const { getByText } = render() - getByText('Left Mount') - getByText('P10 Single-Channel GEN1') - getByText('Last calibrated: today') + render() + screen.getByText('Left Mount') + screen.getByText('P10 Single-Channel GEN1') + screen.getByText('Last calibrated: today') }) }) diff --git a/app/src/organisms/Devices/ProtocolRun/__tests__/SetupPipetteCalibration.test.tsx b/app/src/organisms/Devices/ProtocolRun/__tests__/SetupPipetteCalibration.test.tsx index da83290e178..d09670fb1ad 100644 --- a/app/src/organisms/Devices/ProtocolRun/__tests__/SetupPipetteCalibration.test.tsx +++ b/app/src/organisms/Devices/ProtocolRun/__tests__/SetupPipetteCalibration.test.tsx @@ -1,8 +1,9 @@ import * as React from 'react' -import { when, resetAllWhenMocks } from 'jest-when' - -import { renderWithProviders } from '@opentrons/components' +import { when } from 'vitest-when' +import { describe, it, beforeEach, vi, afterEach, expect } from 'vitest' +import { screen } from '@testing-library/react' +import { renderWithProviders } from '../../../../__testing-utils__' import { i18n } from '../../../../i18n' import { mockTipRackDefinition } from '../../../../redux/custom-labware/__fixtures__' import { useRunPipetteInfoByMount } from '../../hooks' @@ -10,15 +11,8 @@ import { SetupPipetteCalibrationItem } from '../SetupPipetteCalibrationItem' import { SetupInstrumentCalibration } from '../SetupInstrumentCalibration' import type { PipetteInfo } from '../../hooks' -jest.mock('../../hooks') -jest.mock('../SetupPipetteCalibrationItem') - -const mockUseRunPipetteInfoByMount = useRunPipetteInfoByMount as jest.MockedFunction< - typeof useRunPipetteInfoByMount -> -const mockSetupPipetteCalibrationItem = SetupPipetteCalibrationItem as jest.MockedFunction< - typeof SetupPipetteCalibrationItem -> +vi.mock('../../hooks') +vi.mock('../SetupPipetteCalibrationItem') const ROBOT_NAME = 'otie' const RUN_ID = '1' @@ -49,32 +43,36 @@ const render = () => { describe('SetupPipetteCalibration', () => { beforeEach(() => { - when(mockUseRunPipetteInfoByMount).calledWith(RUN_ID).mockReturnValue({ + when(vi.mocked(useRunPipetteInfoByMount)).calledWith(RUN_ID).thenReturn({ left: PIPETTE_INFO, right: null, }) - when(mockSetupPipetteCalibrationItem).mockReturnValue( + vi.mocked(SetupPipetteCalibrationItem).mockReturnValue(
Mock SetupPipetteCalibrationItem
) }) afterEach(() => { - resetAllWhenMocks() + vi.clearAllMocks() }) it('renders required pipettes title', () => { - const { getByText } = render() - getByText('Required Instrument Calibrations') + render() + screen.getByText('Required Instrument Calibrations') }) it('renders one SetupPipetteCalibrationItem when protocol run requires one pipette', () => { - const { getAllByText } = render() - expect(getAllByText('Mock SetupPipetteCalibrationItem')).toHaveLength(1) + render() + expect( + screen.getAllByText('Mock SetupPipetteCalibrationItem') + ).toHaveLength(1) }) it('renders two SetupPipetteCalibrationItems when protocol run requires two pipettes', () => { - when(mockUseRunPipetteInfoByMount).calledWith(RUN_ID).mockReturnValue({ + when(vi.mocked(useRunPipetteInfoByMount)).calledWith(RUN_ID).thenReturn({ left: PIPETTE_INFO, right: PIPETTE_INFO, }) - const { getAllByText } = render() - expect(getAllByText('Mock SetupPipetteCalibrationItem')).toHaveLength(2) + render() + expect( + screen.getAllByText('Mock SetupPipetteCalibrationItem') + ).toHaveLength(2) }) }) diff --git a/app/src/organisms/Devices/ProtocolRun/__tests__/SetupPipetteCalibrationItem.test.tsx b/app/src/organisms/Devices/ProtocolRun/__tests__/SetupPipetteCalibrationItem.test.tsx index 5c9463d54da..482235a1a86 100644 --- a/app/src/organisms/Devices/ProtocolRun/__tests__/SetupPipetteCalibrationItem.test.tsx +++ b/app/src/organisms/Devices/ProtocolRun/__tests__/SetupPipetteCalibrationItem.test.tsx @@ -1,8 +1,7 @@ import * as React from 'react' import { when, resetAllWhenMocks } from 'jest-when' -import { renderWithProviders } from '@opentrons/components' - +import { renderWithProviders } from '../../../../__testing-utils__'} import { i18n } from '../../../../i18n' import { mockDeckCalData } from '../../../../redux/calibration/__fixtures__' import { mockPipetteInfo } from '../../../../redux/pipettes/__fixtures__' diff --git a/app/src/organisms/Devices/ProtocolRun/__tests__/SetupRobotCalibration.test.tsx b/app/src/organisms/Devices/ProtocolRun/__tests__/SetupRobotCalibration.test.tsx index d2fa47c9973..28b09fe0d80 100644 --- a/app/src/organisms/Devices/ProtocolRun/__tests__/SetupRobotCalibration.test.tsx +++ b/app/src/organisms/Devices/ProtocolRun/__tests__/SetupRobotCalibration.test.tsx @@ -1,9 +1,9 @@ import * as React from 'react' -import { when, resetAllWhenMocks } from 'jest-when' -import { fireEvent } from '@testing-library/react' - -import { renderWithProviders } from '@opentrons/components' +import { when } from 'vitest-when' +import { fireEvent, screen } from '@testing-library/react' +import { describe, it, beforeEach, vi, afterEach, expect } from 'vitest' +import { renderWithProviders } from '../../../../__testing-utils__' import { i18n } from '../../../../i18n' import { useTrackEvent, @@ -20,38 +20,18 @@ import { SetupInstrumentCalibration } from '../SetupInstrumentCalibration' import { SetupTipLengthCalibration } from '../SetupTipLengthCalibration' import { SetupRobotCalibration } from '../SetupRobotCalibration' -jest.mock('../../../../redux/analytics') -jest.mock('../../hooks') -jest.mock('../SetupDeckCalibration') -jest.mock('../SetupInstrumentCalibration') -jest.mock('../SetupTipLengthCalibration') - -const mockUseTrackEvent = useTrackEvent as jest.MockedFunction< - typeof useTrackEvent -> -const mockSetupDeckCalibration = SetupDeckCalibration as jest.MockedFunction< - typeof SetupDeckCalibration -> -const mockSetupInstrumentCalibration = SetupInstrumentCalibration as jest.MockedFunction< - typeof SetupInstrumentCalibration -> -const mockSetupTipLengthCalibration = SetupTipLengthCalibration as jest.MockedFunction< - typeof SetupTipLengthCalibration -> -const mockUseDeckCalibrationData = useDeckCalibrationData as jest.MockedFunction< - typeof useDeckCalibrationData -> -const mockUseRunHasStarted = useRunHasStarted as jest.MockedFunction< - typeof useRunHasStarted -> -const mockUseIsFlex = useIsFlex as jest.MockedFunction +vi.mock('../../../../redux/analytics') +vi.mock('../../hooks') +vi.mock('../SetupDeckCalibration') +vi.mock('../SetupInstrumentCalibration') +vi.mock('../SetupTipLengthCalibration') const ROBOT_NAME = 'otie' const RUN_ID = '1' describe('SetupRobotCalibration', () => { - const mockExpandStep = jest.fn() - const mockTrackEvent = jest.fn() + const mockExpandStep = vi.fn() + const mockTrackEvent = vi.fn() const render = ({ robotName = ROBOT_NAME, @@ -75,55 +55,50 @@ describe('SetupRobotCalibration', () => { } beforeEach(() => { - when(mockUseTrackEvent).calledWith().mockReturnValue(mockTrackEvent) - when(mockSetupDeckCalibration).mockReturnValue( + when(vi.mocked(useTrackEvent)).calledWith().thenReturn(mockTrackEvent) + vi.mocked(SetupDeckCalibration).mockReturnValue(
Mock SetupDeckCalibration
) - when(mockSetupInstrumentCalibration).mockReturnValue( + vi.mocked(SetupInstrumentCalibration).mockReturnValue(
Mock SetupInstrumentCalibration
) - when(mockSetupTipLengthCalibration).mockReturnValue( + vi.mocked(SetupTipLengthCalibration).mockReturnValue(
Mock SetupTipLengthCalibration
) - when(mockUseDeckCalibrationData).calledWith(ROBOT_NAME).mockReturnValue({ + when(vi.mocked(useDeckCalibrationData)).calledWith(ROBOT_NAME).thenReturn({ deckCalibrationData: mockDeckCalData, isDeckCalibrated: true, }) - when(mockUseRunHasStarted).calledWith(RUN_ID).mockReturnValue(false) - when(mockUseIsFlex).calledWith(ROBOT_NAME).mockReturnValue(false) + when(vi.mocked(useRunHasStarted)).calledWith(RUN_ID).thenReturn(false) + when(vi.mocked(useIsFlex)).calledWith(ROBOT_NAME).thenReturn(false) }) afterEach(() => { - jest.resetAllMocks() - resetAllWhenMocks() + vi.resetAllMocks() }) it('renders deck, pipette, and tip length calibration components', () => { - const { getByText } = render()[0] - - getByText('Mock SetupDeckCalibration') - getByText('Mock SetupInstrumentCalibration') - getByText('Mock SetupTipLengthCalibration') + render()[0] + screen.getByText('Mock SetupDeckCalibration') + screen.getByText('Mock SetupInstrumentCalibration') + screen.getByText('Mock SetupTipLengthCalibration') }) it('renders only pipette calibration component for Flex', () => { - when(mockUseIsFlex).calledWith(ROBOT_NAME).mockReturnValue(true) - const { getByText, queryByText } = render()[0] - - expect(queryByText('Mock SetupDeckCalibration')).toBeNull() - getByText('Mock SetupInstrumentCalibration') - expect(queryByText('Mock SetupTipLengthCalibration')).toBeNull() + when(vi.mocked(useIsFlex)).calledWith(ROBOT_NAME).thenReturn(true) + render()[0] + expect(screen.queryByText('Mock SetupDeckCalibration')).toBeNull() + screen.getByText('Mock SetupInstrumentCalibration') + expect(screen.queryByText('Mock SetupTipLengthCalibration')).toBeNull() }) it('changes Proceed CTA copy based on next step', () => { - const { getByRole } = render({ nextStep: 'labware_setup_step' })[0] - - getByRole('button', { name: 'Proceed to labware' }) + render({ nextStep: 'labware_setup_step' })[0] + screen.getByRole('button', { name: 'Proceed to labware' }) }) it('calls the expandStep function and tracks the analytics event on click', () => { - const { getByRole } = render()[0] - - fireEvent.click(getByRole('button', { name: 'Proceed to modules' })) + render()[0] + fireEvent.click(screen.getByRole('button', { name: 'Proceed to modules' })) expect(mockExpandStep).toHaveBeenCalled() expect(mockTrackEvent).toHaveBeenCalledWith({ name: ANALYTICS_PROCEED_TO_MODULE_SETUP_STEP, @@ -132,19 +107,17 @@ describe('SetupRobotCalibration', () => { }) it('does not call the expandStep function on click if calibration is not complete', () => { - const { getByRole } = render({ calibrationStatus: { complete: false } })[0] - - const button = getByRole('button', { name: 'Proceed to modules' }) + render({ calibrationStatus: { complete: false } })[0] + const button = screen.getByRole('button', { name: 'Proceed to modules' }) expect(button).toBeDisabled() fireEvent.click(button) expect(mockExpandStep).not.toHaveBeenCalled() }) it('does not call the expandStep function on click if run has started', () => { - when(mockUseRunHasStarted).calledWith(RUN_ID).mockReturnValue(true) - const { getByRole } = render()[0] - - const button = getByRole('button', { name: 'Proceed to modules' }) + when(vi.mocked(useRunHasStarted)).calledWith(RUN_ID).thenReturn(true) + render()[0] + const button = screen.getByRole('button', { name: 'Proceed to modules' }) expect(button).toBeDisabled() fireEvent.click(button) expect(mockExpandStep).not.toHaveBeenCalled()