diff --git a/app/src/molecules/PythonLabwareOffsetSnippet/__tests__/createSnippet.test.ts b/app/src/molecules/PythonLabwareOffsetSnippet/__tests__/createSnippet.test.ts index b0341bc48bc..bdc1a779452 100644 --- a/app/src/molecules/PythonLabwareOffsetSnippet/__tests__/createSnippet.test.ts +++ b/app/src/molecules/PythonLabwareOffsetSnippet/__tests__/createSnippet.test.ts @@ -1,6 +1,6 @@ import { describe, it, expect } from 'vitest' import '@testing-library/jest-dom/vitest' -import { transfer_settings } from '@opentrons/shared-data/protocol/fixtures/6' +import { transfer_settings } from '@opentrons/shared-data' import { ModuleModel, CompletedProtocolAnalysis } from '@opentrons/shared-data' import { createSnippet } from '../createSnippet' diff --git a/app/src/organisms/AddCustomLabwareSlideout/__tests__/AddCustomLabwareSlideout.test.tsx b/app/src/organisms/AddCustomLabwareSlideout/__tests__/AddCustomLabwareSlideout.test.tsx index 7bf3f23675f..f3882525ef8 100644 --- a/app/src/organisms/AddCustomLabwareSlideout/__tests__/AddCustomLabwareSlideout.test.tsx +++ b/app/src/organisms/AddCustomLabwareSlideout/__tests__/AddCustomLabwareSlideout.test.tsx @@ -1,23 +1,20 @@ import * as React from 'react' import { MemoryRouter } from 'react-router-dom' -import { fireEvent } from '@testing-library/react' -import { renderWithProviders } from '@opentrons/components' +import { describe, it, expect, vi, beforeEach } from 'vitest' +import { fireEvent, screen } from '@testing-library/react' import { i18n } from '../../../i18n' import { useTrackEvent, ANALYTICS_ADD_CUSTOM_LABWARE, } from '../../../redux/analytics' +import { renderWithProviders } from '../../../__testing-utils__' import { AddCustomLabwareSlideout } from '..' -jest.mock('../../../redux/custom-labware') -jest.mock('../../../pages/Labware/helpers/getAllDefs') -jest.mock('../../../redux/analytics') +vi.mock('../../../redux/custom-labware') +vi.mock('../../../pages/Labware/helpers/getAllDefs') +vi.mock('../../../redux/analytics') -const mockUseTrackEvent = useTrackEvent as jest.MockedFunction< - typeof useTrackEvent -> - -let mockTrackEvent: jest.Mock +let mockTrackEvent: any const render = ( props: React.ComponentProps @@ -35,18 +32,18 @@ const render = ( describe('AddCustomLabwareSlideout', () => { const props: React.ComponentProps = { isExpanded: true, - onCloseClick: jest.fn(() => null), + onCloseClick: vi.fn(() => null), } beforeEach(() => { - mockTrackEvent = jest.fn() - mockUseTrackEvent.mockReturnValue(mockTrackEvent) + mockTrackEvent = vi.fn() + vi.mocked(useTrackEvent).mockReturnValue(mockTrackEvent) }) it('renders correct title and labware cards and clicking on button triggers analytics event', () => { - const [{ getByText, getByRole }] = render(props) - getByText('Import a Custom Labware Definition') - getByText('Or choose a file from your computer to upload.') - const btn = getByRole('button', { name: 'Upload' }) + render(props) + screen.getByText('Import a Custom Labware Definition') + screen.getByText('Or choose a file from your computer to upload.') + const btn = screen.getByRole('button', { name: 'Upload' }) fireEvent.click(btn) expect(mockTrackEvent).toHaveBeenCalledWith({ name: ANALYTICS_ADD_CUSTOM_LABWARE, @@ -55,7 +52,7 @@ describe('AddCustomLabwareSlideout', () => { }) it('renders drag and drop section', () => { - const [{ getByRole }] = render(props) - getByRole('button', { name: 'browse' }) + render(props) + screen.getByRole('button', { name: 'browse' }) }) }) diff --git a/app/src/organisms/AdvancedSettings/__tests__/AdditionalCustomLabwareSourceFolder.test.tsx b/app/src/organisms/AdvancedSettings/__tests__/AdditionalCustomLabwareSourceFolder.test.tsx index e57b10f5ac5..82583c017cf 100644 --- a/app/src/organisms/AdvancedSettings/__tests__/AdditionalCustomLabwareSourceFolder.test.tsx +++ b/app/src/organisms/AdvancedSettings/__tests__/AdditionalCustomLabwareSourceFolder.test.tsx @@ -1,6 +1,6 @@ import * as React from 'react' +import { describe, it, expect, vi, beforeEach } from 'vitest' import { fireEvent, screen } from '@testing-library/react' -import { renderWithProviders } from '@opentrons/components' import { i18n } from '../../../i18n' import { getCustomLabwareDirectory } from '../../../redux/custom-labware' import { @@ -9,9 +9,10 @@ import { } from '../../../redux/analytics' import { AdditionalCustomLabwareSourceFolder } from '../AdditionalCustomLabwareSourceFolder' +import { renderWithProviders } from '../../../__testing-utils__' -jest.mock('../../../redux/custom-labware') -jest.mock('../../../redux/analytics') +vi.mock('../../../redux/custom-labware') +vi.mock('../../../redux/analytics') const render = () => { return renderWithProviders(, { @@ -19,23 +20,18 @@ const render = () => { }) } -const mockTrackEvent = jest.fn() - -const mockGetCustomLabwarePath = getCustomLabwareDirectory as jest.MockedFunction< - typeof getCustomLabwareDirectory -> -const mockUseTrackEvent = useTrackEvent as jest.MockedFunction< - typeof useTrackEvent -> +const mockTrackEvent = vi.fn() describe('AdditionalCustomLabwareSourceFolder', () => { beforeEach(() => { - mockUseTrackEvent.mockReturnValue(mockTrackEvent) - mockGetCustomLabwarePath.mockReturnValue('') + vi.mocked(useTrackEvent).mockReturnValue(mockTrackEvent) + vi.mocked(getCustomLabwareDirectory).mockReturnValue('') }) it('renders the custom labware section with source folder selected', () => { - mockGetCustomLabwarePath.mockReturnValue('/mock/custom-labware-path') + vi.mocked(getCustomLabwareDirectory).mockReturnValue( + '/mock/custom-labware-path' + ) render() screen.getByText( 'If you want to specify a folder to manually manage Custom Labware files, you can add the directory here.' diff --git a/app/src/organisms/AdvancedSettings/__tests__/ClearUnavailableRobots.test.tsx b/app/src/organisms/AdvancedSettings/__tests__/ClearUnavailableRobots.test.tsx index 5d714d74834..ef7a85b3ba1 100644 --- a/app/src/organisms/AdvancedSettings/__tests__/ClearUnavailableRobots.test.tsx +++ b/app/src/organisms/AdvancedSettings/__tests__/ClearUnavailableRobots.test.tsx @@ -1,10 +1,7 @@ import * as React from 'react' -import { screen, fireEvent } from '@testing-library/react' - -import { - renderWithProviders, - useConditionalConfirm, -} from '@opentrons/components' +import { screen, fireEvent, waitFor } from '@testing-library/react' +import { describe, it, expect, vi, beforeEach } from 'vitest' +import { useConditionalConfirm } from '@opentrons/components' import { i18n } from '../../../i18n' import { getReachableRobots, @@ -14,20 +11,26 @@ import { mockReachableRobot, mockUnreachableRobot, } from '../../../redux/discovery/__fixtures__' +import { renderWithProviders } from '../../../__testing-utils__' import { ClearUnavailableRobots } from '../ClearUnavailableRobots' +import type * as OpentronsComponents from '@opentrons/components' + +const mockConfirm = vi.fn() +const mockCancel = vi.fn() -jest.mock('@opentrons/components/src/hooks') -jest.mock('../../../redux/discovery') +vi.mock('@opentrons/components', async importOriginal => { + const actual = await importOriginal() + return { + ...actual, + useConditionalConfirm: vi.fn(() => ({ + confirm: mockConfirm, + showConfirmation: true, + cancel: mockCancel, + })), + } +}) -const mockGetUnreachableRobots = getUnreachableRobots as jest.MockedFunction< - typeof getUnreachableRobots -> -const mockGetReachableRobots = getReachableRobots as jest.MockedFunction< - typeof getReachableRobots -> -const mockUseConditionalConfirm = useConditionalConfirm as jest.MockedFunction< - typeof useConditionalConfirm -> +vi.mock('../../../redux/discovery') const render = () => { return renderWithProviders(, { @@ -35,22 +38,17 @@ const render = () => { }) } -const mockConfirm = jest.fn() -const mockCancel = jest.fn() - describe('ClearUnavailableRobots', () => { beforeEach(() => { - mockGetUnreachableRobots.mockReturnValue([mockUnreachableRobot]) - mockGetReachableRobots.mockReturnValue([mockReachableRobot]) - mockUseConditionalConfirm.mockReturnValue({ + vi.mocked(getUnreachableRobots).mockReturnValue([mockUnreachableRobot]) + vi.mocked(getReachableRobots).mockReturnValue([mockReachableRobot]) + vi.mocked(useConditionalConfirm).mockReturnValue({ confirm: mockConfirm, showConfirmation: true, cancel: mockCancel, }) }) - afterEach(() => {}) - it('should render text and button', () => { render() screen.getByText('Clear Unavailable Robots') @@ -69,7 +67,8 @@ describe('ClearUnavailableRobots', () => { name: 'Clear unavailable robots list', }) ) - screen.getByText('Clear unavailable robots?') + + screen.getByText('Clear unavailable robots') screen.getByText( 'Clearing the list of unavailable robots on the Devices page cannot be undone.' ) diff --git a/app/src/organisms/AdvancedSettings/__tests__/EnableDevTools.test.tsx b/app/src/organisms/AdvancedSettings/__tests__/EnableDevTools.test.tsx index 9b70ec18271..81707fadcc7 100644 --- a/app/src/organisms/AdvancedSettings/__tests__/EnableDevTools.test.tsx +++ b/app/src/organisms/AdvancedSettings/__tests__/EnableDevTools.test.tsx @@ -1,20 +1,13 @@ import * as React from 'react' import { screen, fireEvent } from '@testing-library/react' +import { describe, it, expect, vi, beforeEach } from 'vitest' -import { renderWithProviders } from '@opentrons/components' import { i18n } from '../../../i18n' - +import { renderWithProviders } from '../../../__testing-utils__' import { getDevtoolsEnabled, toggleDevtools } from '../../../redux/config' import { EnableDevTools } from '../EnableDevTools' -jest.mock('../../../redux/config') - -const mockGetDevtoolsEnabled = getDevtoolsEnabled as jest.MockedFunction< - typeof getDevtoolsEnabled -> -const mockToggleDevtools = toggleDevtools as jest.MockedFunction< - typeof toggleDevtools -> +vi.mock('../../../redux/config') const render = () => { return renderWithProviders(, { @@ -24,11 +17,7 @@ const render = () => { describe('EnableDevTools', () => { beforeEach(() => { - mockGetDevtoolsEnabled.mockReturnValue(true) - }) - - afterEach(() => { - jest.clearAllMocks() + vi.mocked(getDevtoolsEnabled).mockReturnValue(true) }) it('should render text and toggle button', () => { @@ -46,6 +35,6 @@ describe('EnableDevTools', () => { name: 'enable_dev_tools', }) fireEvent.click(toggleButton) - expect(mockToggleDevtools).toHaveBeenCalled() + expect(vi.mocked(toggleDevtools)).toHaveBeenCalled() }) }) diff --git a/app/src/organisms/AdvancedSettings/__tests__/OT2AdvancedSettings.test.tsx b/app/src/organisms/AdvancedSettings/__tests__/OT2AdvancedSettings.test.tsx index 3e85270e9ff..70d8d67699b 100644 --- a/app/src/organisms/AdvancedSettings/__tests__/OT2AdvancedSettings.test.tsx +++ b/app/src/organisms/AdvancedSettings/__tests__/OT2AdvancedSettings.test.tsx @@ -1,7 +1,7 @@ import * as React from 'react' import { screen, fireEvent } from '@testing-library/react' +import { describe, it, expect, vi, beforeEach } from 'vitest' -import { renderWithProviders } from '@opentrons/components' import { i18n } from '../../../i18n' import { @@ -9,22 +9,11 @@ import { setUseTrashSurfaceForTipCal, } from '../../../redux/calibration' import { getUseTrashSurfaceForTipCal } from '../../../redux/config' +import { renderWithProviders } from '../../../__testing-utils__' import { OT2AdvancedSettings } from '../OT2AdvancedSettings' -jest.mock('../../../redux/calibration') -jest.mock('../../../redux/config') - -const mockResetUseTrashSurfaceForTipCal = resetUseTrashSurfaceForTipCal as jest.MockedFunction< - typeof resetUseTrashSurfaceForTipCal -> - -const mockSetUseTrashSurfaceForTipCal = setUseTrashSurfaceForTipCal as jest.MockedFunction< - typeof setUseTrashSurfaceForTipCal -> - -const mockGetUseTrashSurfaceForTipCal = getUseTrashSurfaceForTipCal as jest.MockedFunction< - typeof getUseTrashSurfaceForTipCal -> +vi.mock('../../../redux/calibration') +vi.mock('../../../redux/config') const render = () => { return renderWithProviders(, { @@ -34,11 +23,7 @@ const render = () => { describe('OT2AdvancedSettings', () => { beforeEach(() => { - mockGetUseTrashSurfaceForTipCal.mockReturnValue(true) - }) - - afterEach(() => { - jest.clearAllMocks() + vi.mocked(getUseTrashSurfaceForTipCal).mockReturnValue(true) }) it('should render text and toggle button', () => { @@ -60,17 +45,17 @@ describe('OT2AdvancedSettings', () => { name: 'Always use calibration block to calibrate', }) fireEvent.click(radioButton) - expect(mockSetUseTrashSurfaceForTipCal).toHaveBeenCalledWith(false) + expect(vi.mocked(setUseTrashSurfaceForTipCal)).toHaveBeenCalledWith(false) }) it('should call mock setUseTrashSurfaceForTipCal with true when selecting always trash', () => { - mockGetUseTrashSurfaceForTipCal.mockReturnValue(false) + vi.mocked(getUseTrashSurfaceForTipCal).mockReturnValue(false) render() const radioButton = screen.getByRole('radio', { name: 'Always use trash bin to calibrate', }) fireEvent.click(radioButton) - expect(mockSetUseTrashSurfaceForTipCal).toHaveBeenCalledWith(true) + expect(vi.mocked(setUseTrashSurfaceForTipCal)).toHaveBeenCalledWith(true) }) it('should call mock resetUseTrashSurfaceForTipCal when selecting always prompt', () => { @@ -79,6 +64,6 @@ describe('OT2AdvancedSettings', () => { name: 'Always show the prompt to choose calibration block or trash bin', }) fireEvent.click(radioButton) - expect(mockResetUseTrashSurfaceForTipCal).toHaveBeenCalled() + expect(vi.mocked(resetUseTrashSurfaceForTipCal)).toHaveBeenCalled() }) }) diff --git a/app/src/organisms/AdvancedSettings/__tests__/OverridePathToPython.test.tsx b/app/src/organisms/AdvancedSettings/__tests__/OverridePathToPython.test.tsx index 23363633297..6a94076c68c 100644 --- a/app/src/organisms/AdvancedSettings/__tests__/OverridePathToPython.test.tsx +++ b/app/src/organisms/AdvancedSettings/__tests__/OverridePathToPython.test.tsx @@ -1,7 +1,6 @@ import * as React from 'react' import { fireEvent, screen } from '@testing-library/react' - -import { renderWithProviders } from '@opentrons/components' +import { describe, it, expect, vi, beforeEach } from 'vitest' import { i18n } from '../../../i18n' import { getPathToPythonOverride } from '../../../redux/config' @@ -9,13 +8,14 @@ import { useTrackEvent, ANALYTICS_CHANGE_PATH_TO_PYTHON_DIRECTORY, } from '../../../redux/analytics' +import { renderWithProviders } from '../../../__testing-utils__' import { openPythonInterpreterDirectory } from '../../../redux/protocol-analysis' import { OverridePathToPython } from '../OverridePathToPython' -jest.mock('../../../redux/config') -jest.mock('../../../redux/analytics') -jest.mock('../../../redux/protocol-analysis') +vi.mock('../../../redux/config') +vi.mock('../../../redux/analytics') +vi.mock('../../../redux/protocol-analysis') const render = () => { return ( @@ -26,24 +26,14 @@ const render = () => { ) } -const mockUseTrackEvent = useTrackEvent as jest.MockedFunction< - typeof useTrackEvent -> -const mockGetPathToPythonOverride = getPathToPythonOverride as jest.MockedFunction< - typeof getPathToPythonOverride -> -const mockOpenPythonInterpreterDirectory = openPythonInterpreterDirectory as jest.MockedFunction< - typeof openPythonInterpreterDirectory -> - -const mockTrackEvent = jest.fn() +const mockTrackEvent = vi.fn() describe('OverridePathToPython', () => { beforeEach(() => { - mockUseTrackEvent.mockReturnValue(mockTrackEvent) + vi.mocked(useTrackEvent).mockReturnValue(mockTrackEvent) }) it('renders the path to python override text and button with no default path', () => { - mockGetPathToPythonOverride.mockReturnValue(null) + vi.mocked(getPathToPythonOverride).mockReturnValue(null) render() screen.getByText('Override Path to Python') screen.getByText( @@ -60,7 +50,7 @@ describe('OverridePathToPython', () => { }) it('renders the path to python override text and button with a selected path', () => { - mockGetPathToPythonOverride.mockReturnValue('otherPath') + vi.mocked(getPathToPythonOverride).mockReturnValue('otherPath') render() screen.getByText('Override Path to Python') screen.getByText( @@ -70,8 +60,8 @@ describe('OverridePathToPython', () => { const specifiedPath = screen.getByText('otherPath') const button = screen.getByRole('button', { name: 'Reset to default' }) fireEvent.click(button) - expect(mockGetPathToPythonOverride).toHaveBeenCalled() + expect(vi.mocked(getPathToPythonOverride)).toHaveBeenCalled() fireEvent.click(specifiedPath) - expect(mockOpenPythonInterpreterDirectory).toHaveBeenCalled() + expect(vi.mocked(openPythonInterpreterDirectory)).toHaveBeenCalled() }) }) diff --git a/app/src/organisms/AdvancedSettings/__tests__/PreventRobotCaching.test.tsx b/app/src/organisms/AdvancedSettings/__tests__/PreventRobotCaching.test.tsx index 42a4d49d861..f088efd0f52 100644 --- a/app/src/organisms/AdvancedSettings/__tests__/PreventRobotCaching.test.tsx +++ b/app/src/organisms/AdvancedSettings/__tests__/PreventRobotCaching.test.tsx @@ -1,8 +1,9 @@ import * as React from 'react' -import { when, resetAllWhenMocks } from 'jest-when' +import { when } from 'vitest-when' +import { describe, it, expect, vi, beforeEach } from 'vitest' import { screen, fireEvent } from '@testing-library/react' -import { renderWithProviders } from '@opentrons/components' +import { renderWithProviders } from '../../../__testing-utils__' import { i18n } from '../../../i18n' import { getConfig, toggleConfigValue } from '../../../redux/config' @@ -10,12 +11,7 @@ import { PreventRobotCaching } from '../PreventRobotCaching' import type { State } from '../../../redux/types' -jest.mock('../../../redux/config') - -const mockGetConfig = getConfig as jest.MockedFunction -const mockToggleConfigValue = toggleConfigValue as jest.MockedFunction< - typeof toggleConfigValue -> +vi.mock('../../../redux/config') const MOCK_STATE: State = { config: { @@ -33,14 +29,7 @@ const render = () => { describe('PreventRobotCaching', () => { beforeEach(() => { - when(mockGetConfig) - .calledWith(MOCK_STATE) - .mockReturnValue(MOCK_STATE.config) - }) - - afterEach(() => { - jest.clearAllMocks() - resetAllWhenMocks() + when(getConfig).calledWith(MOCK_STATE).thenReturn(MOCK_STATE.config) }) it('should render text and toggle button', () => { @@ -58,6 +47,8 @@ describe('PreventRobotCaching', () => { name: 'display_unavailable_robots', }) fireEvent.click(toggleButton) - expect(mockToggleConfigValue).toHaveBeenCalledWith('discovery.disableCache') + expect(vi.mocked(toggleConfigValue)).toHaveBeenCalledWith( + 'discovery.disableCache' + ) }) }) diff --git a/app/src/organisms/AdvancedSettings/__tests__/ShowHeaterShakerAttachmentModal.test.tsx b/app/src/organisms/AdvancedSettings/__tests__/ShowHeaterShakerAttachmentModal.test.tsx index 1daf08671f9..3d64290093e 100644 --- a/app/src/organisms/AdvancedSettings/__tests__/ShowHeaterShakerAttachmentModal.test.tsx +++ b/app/src/organisms/AdvancedSettings/__tests__/ShowHeaterShakerAttachmentModal.test.tsx @@ -1,23 +1,15 @@ import * as React from 'react' import { fireEvent, screen } from '@testing-library/react' - -import { renderWithProviders } from '@opentrons/components' - +import { describe, it, expect, vi, beforeEach } from 'vitest' import { i18n } from '../../../i18n' import { getIsHeaterShakerAttached, updateConfigValue, } from '../../../redux/config' +import { renderWithProviders } from '../../../__testing-utils__' import { ShowHeaterShakerAttachmentModal } from '../ShowHeaterShakerAttachmentModal' -jest.mock('../../../redux/config') - -const mockGetIsHeaterShakerAttached = getIsHeaterShakerAttached as jest.MockedFunction< - typeof getIsHeaterShakerAttached -> -const mockUpdateConfigValue = updateConfigValue as jest.MockedFunction< - typeof updateConfigValue -> +vi.mock('../../../redux/config') const render = () => { return renderWithProviders(, { @@ -27,7 +19,7 @@ const render = () => { describe('ShowHeaterShakerAttachmentModal', () => { beforeEach(() => { - mockGetIsHeaterShakerAttached.mockReturnValue(true) + vi.mocked(getIsHeaterShakerAttached).mockReturnValue(true) }) it('renders the toggle button on when showing heater shaker modal as false', () => { @@ -43,7 +35,7 @@ describe('ShowHeaterShakerAttachmentModal', () => { }) it('renders the toggle button on when showing heater shaker modal as true', () => { - mockGetIsHeaterShakerAttached.mockReturnValue(false) + vi.mocked(getIsHeaterShakerAttached).mockReturnValue(false) render() const toggleButton = screen.getByRole('switch', { name: 'show_heater_shaker_modal', @@ -57,7 +49,7 @@ describe('ShowHeaterShakerAttachmentModal', () => { name: 'show_heater_shaker_modal', }) fireEvent.click(toggleButton) - expect(mockUpdateConfigValue).toHaveBeenCalledWith( + expect(vi.mocked(updateConfigValue)).toHaveBeenCalledWith( 'modules.heaterShaker.isAttached', false ) diff --git a/app/src/organisms/AdvancedSettings/__tests__/ShowLabwareOffsetSnippets.test.tsx b/app/src/organisms/AdvancedSettings/__tests__/ShowLabwareOffsetSnippets.test.tsx index ecce36d0631..1d25cb58052 100644 --- a/app/src/organisms/AdvancedSettings/__tests__/ShowLabwareOffsetSnippets.test.tsx +++ b/app/src/organisms/AdvancedSettings/__tests__/ShowLabwareOffsetSnippets.test.tsx @@ -1,22 +1,15 @@ import * as React from 'react' import { fireEvent, screen } from '@testing-library/react' - +import { describe, it, expect, vi, beforeEach } from 'vitest' import { i18n } from '../../../i18n' -import { renderWithProviders } from '@opentrons/components' import { getIsLabwareOffsetCodeSnippetsOn, updateConfigValue, } from '../../../redux/config' +import { renderWithProviders } from '../../../__testing-utils__' import { ShowLabwareOffsetSnippets } from '../ShowLabwareOffsetSnippets' -jest.mock('../../../redux/config') - -const mockGetIsLabwareOffsetCodeSnippetsOn = getIsLabwareOffsetCodeSnippetsOn as jest.MockedFunction< - typeof getIsLabwareOffsetCodeSnippetsOn -> -const mockUpdateConfigValue = updateConfigValue as jest.MockedFunction< - typeof updateConfigValue -> +vi.mock('../../../redux/config') const render = () => { return ( @@ -29,7 +22,7 @@ const render = () => { describe('ShowLabwareOffsetSnippets', () => { beforeEach(() => { - mockGetIsLabwareOffsetCodeSnippetsOn.mockReturnValue(true) + vi.mocked(getIsLabwareOffsetCodeSnippetsOn).mockReturnValue(true) }) it('renders the display show link to get labware offset data section', () => { render() @@ -46,7 +39,7 @@ describe('ShowLabwareOffsetSnippets', () => { name: 'show_link_to_get_labware_offset_data', }) fireEvent.click(toggleButton) - expect(mockUpdateConfigValue).toHaveBeenCalledWith( + expect(vi.mocked(updateConfigValue)).toHaveBeenCalledWith( 'labware.showLabwareOffsetCodeSnippets', false ) diff --git a/app/src/organisms/AdvancedSettings/__tests__/U2EInformation.test.tsx b/app/src/organisms/AdvancedSettings/__tests__/U2EInformation.test.tsx index 7cb79649ee7..01b5a80305d 100644 --- a/app/src/organisms/AdvancedSettings/__tests__/U2EInformation.test.tsx +++ b/app/src/organisms/AdvancedSettings/__tests__/U2EInformation.test.tsx @@ -1,7 +1,6 @@ import * as React from 'react' import { screen } from '@testing-library/react' -import { renderWithProviders } from '@opentrons/components' - +import { describe, it, expect, vi, beforeEach } from 'vitest' import { i18n } from '../../../i18n' import { getU2EAdapterDevice, @@ -11,17 +10,11 @@ import { UP_TO_DATE, } from '../../../redux/system-info' import * as Fixtures from '../../../redux/system-info/__fixtures__' +import { renderWithProviders } from '../../../__testing-utils__' import { U2EInformation } from '../U2EInformation' -jest.mock('../../../redux/system-info') - -const mockGetU2EAdapterDevice = getU2EAdapterDevice as jest.MockedFunction< - typeof getU2EAdapterDevice -> -const mockGetU2EWindowsDriverStatus = getU2EWindowsDriverStatus as jest.MockedFunction< - typeof getU2EWindowsDriverStatus -> +vi.mock('../../../redux/system-info') const render = () => { return renderWithProviders(, { @@ -31,8 +24,10 @@ const render = () => { describe('U2EInformation', () => { beforeEach(() => { - mockGetU2EAdapterDevice.mockReturnValue(Fixtures.mockWindowsRealtekDevice) - mockGetU2EWindowsDriverStatus.mockReturnValue(OUTDATED) + vi.mocked(getU2EAdapterDevice).mockReturnValue( + Fixtures.mockWindowsRealtekDevice + ) + vi.mocked(getU2EWindowsDriverStatus).mockReturnValue(OUTDATED) }) it('render the usb-to-ethernet adapter information', () => { @@ -47,10 +42,10 @@ describe('U2EInformation', () => { }) it('renders the test data of the usb-to-ethernet adapter information with mac', () => { - mockGetU2EAdapterDevice.mockReturnValue({ + vi.mocked(getU2EAdapterDevice).mockReturnValue({ ...Fixtures.mockRealtekDevice, }) - mockGetU2EWindowsDriverStatus.mockReturnValue(NOT_APPLICABLE) + vi.mocked(getU2EWindowsDriverStatus).mockReturnValue(NOT_APPLICABLE) render() screen.getByText('USB 10/100 LAN') screen.getByText('Realtek') @@ -64,7 +59,7 @@ describe('U2EInformation', () => { }) it('should render text and driver information', () => { - mockGetU2EWindowsDriverStatus.mockReturnValue(UP_TO_DATE) + vi.mocked(getU2EWindowsDriverStatus).mockReturnValue(UP_TO_DATE) render() screen.getByText('Realtek USB FE Family Controller') screen.getByText('Realtek') @@ -78,7 +73,7 @@ describe('U2EInformation', () => { }) it('renders the not connected message and not display item titles when USB-to-Ethernet is not connected', () => { - mockGetU2EAdapterDevice.mockReturnValue(null) + vi.mocked(getU2EAdapterDevice).mockReturnValue(null) render() expect(screen.queryByText('Description')).not.toBeInTheDocument() expect(screen.queryByText('Manufacturer')).not.toBeInTheDocument() diff --git a/app/src/organisms/AdvancedSettings/__tests__/UpdatedChannel.test.tsx b/app/src/organisms/AdvancedSettings/__tests__/UpdatedChannel.test.tsx index 84ee9da2a8e..666b1088283 100644 --- a/app/src/organisms/AdvancedSettings/__tests__/UpdatedChannel.test.tsx +++ b/app/src/organisms/AdvancedSettings/__tests__/UpdatedChannel.test.tsx @@ -1,7 +1,6 @@ import * as React from 'react' import { screen } from '@testing-library/react' -import { renderWithProviders } from '@opentrons/components' - +import { describe, it, vi, beforeEach } from 'vitest' import { i18n } from '../../../i18n' import { getUpdateChannelOptions, @@ -9,26 +8,17 @@ import { // updateConfigValue, } from '../../../redux/config' import { UpdatedChannel } from '../UpdatedChannel' +import { renderWithProviders } from '../../../__testing-utils__' -jest.mock('../../../redux/config') +vi.mock('../../../redux/config') const render = () => { return renderWithProviders(, { i18nInstance: i18n }) } -const mockGetUpdateChannelOptions = getUpdateChannelOptions as jest.MockedFunction< - typeof getUpdateChannelOptions -> -const mockGetUpdateChannel = getUpdateChannel as jest.MockedFunction< - typeof getUpdateChannel -> -// const mockUpdateConfigValue = updateConfigValue as jest.MockedFunction< -// typeof updateConfigValue -// > - describe('UpdatedChannel', () => { beforeEach(() => { - mockGetUpdateChannelOptions.mockReturnValue([ + vi.mocked(getUpdateChannelOptions).mockReturnValue([ { label: 'Stable', value: 'latest', @@ -36,7 +26,7 @@ describe('UpdatedChannel', () => { { label: 'Beta', value: 'beta' }, { label: 'Alpha', value: 'alpha' }, ]) - mockGetUpdateChannel.mockReturnValue('beta') + vi.mocked(getUpdateChannel).mockReturnValue('beta') }) it('renders text and selector', () => { render() diff --git a/app/src/organisms/Alerts/__tests__/Alerts.test.tsx b/app/src/organisms/Alerts/__tests__/Alerts.test.tsx index 631f8ba779b..26f2bedb2bb 100644 --- a/app/src/organisms/Alerts/__tests__/Alerts.test.tsx +++ b/app/src/organisms/Alerts/__tests__/Alerts.test.tsx @@ -1,3 +1,5 @@ +import { describe, it } from 'vitest' + describe('app-wide Alerts component', () => { it.todo('replace deprecated enzyme test') }) diff --git a/app/src/organisms/Alerts/__tests__/U2EDriverOutdatedAlert.test.tsx b/app/src/organisms/Alerts/__tests__/U2EDriverOutdatedAlert.test.tsx index 5737f3336fe..2d6a04526d3 100644 --- a/app/src/organisms/Alerts/__tests__/U2EDriverOutdatedAlert.test.tsx +++ b/app/src/organisms/Alerts/__tests__/U2EDriverOutdatedAlert.test.tsx @@ -1,3 +1,5 @@ +import { describe, it } from 'vitest' + describe('U2EDriverOutdatedAlert', () => { it.todo('replace deprecated enzyme test') }) diff --git a/app/src/organisms/AppSettings/__tests__/ConnectRobotSlideout.test.tsx b/app/src/organisms/AppSettings/__tests__/ConnectRobotSlideout.test.tsx index 16db47cc9c6..ca03b33463c 100644 --- a/app/src/organisms/AppSettings/__tests__/ConnectRobotSlideout.test.tsx +++ b/app/src/organisms/AppSettings/__tests__/ConnectRobotSlideout.test.tsx @@ -1,14 +1,15 @@ import * as React from 'react' import { fireEvent, screen } from '@testing-library/react' -import { renderWithProviders } from '@opentrons/components' - +import '@testing-library/jest-dom/vitest' +import { describe, it, expect, vi, beforeEach } from 'vitest' import { i18n } from '../../../i18n' import { getScanning, getViewableRobots } from '../../../redux/discovery' import { getConfig } from '../../../redux/config' +import { renderWithProviders } from '../../../__testing-utils__' import { ConnectRobotSlideout } from '../ConnectRobotSlideout' -jest.mock('../../../redux/discovery') -jest.mock('../../../redux/config') +vi.mock('../../../redux/discovery') +vi.mock('../../../redux/config') const render = (props: React.ComponentProps) => { return renderWithProviders(, { @@ -16,24 +17,18 @@ const render = (props: React.ComponentProps) => { })[0] } -const mockGetScanning = getScanning as jest.MockedFunction -const mockGetConfig = getConfig as jest.MockedFunction -const mockGetViewableRobots = getViewableRobots as jest.MockedFunction< - typeof getViewableRobots -> - describe('ConnectRobotSlideout', () => { let props: React.ComponentProps beforeEach(() => { - mockGetScanning.mockReturnValue(true) + vi.mocked(getScanning).mockReturnValue(true) - mockGetConfig.mockReturnValue({ + vi.mocked(getConfig).mockReturnValue({ discovery: { candidates: ['1.1.1.1', 'localhost', '192.168.1.1'], }, } as any) - mockGetViewableRobots.mockReturnValue([ + vi.mocked(getViewableRobots).mockReturnValue([ { name: 'other-robot-name', host: '1.1.1.1', @@ -56,16 +51,12 @@ describe('ConnectRobotSlideout', () => { props = { candidates: [], - checkIpAndHostname: jest.fn(), + checkIpAndHostname: vi.fn(), isExpanded: true, - onCloseClick: jest.fn(), + onCloseClick: vi.fn(), } as React.ComponentProps }) - afterEach(() => { - jest.resetAllMocks() - }) - it('renders correct title, body, and footer for ConnectRobotSlideout', () => { render(props) screen.getByText('Connect to a Robot via IP Address') @@ -132,24 +123,6 @@ describe('ConnectRobotSlideout', () => { screen.queryByText('Available') }) - it.todo( - 'Clicking Add button with an IP address/hostname should display the IP address/hostname and Not Found label' - ) - // NOTE: consider mocking formik here? - // , async () => { - // mockGetConfig.mockReturnValue({ discovery: { candidates: ['1.1.1.2'] } } as any) - // mockGetViewableRobots.mockReturnValue([] as any[]) - // render(props) - // const user = userEvent.setup() - // const notFoundIpAddress = '1.1.1.2' - // await user.type(screen.getByRole('textbox'), notFoundIpAddress) - // await user.click(screen.getByRole('button', { name: 'Add' })) - // await waitFor(() => - // expect(screen.getByText(notFoundIpAddress)) - // ) - // screen.getByText('Not Found') - // }) - it('Clicking Close button in a row should remove an IP address/hostname', async () => { render(props) const targetIpAddress = 'test' diff --git a/app/src/organisms/AppSettings/__tests__/PreviousVersionModal.test.tsx b/app/src/organisms/AppSettings/__tests__/PreviousVersionModal.test.tsx index 425b7d34cbb..3202528f2ef 100644 --- a/app/src/organisms/AppSettings/__tests__/PreviousVersionModal.test.tsx +++ b/app/src/organisms/AppSettings/__tests__/PreviousVersionModal.test.tsx @@ -1,7 +1,9 @@ import * as React from 'react' import { fireEvent, screen } from '@testing-library/react' -import { renderWithProviders } from '@opentrons/components' +import { describe, it, expect, vi } from 'vitest' +import '@testing-library/jest-dom/vitest' import { i18n } from '../../../i18n' +import { renderWithProviders } from '../../../__testing-utils__' import { PreviousVersionModal, UNINSTALL_APP_URL, @@ -14,7 +16,7 @@ const render = (props: React.ComponentProps) => { }) } const props: React.ComponentProps = { - closeModal: jest.fn(), + closeModal: vi.fn(), } describe('PreviousVersionModal', () => { diff --git a/app/src/organisms/ApplyHistoricOffsets/__tests__/ApplyHistoricOffsets.test.tsx b/app/src/organisms/ApplyHistoricOffsets/__tests__/ApplyHistoricOffsets.test.tsx index ab637f9b5b8..2fcef7e7ea1 100644 --- a/app/src/organisms/ApplyHistoricOffsets/__tests__/ApplyHistoricOffsets.test.tsx +++ b/app/src/organisms/ApplyHistoricOffsets/__tests__/ApplyHistoricOffsets.test.tsx @@ -1,24 +1,18 @@ import * as React from 'react' -import { renderWithProviders } from '@opentrons/components' +import { fireEvent, screen } from '@testing-library/react' +import { describe, it, expect, vi } from 'vitest' import fixture_adapter from '@opentrons/shared-data/labware/definitions/2/opentrons_96_pcr_adapter/1.json' import fixture_96_wellplate from '@opentrons/shared-data/labware/definitions/2/opentrons_96_wellplate_200ul_pcr_full_skirt/1.json' import { i18n } from '../../../i18n' -import { ApplyHistoricOffsets } from '..' +import { renderWithProviders } from '../../../__testing-utils__' import { getIsLabwareOffsetCodeSnippetsOn } from '../../../redux/config' import { getLabwareDefinitionsFromCommands } from '../../LabwarePositionCheck/utils/labware' +import { ApplyHistoricOffsets } from '..' import type { LabwareDefinition2 } from '@opentrons/shared-data' import type { OffsetCandidate } from '../hooks/useOffsetCandidatesForAnalysis' -import { fireEvent, screen } from '@testing-library/react' -jest.mock('../../../redux/config') -jest.mock('../../LabwarePositionCheck/utils/labware') - -const mockGetIsLabwareOffsetCodeSnippetsOn = getIsLabwareOffsetCodeSnippetsOn as jest.MockedFunction< - typeof getIsLabwareOffsetCodeSnippetsOn -> -const mockGetLabwareDefinitionsFromCommands = getLabwareDefinitionsFromCommands as jest.MockedFunction< - typeof getLabwareDefinitionsFromCommands -> +vi.mock('../../../redux/config') +vi.mock('../../LabwarePositionCheck/utils/labware') const mockLabwareDef = fixture_96_wellplate as LabwareDefinition2 const mockAdapterDef = fixture_adapter as LabwareDefinition2 @@ -87,10 +81,6 @@ describe('ApplyHistoricOffsets', () => { { i18nInstance: i18n } ) - afterEach(() => { - jest.resetAllMocks() - }) - it('renders correct copy when shouldApplyOffsets is true', () => { render() screen.getByText('Apply labware offset data') @@ -104,7 +94,7 @@ describe('ApplyHistoricOffsets', () => { }) it('renders view data modal when link clicked, with correct copy and table row for each candidate', () => { - mockGetLabwareDefinitionsFromCommands.mockReturnValue([ + vi.mocked(getLabwareDefinitionsFromCommands).mockReturnValue([ mockLabwareDef, mockAdapterDef, ]) @@ -167,11 +157,11 @@ describe('ApplyHistoricOffsets', () => { }) it('renders tabbed offset data with snippets when config option is selected', () => { - mockGetLabwareDefinitionsFromCommands.mockReturnValue([ + vi.mocked(getLabwareDefinitionsFromCommands).mockReturnValue([ mockLabwareDef, mockAdapterDef, ]) - mockGetIsLabwareOffsetCodeSnippetsOn.mockReturnValue(true) + vi.mocked(getIsLabwareOffsetCodeSnippetsOn).mockReturnValue(true) render() const viewDataButton = screen.getByText('View data') fireEvent.click(viewDataButton) diff --git a/app/src/organisms/ApplyHistoricOffsets/__tests__/LabwareOffsetTable.test.tsx b/app/src/organisms/ApplyHistoricOffsets/__tests__/LabwareOffsetTable.test.tsx index 9a2c76a0431..89cd694ad30 100644 --- a/app/src/organisms/ApplyHistoricOffsets/__tests__/LabwareOffsetTable.test.tsx +++ b/app/src/organisms/ApplyHistoricOffsets/__tests__/LabwareOffsetTable.test.tsx @@ -1,15 +1,15 @@ import * as React from 'react' -import { renderWithProviders } from '@opentrons/components' import { screen } from '@testing-library/react' -import fixture_adapter from '@opentrons/shared-data/labware/definitions/2/opentrons_96_pcr_adapter/1.json' -import fixture_96_wellplate from '@opentrons/shared-data/labware/definitions/2/opentrons_96_wellplate_200ul_pcr_full_skirt/1.json' +import { describe, it, expect } from 'vitest' +import { fixture96Plate, fixtureTiprackAdapter } from '@opentrons/shared-data' import { i18n } from '../../../i18n' +import { renderWithProviders } from '../../../__testing-utils__' import { LabwareOffsetTable } from '../LabwareOffsetTable' import type { LabwareDefinition2 } from '@opentrons/shared-data' import type { OffsetCandidate } from '../hooks/useOffsetCandidatesForAnalysis' -const mockLabwareDef = fixture_96_wellplate as LabwareDefinition2 -const mockAdapterDef = fixture_adapter as LabwareDefinition2 +const mockLabwareDef = fixture96Plate as LabwareDefinition2 +const mockAdapterDef = fixtureTiprackAdapter as LabwareDefinition2 const mockFirstCandidate: OffsetCandidate = { id: 'first_offset_id', @@ -67,10 +67,6 @@ const render = () => ) describe('LabwareOffsetTable', () => { - afterEach(() => { - jest.resetAllMocks() - }) - it('renders headers text and values for each candidate', () => { render() // headers @@ -103,9 +99,7 @@ describe('LabwareOffsetTable', () => { screen.getByText('8.00') screen.getByText('9.00') // fourth candidate is labware on adapter on module - screen.getByText( - 'Opentrons 96 PCR Heater-Shaker Adapter in Heater-Shaker Module GEN1 in Slot 3' - ) + screen.getByText('in Heater-Shaker Module GEN1 in Slot 3') screen.getByText('Fourth Fake Labware Display Name') screen.getByText('7.20') screen.getByText('8.10') diff --git a/app/src/organisms/ApplyHistoricOffsets/hooks/__tests__/getLabwareLocationCombos.test.ts b/app/src/organisms/ApplyHistoricOffsets/hooks/__tests__/getLabwareLocationCombos.test.ts index 5c3278634b5..ad704944ddf 100644 --- a/app/src/organisms/ApplyHistoricOffsets/hooks/__tests__/getLabwareLocationCombos.test.ts +++ b/app/src/organisms/ApplyHistoricOffsets/hooks/__tests__/getLabwareLocationCombos.test.ts @@ -1,15 +1,15 @@ -import fixture_tiprack_300_ul from '@opentrons/shared-data/labware/fixtures/2/fixture_tiprack_300_ul.json' -import fixture_adapter from '@opentrons/shared-data/labware/definitions/2/opentrons_96_pcr_adapter/1.json' +import { describe, it, expect, beforeEach } from 'vitest' import { getLabwareDefURI, - ProtocolAnalysisOutput, + opentrons96PcrAdapterV1, + fixtureTiprack300ul, } from '@opentrons/shared-data' import { getLabwareLocationCombos } from '../getLabwareLocationCombos' import type { LabwareDefinition2, RunTimeCommand } from '@opentrons/shared-data' -const mockAdapterDef = fixture_adapter as LabwareDefinition2 -const mockLabwareDef = fixture_tiprack_300_ul as LabwareDefinition2 +const mockAdapterDef = opentrons96PcrAdapterV1 as LabwareDefinition2 +const mockLabwareDef = fixtureTiprack300ul as LabwareDefinition2 const mockLoadLabwareCommands: RunTimeCommand[] = [ { key: 'CommandKey0', @@ -132,7 +132,7 @@ const mockLoadLabwareCommands: RunTimeCommand[] = [ }, ] -const mockLabwareEntities: ProtocolAnalysisOutput['labware'] = [ +const mockLabwareEntities = [ { id: 'firstLabwareId', loadName: mockLabwareDef.parameters.loadName, @@ -186,7 +186,7 @@ describe('getLabwareLocationCombos', () => { const commands: RunTimeCommand[] = mockLoadLabwareCommands const labware = mockLabwareEntities - const modules: ProtocolAnalysisOutput['modules'] = [ + const modules: any = [ { id: 'firstModuleId', model: 'heaterShakerModuleV1', @@ -281,7 +281,7 @@ describe('getLabwareLocationCombos', () => { }, ] - const labware: ProtocolAnalysisOutput['labware'] = [ + const labware = [ { id: 'firstLabwareId', loadName: mockLabwareDef.parameters.loadName, @@ -304,7 +304,7 @@ describe('getLabwareLocationCombos', () => { displayName: 'duplicate labware nickname', }, ] - const modules: ProtocolAnalysisOutput['modules'] = [ + const modules: any = [ { id: 'firstModuleId', model: 'heaterShakerModuleV1', diff --git a/app/src/organisms/ApplyHistoricOffsets/hooks/__tests__/useHistoricRunDetails.test.tsx b/app/src/organisms/ApplyHistoricOffsets/hooks/__tests__/useHistoricRunDetails.test.tsx index 8e72743a1cd..f7fb89db7e6 100644 --- a/app/src/organisms/ApplyHistoricOffsets/hooks/__tests__/useHistoricRunDetails.test.tsx +++ b/app/src/organisms/ApplyHistoricOffsets/hooks/__tests__/useHistoricRunDetails.test.tsx @@ -1,5 +1,6 @@ import * as React from 'react' -import { when } from 'jest-when' +import { describe, it, expect, vi } from 'vitest' +import { when } from 'vitest-when' import { renderHook, waitFor } from '@testing-library/react' import { useNotifyAllRunsQuery } from '../../../../resources/runs/useNotifyAllRunsQuery' @@ -9,11 +10,7 @@ import { mockSuccessQueryResults } from '../../../../__fixtures__' import type { RunData } from '@opentrons/api-client' -jest.mock('../../../../resources/runs/useNotifyAllRunsQuery') - -const mockuseNotifyAllRunsQuery = useNotifyAllRunsQuery as jest.MockedFunction< - typeof useNotifyAllRunsQuery -> +vi.mock('../../../../resources/runs/useNotifyAllRunsQuery') const MOCK_RUN_LATER: RunData = { ...mockRunningRun, @@ -33,9 +30,9 @@ const MOCK_RUN_EARLIER: RunData = { } describe('useHistoricRunDetails', () => { - when(mockuseNotifyAllRunsQuery) + when(useNotifyAllRunsQuery) .calledWith({}, {}, undefined) - .mockReturnValue( + .thenReturn( mockSuccessQueryResults({ data: [MOCK_RUN_LATER, MOCK_RUN_EARLIER], links: {}, @@ -52,9 +49,9 @@ describe('useHistoricRunDetails', () => { }) }) it('returns historical run details with newest first to specific host', async () => { - when(mockuseNotifyAllRunsQuery) + when(useNotifyAllRunsQuery) .calledWith({}, {}, { hostname: 'fakeIp' }) - .mockReturnValue( + .thenReturn( mockSuccessQueryResults({ data: [MOCK_RUN_EARLIER, MOCK_RUN_EARLIER, MOCK_RUN_LATER], links: {}, diff --git a/app/src/organisms/ApplyHistoricOffsets/hooks/__tests__/useOffsetCandidatesForAnalysis.test.tsx b/app/src/organisms/ApplyHistoricOffsets/hooks/__tests__/useOffsetCandidatesForAnalysis.test.tsx index 47696eec10f..cfc3a2f459b 100644 --- a/app/src/organisms/ApplyHistoricOffsets/hooks/__tests__/useOffsetCandidatesForAnalysis.test.tsx +++ b/app/src/organisms/ApplyHistoricOffsets/hooks/__tests__/useOffsetCandidatesForAnalysis.test.tsx @@ -1,10 +1,11 @@ import * as React from 'react' -import { resetAllWhenMocks, when } from 'jest-when' +import { describe, it, expect, vi } from 'vitest' +import { when } from 'vitest-when' import { renderHook, waitFor } from '@testing-library/react' -import fixture_tiprack_300_ul from '@opentrons/shared-data/labware/fixtures/2/fixture_tiprack_300_ul.json' import { getLabwareDisplayName, getLoadedLabwareDefinitionsByUri, + fixtureTiprack300ul, } from '@opentrons/shared-data' import { useAllHistoricOffsets } from '../useAllHistoricOffsets' import { getLabwareLocationCombos } from '../getLabwareLocationCombos' @@ -15,20 +16,12 @@ import { storedProtocolData as storedProtocolDataFixture } from '../../../../red import type { LabwareDefinition2 } from '@opentrons/shared-data' import type { OffsetCandidate } from '../useOffsetCandidatesForAnalysis' -jest.mock('../useAllHistoricOffsets') -jest.mock('../getLabwareLocationCombos') -jest.mock('@opentrons/shared-data') +vi.mock('../useAllHistoricOffsets') +vi.mock('../getLabwareLocationCombos') +vi.mock('@opentrons/shared-data') + +const mockLabwareDef = fixtureTiprack300ul as LabwareDefinition2 -const mockLabwareDef = fixture_tiprack_300_ul as LabwareDefinition2 -const mockUseAllHistoricOffsets = useAllHistoricOffsets as jest.MockedFunction< - typeof useAllHistoricOffsets -> -const mockGetLabwareLocationCombos = getLabwareLocationCombos as jest.MockedFunction< - typeof getLabwareLocationCombos -> -const mockGetLoadedLabwareDefinitionsByUri = getLoadedLabwareDefinitionsByUri as jest.MockedFunction< - typeof getLoadedLabwareDefinitionsByUri -> const mockFirstCandidate: OffsetCandidate = { id: 'first_offset_id', labwareDisplayName: 'First Fake Labware Display Name', @@ -68,18 +61,18 @@ const mockRobotIp = 'fakeRobotIp' describe('useOffsetCandidatesForAnalysis', () => { beforeEach(() => { - when(mockUseAllHistoricOffsets) + when(useAllHistoricOffsets) .calledWith({ hostname: mockRobotIp }) - .mockReturnValue([ + .thenReturn([ mockFirstDupCandidate, mockThirdCandidate, mockSecondCandidate, mockFirstCandidate, ]) - when(mockUseAllHistoricOffsets).calledWith(null).mockReturnValue([]) - when(mockGetLabwareLocationCombos) + when(useAllHistoricOffsets).calledWith(null).thenReturn([]) + when(getLabwareLocationCombos) .calledWith(expect.any(Array), expect.any(Array), expect.any(Array)) - .mockReturnValue([ + .thenReturn([ { location: { slotName: '1' }, definitionUri: 'firstFakeDefURI', @@ -97,19 +90,15 @@ describe('useOffsetCandidatesForAnalysis', () => { definitionUri: 'thirdFakeDefURI', }, ]) - when(mockGetLoadedLabwareDefinitionsByUri) + when(getLoadedLabwareDefinitionsByUri) .calledWith(expect.any(Array)) - .mockReturnValue({ + .thenReturn({ firstFakeDefURI: mockLabwareDef, secondFakeDefURI: mockLabwareDef, thirdFakeDefURI: mockLabwareDef, }) }) - afterEach(() => { - resetAllWhenMocks() - }) - it('returns an empty array if robot ip but no analysis output', async () => { const wrapper: React.FunctionComponent<{ children: React.ReactNode }> = ({ children, diff --git a/app/src/organisms/Breadcrumbs/__tests__/Breadcrumbs.test.tsx b/app/src/organisms/Breadcrumbs/__tests__/Breadcrumbs.test.tsx index c47a93aa85f..688a3d8a9f1 100644 --- a/app/src/organisms/Breadcrumbs/__tests__/Breadcrumbs.test.tsx +++ b/app/src/organisms/Breadcrumbs/__tests__/Breadcrumbs.test.tsx @@ -1,8 +1,8 @@ import * as React from 'react' import { MemoryRouter, Route, Switch } from 'react-router-dom' -import { when } from 'jest-when' +import { when } from 'vitest-when' +import { describe, it, expect, beforeEach, vi } from 'vitest' -import { renderWithProviders } from '@opentrons/components' import { fireEvent, screen } from '@testing-library/react' import { i18n } from '../../../i18n' @@ -12,6 +12,7 @@ import { } from '../../../organisms/Devices/hooks' import { getProtocolDisplayName } from '../../../organisms/ProtocolsLanding/utils' import { getIsOnDevice } from '../../../redux/config' +import { renderWithProviders } from '../../../__testing-utils__' import { mockConnectableRobot } from '../../../redux/discovery/__fixtures__' import { getStoredProtocol } from '../../../redux/protocol-storage' import { storedProtocolData as storedProtocolDataFixture } from '../../../redux/protocol-storage/__fixtures__' @@ -19,24 +20,10 @@ import { Breadcrumbs } from '..' import type { State } from '../../../redux/types' -jest.mock('../../../organisms/Devices/hooks') -jest.mock('../../../organisms/ProtocolsLanding/utils') -jest.mock('../../../redux/config') -jest.mock('../../../redux/protocol-storage') - -const mockUseRobot = useRobot as jest.MockedFunction -const mockUseRunCreatedAtTimestamp = useRunCreatedAtTimestamp as jest.MockedFunction< - typeof useRunCreatedAtTimestamp -> -const mockGetStoredProtocol = getStoredProtocol as jest.MockedFunction< - typeof getStoredProtocol -> -const mockGetIsOnDevice = getIsOnDevice as jest.MockedFunction< - typeof getIsOnDevice -> -const mockGetProtocolDisplayName = getProtocolDisplayName as jest.MockedFunction< - typeof getProtocolDisplayName -> +vi.mock('../../../organisms/Devices/hooks') +vi.mock('../../../organisms/ProtocolsLanding/utils') +vi.mock('../../../redux/config') +vi.mock('../../../redux/protocol-storage') const ROBOT_NAME = 'otie' const RUN_ID = '95e67900-bc9f-4fbf-92c6-cc4d7226a51b' @@ -70,25 +57,21 @@ const render = (path = '/') => { describe('Breadcrumbs', () => { beforeEach(() => { - when(mockUseRobot) - .calledWith(ROBOT_NAME) - .mockReturnValue(mockConnectableRobot) - when(mockUseRunCreatedAtTimestamp) - .calledWith(RUN_ID) - .mockReturnValue(CREATED_AT) - when(mockGetStoredProtocol) + when(useRobot).calledWith(ROBOT_NAME).thenReturn(mockConnectableRobot) + when(useRunCreatedAtTimestamp).calledWith(RUN_ID).thenReturn(CREATED_AT) + when(getStoredProtocol) .calledWith({} as State, PROTOCOL_KEY) - .mockReturnValue(storedProtocolDataFixture) - when(mockGetIsOnDevice) + .thenReturn(storedProtocolDataFixture) + when(getIsOnDevice) .calledWith({} as State) - .mockReturnValue(false) - when(mockGetProtocolDisplayName) + .thenReturn(false) + when(getProtocolDisplayName) .calledWith( storedProtocolDataFixture.protocolKey, storedProtocolDataFixture.srcFileNames, storedProtocolDataFixture.mostRecentAnalysis ) - .mockReturnValue(PROTOCOL_NAME) + .thenReturn(PROTOCOL_NAME) }) it('renders an array of device breadcrumbs', () => { render(`/devices/${ROBOT_NAME}/protocol-runs/${RUN_ID}`) @@ -104,9 +87,9 @@ describe('Breadcrumbs', () => { }) it('does not render devices breadcrumb when in on device mode', () => { - when(mockGetIsOnDevice) + when(getIsOnDevice) .calledWith({} as State) - .mockReturnValue(true) + .thenReturn(true) render(`/devices/${ROBOT_NAME}/protocol-runs/${RUN_ID}`) expect(screen.queryByText('Devices')).toBeNull() screen.getByText('otie') diff --git a/app/src/pages/InstrumentsDashboard/__tests__/InstrumentsDashboard.test.tsx b/app/src/pages/InstrumentsDashboard/__tests__/InstrumentsDashboard.test.tsx index fe5db8748b7..0dc938b663a 100644 --- a/app/src/pages/InstrumentsDashboard/__tests__/InstrumentsDashboard.test.tsx +++ b/app/src/pages/InstrumentsDashboard/__tests__/InstrumentsDashboard.test.tsx @@ -74,15 +74,18 @@ const mock96ChannelData = { }, }, } -vi.mock('@opentrons/react-api-client', async (importOriginal) => { +vi.mock('@opentrons/react-api-client', async importOriginal => { const actual = await importOriginal() return { ...actual, - useInstrumentsQuery: vi.fn(() => ({ - data: { - data: [mockLeftPipetteData, mockRightPipetteData, mockGripperData], - }, - } as any)) + useInstrumentsQuery: vi.fn( + () => + ({ + data: { + data: [mockLeftPipetteData, mockRightPipetteData, mockGripperData], + }, + } as any) + ), } }) vi.mock('../../../organisms/GripperWizardFlows') @@ -153,19 +156,25 @@ describe('InstrumentsDashboard', () => { screen.getByText(mockGripperData.serialNumber) }) it('should open choose pipette to attach to left mount when empty and clicked', () => { - vi.mocked(useInstrumentsQuery).mockReturnValue({ data: { data: [] } } as any) + vi.mocked(useInstrumentsQuery).mockReturnValue({ + data: { data: [] }, + } as any) render() fireEvent.click(screen.getByText('left Mount')) expect(vi.mocked(ChoosePipette)).toHaveBeenCalled() }) it('should open choose pipette to attach to right mount when empty and clicked', () => { - vi.mocked(useInstrumentsQuery).mockReturnValue({ data: { data: [] } } as any) + vi.mocked(useInstrumentsQuery).mockReturnValue({ + data: { data: [] }, + } as any) render() fireEvent.click(screen.getByText('right Mount')) expect(vi.mocked(ChoosePipette)).toHaveBeenCalled() }) it('should open attach gripper wizard when extension mount item empty and clicked', () => { - vi.mocked(useInstrumentsQuery).mockReturnValue({ data: { data: [] } } as any) + vi.mocked(useInstrumentsQuery).mockReturnValue({ + data: { data: [] }, + } as any) render() fireEvent.click(screen.getByText('extension Mount')) expect(vi.mocked(GripperWizardFlows)).toHaveBeenCalled() diff --git a/app/src/resources/deck_configuration/__tests__/hooks.test.ts b/app/src/resources/deck_configuration/__tests__/hooks.test.ts index 5a37005074e..29e12c44bb1 100644 --- a/app/src/resources/deck_configuration/__tests__/hooks.test.ts +++ b/app/src/resources/deck_configuration/__tests__/hooks.test.ts @@ -1,4 +1,5 @@ -import { when, resetAllWhenMocks } from 'jest-when' +import { describe, it, vi, beforeEach } from 'vitest' +import { when } from 'vitest-when' import { useDeckConfigurationQuery } from '@opentrons/react-api-client' import { @@ -12,11 +13,7 @@ import { import type { UseQueryResult } from 'react-query' import type { DeckConfiguration } from '@opentrons/shared-data' -jest.mock('@opentrons/react-api-client') - -const mockUseDeckConfigurationQuery = useDeckConfigurationQuery as jest.MockedFunction< - typeof useDeckConfigurationQuery -> +vi.mock('@opentrons/react-api-client') const MOCK_DECK_CONFIG: DeckConfiguration = [ { @@ -55,13 +52,12 @@ const MOCK_DECK_CONFIG: DeckConfiguration = [ describe('useDeckConfigurationCompatibility', () => { beforeEach(() => { - when(mockUseDeckConfigurationQuery) + when(useDeckConfigurationQuery) .calledWith() - .mockReturnValue({ + .thenReturn({ data: MOCK_DECK_CONFIG, } as UseQueryResult) }) - afterEach(() => resetAllWhenMocks()) it('returns configured status if fixture is configured at location', () => {}) }) diff --git a/app/src/resources/devices/__tests__/useIsEstopNotDisengaged.test.tsx b/app/src/resources/devices/__tests__/useIsEstopNotDisengaged.test.tsx index 2107df52711..7d64b32de17 100644 --- a/app/src/resources/devices/__tests__/useIsEstopNotDisengaged.test.tsx +++ b/app/src/resources/devices/__tests__/useIsEstopNotDisengaged.test.tsx @@ -1,5 +1,5 @@ -import { when, resetAllWhenMocks } from 'jest-when' - +import { when } from 'vitest-when' +import { describe, it, expect, vi, beforeEach } from 'vitest' import { useIsFlex } from '../../../organisms/Devices/hooks' import { useEstopQuery } from '@opentrons/react-api-client' import { @@ -10,13 +10,8 @@ import { } from '../../../organisms/EmergencyStop' import { useIsEstopNotDisengaged } from '../hooks/useIsEstopNotDisengaged' -jest.mock('@opentrons/react-api-client') -jest.mock('../../../organisms/Devices/hooks') - -const mockUseIsFlex = useIsFlex as jest.MockedFunction -const mockUseEstopQuery = useEstopQuery as jest.MockedFunction< - typeof useEstopQuery -> +vi.mock('@opentrons/react-api-client') +vi.mock('../../../organisms/Devices/hooks') const ROBOT_NAME = 'mockRobot' const mockEstopStatus = { @@ -47,25 +42,20 @@ const mockNotPresentStatus = { describe('useIsEstopNotDisengaged', () => { beforeEach(() => { - when(mockUseIsFlex).calledWith(ROBOT_NAME).mockReturnValue(true) - mockUseEstopQuery.mockReturnValue({ + when(useIsFlex).calledWith(ROBOT_NAME).thenReturn(true) + vi.mocked(useEstopQuery).mockReturnValue({ data: mockEstopStatus, error: null, } as any) }) - afterAll(() => { - resetAllWhenMocks() - jest.clearAllMocks() - }) - it('should return false when e-stop status is disengaged', () => { const isEstopNotDisengaged = useIsEstopNotDisengaged(ROBOT_NAME) expect(isEstopNotDisengaged).toBe(false) }) it('should return true when e-stop status is physically engaged', () => { - mockUseEstopQuery.mockReturnValue({ + vi.mocked(useEstopQuery).mockReturnValue({ data: mockPhysicallyEngagedStatus, } as any) const isEstopNotDisengaged = useIsEstopNotDisengaged(ROBOT_NAME) @@ -73,20 +63,22 @@ describe('useIsEstopNotDisengaged', () => { }) it('should return true when e-stop status is logically engaged', () => { - mockUseEstopQuery.mockReturnValue({ + vi.mocked(useEstopQuery).mockReturnValue({ data: mockLogicallyEngagedStatus, } as any) const isEstopNotDisengaged = useIsEstopNotDisengaged(ROBOT_NAME) expect(isEstopNotDisengaged).toBe(true) }) it('should return true when e-stop status is not present', () => { - mockUseEstopQuery.mockReturnValue({ data: mockNotPresentStatus } as any) + vi.mocked(useEstopQuery).mockReturnValue({ + data: mockNotPresentStatus, + } as any) const isEstopNotDisengaged = useIsEstopNotDisengaged(ROBOT_NAME) expect(isEstopNotDisengaged).toBe(true) }) it('should return false when a robot is OT-2', () => { - when(mockUseIsFlex).calledWith(ROBOT_NAME).mockReturnValue(false) - mockUseEstopQuery.mockReturnValue({ + when(useIsFlex).calledWith(ROBOT_NAME).thenReturn(false) + vi.mocked(useEstopQuery).mockReturnValue({ data: mockPhysicallyEngagedStatus, } as any) const isEstopNotDisengaged = useIsEstopNotDisengaged(ROBOT_NAME) diff --git a/app/src/resources/networking/__tests__/useCanDisconnect.test.tsx b/app/src/resources/networking/__tests__/useCanDisconnect.test.tsx index bbb9580c461..5a81f052edd 100644 --- a/app/src/resources/networking/__tests__/useCanDisconnect.test.tsx +++ b/app/src/resources/networking/__tests__/useCanDisconnect.test.tsx @@ -1,7 +1,9 @@ import * as React from 'react' -import { when, resetAllWhenMocks } from 'jest-when' +import { when } from 'vitest-when' +import { describe, it, expect, vi, beforeEach } from 'vitest' import { createStore } from 'redux' import { Provider } from 'react-redux' +import { SECURITY_WPA_EAP, WifiNetwork } from '@opentrons/api-client' import { renderHook } from '@testing-library/react' import { getRobotApiVersionByName } from '../../../redux/discovery' @@ -11,16 +13,10 @@ import { useWifiList } from '../hooks/useWifiList' import type { Store } from 'redux' import type { State } from '../../../redux/types' -import { SECURITY_WPA_EAP, WifiNetwork } from '@opentrons/api-client' - -jest.mock('../hooks/useWifiList') -jest.mock('../../../organisms/Devices/hooks') -jest.mock('../../../redux/discovery') -const mockGetRobotApiVersionByName = getRobotApiVersionByName as jest.MockedFunction< - typeof getRobotApiVersionByName -> -const mockUseIsFlex = useIsFlex as jest.MockedFunction +vi.mock('../hooks/useWifiList') +vi.mock('../../../organisms/Devices/hooks') +vi.mock('../../../redux/discovery') const store: Store = createStore(state => state, {}) @@ -38,30 +34,29 @@ const mockWifiNetwork: WifiNetwork = { describe('useCanDisconnect', () => { beforeEach(() => { - when(useWifiList).calledWith('otie').mockReturnValue([]) - when(mockUseIsFlex).calledWith('otie').mockReturnValue(false) + when(useWifiList).calledWith('otie').thenReturn([]) + when(useIsFlex).calledWith('otie').thenReturn(false) }) - afterEach(() => resetAllWhenMocks()) it('useCanDisconnect returns true if active network, robot >= 3.17', () => { when(useWifiList) .calledWith('otie') - .mockReturnValue([{ ...mockWifiNetwork, active: true }]) + .thenReturn([{ ...mockWifiNetwork, active: true }]) - when(mockGetRobotApiVersionByName) + when(getRobotApiVersionByName) .calledWith({} as any, 'otie') - .mockReturnValue('3.17.0') + .thenReturn('3.17.0') const { result } = renderHook(() => useCanDisconnect('otie'), { wrapper }) expect(result.current).toBe(true) }) it('useCanDisconnect returns false if no list in state', () => { - when(useWifiList).calledWith('otie').mockReturnValue([]) + when(useWifiList).calledWith('otie').thenReturn([]) - when(mockGetRobotApiVersionByName) + when(getRobotApiVersionByName) .calledWith({} as any, 'otie') - .mockReturnValue('3.17.0') + .thenReturn('3.17.0') const { result } = renderHook(() => useCanDisconnect('otie'), { wrapper }) expect(result.current).toBe(false) @@ -70,11 +65,11 @@ describe('useCanDisconnect', () => { it('useCanDisconnect returns false if no active network', () => { when(useWifiList) .calledWith('otie') - .mockReturnValue([{ ...mockWifiNetwork, active: false }]) + .thenReturn([{ ...mockWifiNetwork, active: false }]) - when(mockGetRobotApiVersionByName) + when(getRobotApiVersionByName) .calledWith({} as any, 'otie') - .mockReturnValue('3.17.0') + .thenReturn('3.17.0') const { result } = renderHook(() => useCanDisconnect('otie'), { wrapper }) expect(result.current).toBe(false) @@ -83,11 +78,11 @@ describe('useCanDisconnect', () => { it('useCanDisconnect returns false if less than 3.17.0', () => { when(useWifiList) .calledWith('otie') - .mockReturnValue([{ ...mockWifiNetwork, active: true }]) + .thenReturn([{ ...mockWifiNetwork, active: true }]) - when(mockGetRobotApiVersionByName) + when(getRobotApiVersionByName) .calledWith({} as any, 'otie') - .mockReturnValue('3.16.999') + .thenReturn('3.16.999') const { result } = renderHook(() => useCanDisconnect('otie'), { wrapper }) expect(result.current).toBe(false) @@ -96,13 +91,13 @@ describe('useCanDisconnect', () => { it('useCanDisconnect returns true for a Flex', () => { when(useWifiList) .calledWith('otie') - .mockReturnValue([{ ...mockWifiNetwork, active: true }]) + .thenReturn([{ ...mockWifiNetwork, active: true }]) - when(mockGetRobotApiVersionByName) + when(getRobotApiVersionByName) .calledWith({} as any, 'otie') - .mockReturnValue('0.22.999-gamma.1') + .thenReturn('0.22.999-gamma.1') - when(mockUseIsFlex).calledWith('otie').mockReturnValue(true) + when(useIsFlex).calledWith('otie').thenReturn(true) const { result } = renderHook(() => useCanDisconnect('otie'), { wrapper }) expect(result.current).toBe(true) @@ -111,11 +106,11 @@ describe('useCanDisconnect', () => { it('useCanDisconnect returns false if robot API version not found', () => { when(useWifiList) .calledWith('otie') - .mockReturnValue([{ ...mockWifiNetwork, active: true }]) + .thenReturn([{ ...mockWifiNetwork, active: true }]) - when(mockGetRobotApiVersionByName) + when(getRobotApiVersionByName) .calledWith({} as any, 'otie') - .mockReturnValue(null) + .thenReturn(null) const { result } = renderHook(() => useCanDisconnect('otie'), { wrapper }) expect(result.current).toBe(false) diff --git a/app/src/resources/networking/__tests__/useNetworkConnection.test.tsx b/app/src/resources/networking/__tests__/useNetworkConnection.test.tsx index 88e28ee6b84..624a5a37917 100644 --- a/app/src/resources/networking/__tests__/useNetworkConnection.test.tsx +++ b/app/src/resources/networking/__tests__/useNetworkConnection.test.tsx @@ -1,6 +1,7 @@ import * as React from 'react' -import { when, resetAllWhenMocks } from 'jest-when' +import { when } from 'vitest-when' +import { describe, it, expect, vi, beforeEach } from 'vitest' import { Provider } from 'react-redux' import { createStore, Store } from 'redux' import { renderHook } from '@testing-library/react' @@ -10,11 +11,12 @@ import { i18n } from '../../../i18n' import { useWifiList } from '../../../resources/networking/hooks' import * as Networking from '../../../redux/networking' import * as Fixtures from '../../../redux/networking/__fixtures__' +import { getNetworkInterfaces } from '../../../redux/networking' import { useNetworkConnection } from '../hooks/useNetworkConnection' -jest.mock('../../../resources/networking/hooks') -jest.mock('../../../redux/networking/selectors') +vi.mock('../../../resources/networking/hooks') +vi.mock('../../../redux/networking/selectors') const mockRobotName = 'robot-name' const mockWifiList = [ @@ -41,12 +43,7 @@ const mockEthernet = { type: Networking.INTERFACE_ETHERNET, } -const mockUseWifiList = useWifiList as jest.MockedFunction -const mockGetNetworkInterface = Networking.getNetworkInterfaces as jest.MockedFunction< - typeof Networking.getNetworkInterfaces -> - -const store: Store = createStore(jest.fn(), {}) +const store: Store = createStore(vi.fn(), {}) // ToDo (kj:0202/2023) USB test cases will be added when USB is out describe('useNetworkConnection', () => { @@ -59,18 +56,12 @@ describe('useNetworkConnection', () => { ) - when(mockUseWifiList) - .calledWith(mockRobotName, 10000) - .mockReturnValue(mockWifiList) - when(mockGetNetworkInterface) + when(useWifiList).calledWith(mockRobotName, 10000).thenReturn(mockWifiList) + when(getNetworkInterfaces) .calledWith(undefined as any, mockRobotName) - .mockReturnValue({ wifi: mockWifi, ethernet: mockEthernet }) + .thenReturn({ wifi: mockWifi, ethernet: mockEthernet }) }) - afterEach(() => { - resetAllWhenMocks() - jest.resetAllMocks() - }) it('should return network connection information - wifi and ethernet are connected', () => { const { result } = renderHook(() => useNetworkConnection(mockRobotName), { wrapper, @@ -84,9 +75,9 @@ describe('useNetworkConnection', () => { }) it('should return network connection information - only wifi is connected and ethernet is connected', () => { - when(mockGetNetworkInterface) + when(getNetworkInterfaces) .calledWith(undefined as any, mockRobotName) - .mockReturnValue({ wifi: mockWifi, ethernet: null }) + .thenReturn({ wifi: mockWifi, ethernet: null }) const { result } = renderHook(() => useNetworkConnection(mockRobotName), { wrapper, }) @@ -97,9 +88,9 @@ describe('useNetworkConnection', () => { }) it('should return network connection information - only ethernet is connected', () => { - when(mockGetNetworkInterface) + when(getNetworkInterfaces) .calledWith(undefined as any, mockRobotName) - .mockReturnValue({ wifi: null, ethernet: mockEthernet }) + .thenReturn({ wifi: null, ethernet: mockEthernet }) const { result } = renderHook(() => useNetworkConnection(mockRobotName), { wrapper, }) @@ -109,9 +100,9 @@ describe('useNetworkConnection', () => { }) it('should return network connection information - wifi and ethernet are not connected', () => { - when(mockGetNetworkInterface) + when(getNetworkInterfaces) .calledWith(undefined as any, mockRobotName) - .mockReturnValue({ wifi: null, ethernet: null }) + .thenReturn({ wifi: null, ethernet: null }) const { result } = renderHook(() => useNetworkConnection(mockRobotName), { wrapper, }) diff --git a/app/src/resources/networking/__tests__/useWifiList.test.ts b/app/src/resources/networking/__tests__/useWifiList.test.ts index a054b369752..8db28648272 100644 --- a/app/src/resources/networking/__tests__/useWifiList.test.ts +++ b/app/src/resources/networking/__tests__/useWifiList.test.ts @@ -1,4 +1,5 @@ -import { when, resetAllWhenMocks } from 'jest-when' +import { when } from 'vitest-when' +import { describe, it, expect, vi, beforeEach } from 'vitest' import { SECURITY_WPA_EAP, WifiNetwork } from '@opentrons/api-client' import { useWifiQuery } from '@opentrons/react-api-client' import { useRobot } from '../../../organisms/Devices/hooks' @@ -6,13 +7,8 @@ import { useWifiList } from '../hooks' import type { WifiListResponse } from '@opentrons/api-client' import type { UseQueryResult } from 'react-query' -jest.mock('@opentrons/react-api-client') -jest.mock('../../../organisms/Devices/hooks') - -const mockUseWifiQuery = useWifiQuery as jest.MockedFunction< - typeof useWifiQuery -> -const mockUseRobot = useRobot as jest.MockedFunction +vi.mock('@opentrons/react-api-client') +vi.mock('../../../organisms/Devices/hooks') const mockWifiNetwork: WifiNetwork = { ssid: 'linksys', @@ -24,41 +20,40 @@ const mockWifiNetwork: WifiNetwork = { describe('useWifiList', () => { beforeEach(() => { - when(mockUseRobot).calledWith(null).mockReturnValue(null) + when(useRobot).calledWith(null).thenReturn(null) }) - afterEach(() => resetAllWhenMocks()) it('returns empty list if unavailable', () => { - when(mockUseWifiQuery) + when(useWifiQuery) .calledWith(expect.anything(), null) - .mockReturnValue({ + .thenReturn({ data: {}, } as UseQueryResult) const wifiList = useWifiList() expect(wifiList).toEqual([]) }) it('getWifiList returns wifiList from state', () => { - when(mockUseWifiQuery) + when(useWifiQuery) .calledWith(expect.anything(), null) - .mockReturnValue(({ + .thenReturn(({ data: { list: [mockWifiNetwork] }, } as unknown) as UseQueryResult) const wifiList = useWifiList() expect(wifiList).toEqual([mockWifiNetwork]) }) it('getWifiList dedupes duplicate SSIDs', () => { - when(mockUseWifiQuery) + when(useWifiQuery) .calledWith(expect.anything(), null) - .mockReturnValue(({ + .thenReturn(({ data: { list: [mockWifiNetwork, mockWifiNetwork] }, } as unknown) as UseQueryResult) const wifiList = useWifiList() expect(wifiList).toEqual([mockWifiNetwork]) }) it('getWifiList sorts by active then ssid', () => { - when(mockUseWifiQuery) + when(useWifiQuery) .calledWith(expect.anything(), null) - .mockReturnValue(({ + .thenReturn(({ data: { list: [ { ...mockWifiNetwork, ssid: 'bbb' }, @@ -75,9 +70,9 @@ describe('useWifiList', () => { ]) }) it('getWifiList sorts by active then ssid then dedupes', () => { - when(mockUseWifiQuery) + when(useWifiQuery) .calledWith(expect.anything(), null) - .mockReturnValue(({ + .thenReturn(({ data: { list: [ { ...mockWifiNetwork, ssid: 'bbb' }, diff --git a/app/src/resources/runs/__tests__/util.test.ts b/app/src/resources/runs/__tests__/util.test.ts index 14afde92a49..2c86d41ffda 100644 --- a/app/src/resources/runs/__tests__/util.test.ts +++ b/app/src/resources/runs/__tests__/util.test.ts @@ -1,3 +1,4 @@ +import { describe, it, expect } from 'vitest' import { formatTimeWithUtcLabel } from '../utils' describe('formatTimeWithUtc', () => { diff --git a/shared-data/command/index.ts b/shared-data/command/index.ts index 738d0e332a1..4f7c3c0ba85 100644 --- a/shared-data/command/index.ts +++ b/shared-data/command/index.ts @@ -1,7 +1,5 @@ import commandSchemaV7 from './schemas/7.json' import commandSchemaV8 from './schemas/8.json' +export * from './types/index' -export { - commandSchemaV7, - commandSchemaV8 -} \ No newline at end of file +export { commandSchemaV7, commandSchemaV8 } diff --git a/shared-data/js/index.ts b/shared-data/js/index.ts index c135b8367cc..740b49ed13e 100644 --- a/shared-data/js/index.ts +++ b/shared-data/js/index.ts @@ -1,17 +1,18 @@ +export * from '../command' +export * from '../deck' +export * from '../protocol' export * from './constants' export * from './deck' -export * from './labware' +export * from './errors' +export * from './fixtures' +export * from './fixtures' export * from './getLabware' +export * from './gripper' export * from './helpers' -export * from './pipettes' -export * from './types' +export * from './labware' export * from './labwareTools' export * from './modules' -export * from './fixtures' -export * from './gripper' -export * from '../protocol' -export * from '../command' -export * from '../deck' +export * from './pipettes' +export * from './protocols' export * from './titleCase' -export * from './errors' -export * from './fixtures' +export * from './types' \ No newline at end of file diff --git a/shared-data/js/labware.ts b/shared-data/js/labware.ts index f070dd4fa5f..36fff022492 100644 --- a/shared-data/js/labware.ts +++ b/shared-data/js/labware.ts @@ -555,6 +555,7 @@ export { fixtureTiprack300ul, fixtureTiprack1000ul, fixtureTiprackAdapter, + opentrons96PcrAdapterV1, opentrons1Trash3200MlFixedV1, } diff --git a/shared-data/js/protocols.ts b/shared-data/js/protocols.ts index fc9f1f0a5d8..78b3690dbeb 100644 --- a/shared-data/js/protocols.ts +++ b/shared-data/js/protocols.ts @@ -17,7 +17,6 @@ import protocolSchema5 from '../protocol/schemas/5.json' import protocolSchema4 from '../protocol/schemas/4.json' import protocolSchema3 from '../protocol/schemas/3.json' import protocolSchema1 from '../protocol/schemas/1.json' - import type * as ProtocolSchemas from '../protocol' import type { CreateCommand } from '../command/types' import type { CommandAnnotation } from '../commandAnnotation/types' @@ -288,3 +287,5 @@ export function validate( }) } } + +export * from '../protocol/fixtures/index' diff --git a/shared-data/protocol/fixtures/index.ts b/shared-data/protocol/fixtures/index.ts new file mode 100644 index 00000000000..c7af923267c --- /dev/null +++ b/shared-data/protocol/fixtures/index.ts @@ -0,0 +1 @@ +export * from './6/index'