diff --git a/app/src/organisms/Devices/ProtocolRun/__tests__/ProtocolAnalysisErrorModal.test.tsx b/app/src/organisms/Devices/ProtocolRun/__tests__/ProtocolAnalysisErrorModal.test.tsx index 24e4e43adb4..e7d2be4c976 100644 --- a/app/src/organisms/Devices/ProtocolRun/__tests__/ProtocolAnalysisErrorModal.test.tsx +++ b/app/src/organisms/Devices/ProtocolRun/__tests__/ProtocolAnalysisErrorModal.test.tsx @@ -1,6 +1,8 @@ import * as React from 'react' -import { fireEvent } from '@testing-library/react' -import { renderWithProviders } from '@opentrons/components' +import { fireEvent, screen } from '@testing-library/react' +import { describe, it, beforeEach, expect, vi } from 'vitest' + +import { renderWithProviders } from '../../../../__testing-utils__' import { i18n } from '../../../../i18n' import { ProtocolAnalysisErrorModal } from '../ProtocolAnalysisErrorModal' @@ -19,7 +21,7 @@ describe('ProtocolAnalysisErrorModal', () => { props = { displayName: 'test_protocol', robotName: 'test_robot', - onClose: jest.fn(), + onClose: vi.fn(), errors: [ { id: 'error_id', @@ -31,13 +33,13 @@ describe('ProtocolAnalysisErrorModal', () => { } }) it('renders error modal', () => { - const { getByText, getByLabelText } = render(props) - getByText('protocol analysis error') - getByLabelText('close_analysis_error_modal') + render(props) + screen.getByText('protocol analysis error') + screen.getByLabelText('close_analysis_error_modal') }) it('calls onClose when close button clicked', () => { - const { getByLabelText } = render(props) - const btn = getByLabelText('close_analysis_error_modal') + render(props) + const btn = screen.getByLabelText('close_analysis_error_modal') fireEvent.click(btn) expect(props.onClose).toHaveBeenCalled() }) diff --git a/app/src/organisms/Devices/ProtocolRun/__tests__/ProtocolDropTipBanner.test.tsx b/app/src/organisms/Devices/ProtocolRun/__tests__/ProtocolDropTipBanner.test.tsx index ebc0bf5d38b..52312e9c3a8 100644 --- a/app/src/organisms/Devices/ProtocolRun/__tests__/ProtocolDropTipBanner.test.tsx +++ b/app/src/organisms/Devices/ProtocolRun/__tests__/ProtocolDropTipBanner.test.tsx @@ -1,8 +1,8 @@ import * as React from 'react' -import { fireEvent } from '@testing-library/react' - -import { renderWithProviders } from '@opentrons/components' +import { fireEvent, screen } from '@testing-library/react' +import { describe, it, beforeEach, vi, expect } from 'vitest' +import { renderWithProviders } from '../../../../__testing-utils__' import { ProtocolDropTipBanner } from '../ProtocolDropTipBanner' import { i18n } from '../../../../i18n' @@ -17,8 +17,8 @@ describe('Module Update Banner', () => { beforeEach(() => { props = { - onCloseClick: jest.fn(), - onLaunchWizardClick: jest.fn(), + onCloseClick: vi.fn(), + onLaunchWizardClick: vi.fn(), } }) @@ -30,16 +30,16 @@ describe('Module Update Banner', () => { }) it('launches the drop tip wizard when clicking on the appropriate banner text', () => { - const { getByText } = render(props) + render(props) expect(props.onLaunchWizardClick).not.toHaveBeenCalled() - fireEvent.click(getByText('Remove tips')) + fireEvent.click(screen.getByText('Remove tips')) expect(props.onLaunchWizardClick).toHaveBeenCalled() }) it('closes the banner when clicking the appropriate button', () => { - const { getByTestId } = render(props) + render(props) expect(props.onCloseClick).not.toHaveBeenCalled() - fireEvent.click(getByTestId('Banner_close-button')) + fireEvent.click(screen.getByTestId('Banner_close-button')) expect(props.onCloseClick).toHaveBeenCalled() }) }) diff --git a/app/src/organisms/Devices/ProtocolRun/__tests__/ProtocolRunModuleControls.test.tsx b/app/src/organisms/Devices/ProtocolRun/__tests__/ProtocolRunModuleControls.test.tsx index 28bcd5617ce..dd6e3b18209 100644 --- a/app/src/organisms/Devices/ProtocolRun/__tests__/ProtocolRunModuleControls.test.tsx +++ b/app/src/organisms/Devices/ProtocolRun/__tests__/ProtocolRunModuleControls.test.tsx @@ -1,7 +1,10 @@ import * as React from 'react' -import { resetAllWhenMocks, when } from 'jest-when' +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 { renderWithProviders } from '@opentrons/components' import { ModuleModel, ModuleType } from '@opentrons/shared-data' import { useInstrumentsQuery } from '@opentrons/react-api-client' import { ProtocolRunModuleControls } from '../ProtocolRunModuleControls' @@ -14,20 +17,11 @@ import { mockHeaterShaker, } from '../../../../redux/modules/__fixtures__' -jest.mock('@opentrons/react-api-client') -jest.mock('../../../ModuleCard') -jest.mock('../../hooks') - -const mockModuleCard = ModuleCard as jest.MockedFunction -const mockUseModuleRenderInfoForProtocolById = useModuleRenderInfoForProtocolById as jest.MockedFunction< - typeof useModuleRenderInfoForProtocolById -> -const mockUseInstrumentsQuery = useInstrumentsQuery as jest.MockedFunction< - typeof useInstrumentsQuery -> +vi.mock('@opentrons/react-api-client') +vi.mock('../../../ModuleCard') +vi.mock('../../hooks') const RUN_ID = 'test123' - const mockTempMod = { labwareOffset: { x: 3, y: 3, z: 3 }, moduleId: 'temperature_id', @@ -65,20 +59,21 @@ const render = ( describe('ProtocolRunModuleControls', () => { beforeEach(() => { - when(mockUseInstrumentsQuery).mockReturnValue({ - data: { data: [] }, - } as any) + when(vi.mocked(useInstrumentsQuery)) + .calledWith() + .thenReturn({ + data: { data: [] }, + } as any) }) afterEach(() => { - jest.resetAllMocks() - resetAllWhenMocks() + vi.resetAllMocks() }) it('renders a magnetic module card', () => { - when(mockUseModuleRenderInfoForProtocolById) + when(vi.mocked(useModuleRenderInfoForProtocolById)) .calledWith(RUN_ID) - .mockReturnValue({ + .thenReturn({ [mockMagMod.moduleId]: { moduleId: 'magModModuleId', x: '0', @@ -91,19 +86,19 @@ describe('ProtocolRunModuleControls', () => { attachedModuleMatch: mockMagneticModuleGen2, }, } as any) - when(mockModuleCard).mockReturnValue(
mock Magnetic Module Card
) - const { getByText } = render({ + when(vi.mocked(ModuleCard)).thenReturn(
mock Magnetic Module Card
) + render({ robotName: 'otie', runId: 'test123', }) - getByText('mock Magnetic Module Card') + screen.getByText('mock Magnetic Module Card') }) it('renders a temperature module card', () => { - when(mockUseModuleRenderInfoForProtocolById) + when(vi.mocked(useModuleRenderInfoForProtocolById)) .calledWith(RUN_ID) - .mockReturnValue({ + .thenReturn({ [mockTempMod.moduleId]: { moduleId: 'temperatureModuleId', x: '0', @@ -116,21 +111,21 @@ describe('ProtocolRunModuleControls', () => { attachedModuleMatch: mockTemperatureModuleGen2, }, } as any) - when(mockModuleCard).mockReturnValue( + when(vi.mocked(ModuleCard)).thenReturn(
mock Temperature Module Card
) - const { getByText } = render({ + render({ robotName: 'otie', runId: 'test123', }) - getByText('mock Temperature Module Card') + screen.getByText('mock Temperature Module Card') }) it('renders a thermocycler module card', () => { - when(mockUseModuleRenderInfoForProtocolById) + when(vi.mocked(useModuleRenderInfoForProtocolById)) .calledWith(RUN_ID) - .mockReturnValue({ + .thenReturn({ [mockTCModule.moduleId]: { moduleId: mockTCModule.moduleId, x: MOCK_TC_COORDS[0], @@ -144,22 +139,22 @@ describe('ProtocolRunModuleControls', () => { }, } as any) - when(mockModuleCard).mockReturnValue( + when(vi.mocked(ModuleCard)).thenReturn(
mock Thermocycler Module Card
) - const { getByText } = render({ + render({ robotName: 'otie', runId: 'test123', }) - getByText('mock Thermocycler Module Card') + screen.getByText('mock Thermocycler Module Card') }) it('renders a heater-shaker module card', () => { - when(mockUseModuleRenderInfoForProtocolById) + when(vi.mocked(useModuleRenderInfoForProtocolById)) .calledWith(RUN_ID) - .mockReturnValue({ + .thenReturn({ [mockHeaterShakerDef.moduleId]: { moduleId: 'heaterShakerModuleId', x: '0', @@ -172,22 +167,22 @@ describe('ProtocolRunModuleControls', () => { attachedModuleMatch: mockHeaterShaker, }, } as any) - when(mockModuleCard).mockReturnValue( + when(vi.mocked(ModuleCard)).thenReturn(
mock Heater-Shaker Module Card
) - const { getByText } = render({ + render({ robotName: 'otie', runId: 'test123', }) - getByText('mock Heater-Shaker Module Card') + screen.getByText('mock Heater-Shaker Module Card') }) it('renders correct text when module is not attached but required for protocol', () => { - when(mockUseModuleRenderInfoForProtocolById) + when(vi.mocked(useModuleRenderInfoForProtocolById)) .calledWith(RUN_ID) - .mockReturnValue({ + .thenReturn({ [mockHeaterShakerDef.moduleId]: { moduleId: 'heaterShakerModuleId', x: '0', @@ -201,11 +196,11 @@ describe('ProtocolRunModuleControls', () => { }, } as any) - const { getByText } = render({ + render({ robotName: 'otie', runId: 'test123', }) - getByText('Connect modules to see controls') + screen.getByText('Connect modules to see controls') }) }) diff --git a/app/src/organisms/Devices/ProtocolRun/__tests__/RunFailedModal.test.tsx b/app/src/organisms/Devices/ProtocolRun/__tests__/RunFailedModal.test.tsx index 9264c54eba2..c94191a2b25 100644 --- a/app/src/organisms/Devices/ProtocolRun/__tests__/RunFailedModal.test.tsx +++ b/app/src/organisms/Devices/ProtocolRun/__tests__/RunFailedModal.test.tsx @@ -1,7 +1,7 @@ import * as React from 'react' +import { describe, it, beforeEach, vi, expect, afterEach } from 'vitest' -import { renderWithProviders } from '@opentrons/components' - +import { renderWithProviders } from '../../../../__testing-utils__' import { i18n } from '../../../../i18n' import { useDownloadRunLog } from '../../hooks' import { RunFailedModal } from '../RunFailedModal' @@ -9,11 +9,7 @@ import { RunFailedModal } from '../RunFailedModal' import type { RunError } from '@opentrons/api-client' import { fireEvent, screen } from '@testing-library/react' -jest.mock('../../hooks') - -const mockUseDownloadRunLog = useDownloadRunLog as jest.MockedFunction< - typeof useDownloadRunLog -> +vi.mock('../../hooks') const RUN_ID = '1' const ROBOT_NAME = 'mockRobotName' @@ -40,17 +36,17 @@ describe('RunFailedModal - DesktopApp', () => { props = { robotName: ROBOT_NAME, runId: RUN_ID, - setShowRunFailedModal: jest.fn(), + setShowRunFailedModal: vi.fn(), highestPriorityError: mockError, } - mockUseDownloadRunLog.mockReturnValue({ - downloadRunLog: jest.fn(), + vi.mocked(useDownloadRunLog).mockReturnValue({ + downloadRunLog: vi.fn(), isRunLogLoading: false, }) }) afterEach(() => { - jest.clearAllMocks() + vi.clearAllMocks() }) it('should render text, link and button', () => { @@ -80,6 +76,6 @@ describe('RunFailedModal - DesktopApp', () => { it('should call a mock function when clicking download run log button', () => { render(props) fireEvent.click(screen.getByText('Download Run Log')) - expect(mockUseDownloadRunLog).toHaveBeenCalled() + expect(vi.mocked(useDownloadRunLog)).toHaveBeenCalled() }) }) diff --git a/app/src/organisms/Devices/ProtocolRun/__tests__/SetupCalibrationItem.test.tsx b/app/src/organisms/Devices/ProtocolRun/__tests__/SetupCalibrationItem.test.tsx index 338f03ff82e..0cd4c009bb5 100644 --- a/app/src/organisms/Devices/ProtocolRun/__tests__/SetupCalibrationItem.test.tsx +++ b/app/src/organisms/Devices/ProtocolRun/__tests__/SetupCalibrationItem.test.tsx @@ -1,22 +1,16 @@ import * as React from 'react' import { screen } from '@testing-library/react' -import { renderWithProviders } from '@opentrons/components' +import { when } from 'vitest-when' +import { describe, it, beforeEach, vi, afterEach } from 'vitest' +import { renderWithProviders } from '../../../../__testing-utils__' import { i18n } from '../../../../i18n' import { useRunHasStarted } from '../../hooks' import { formatTimestamp } from '../../utils' import { SetupCalibrationItem } from '../SetupCalibrationItem' -import { when, resetAllWhenMocks } from 'jest-when' -jest.mock('../../hooks') -jest.mock('../../utils') - -const mockFormatTimestamp = formatTimestamp as jest.MockedFunction< - typeof formatTimestamp -> -const mockUseRunHasStarted = useRunHasStarted as jest.MockedFunction< - typeof useRunHasStarted -> +vi.mock('../../hooks') +vi.mock('../../utils') const RUN_ID = '1' @@ -37,11 +31,11 @@ describe('SetupCalibrationItem', () => { } beforeEach(() => { - when(mockUseRunHasStarted).calledWith(RUN_ID).mockReturnValue(false) + when(vi.mocked(useRunHasStarted)).calledWith(RUN_ID).thenReturn(false) }) afterEach(() => { - resetAllWhenMocks() + vi.resetAllMocks() }) it('renders all nodes with prop contents', () => { @@ -51,9 +45,9 @@ describe('SetupCalibrationItem', () => { screen.getByRole('button', { name: 'stub button' }) }) it('renders calibrated date if there is no subtext', () => { - when(mockFormatTimestamp) + when(vi.mocked(formatTimestamp)) .calledWith('Thursday, September 9, 2021') - .mockReturnValue('09/09/2021 00:00:00') + .thenReturn('09/09/2021 00:00:00') render({ calibratedDate: 'Thursday, September 9, 2021', }) @@ -64,7 +58,7 @@ describe('SetupCalibrationItem', () => { screen.getByText('Not calibrated yet') }) it('renders calibration data not available if run has started', () => { - when(mockUseRunHasStarted).calledWith(RUN_ID).mockReturnValue(true) + when(vi.mocked(useRunHasStarted)).calledWith(RUN_ID).thenReturn(true) render() screen.getByText('Calibration data not available once run has started') })