From 6fcf0de91fc2f4d769a301c05c4999d84a242796 Mon Sep 17 00:00:00 2001 From: Jamey Huffnagle Date: Tue, 27 Feb 2024 09:30:07 -0500 Subject: [PATCH] C* components test updates --- .../__tests__/CalibrateDeck.test.tsx | 27 ++- .../__tests__/CalibratePipetteOffset.test.tsx | 31 ++- .../useCalibratePipetteOffset.test.tsx | 2 + .../AskForCalibrationBlockModal.test.tsx | 12 +- .../__tests__/CalibrateTipLength.test.tsx | 31 +-- .../Introduction/__tests__/Body.test.tsx | 3 +- .../__tests__/Introduction.test.tsx | 18 +- .../__tests__/InvalidationWarning.test.tsx | 4 +- .../__tests__/ChooseTipRack.test.tsx | 52 ++--- .../__tests__/ChosenTipRackRender.test.tsx | 8 +- .../__tests__/CompleteConfirmation.test.tsx | 10 +- .../__tests__/ConfirmCrashRecovery.test.tsx | 11 +- .../__tests__/ConfirmExit.test.tsx | 12 +- .../__tests__/DeckSetup.test.tsx | 35 ++-- .../__tests__/MeasureNozzle.test.tsx | 13 +- .../__tests__/MeasureTip.test.tsx | 12 +- .../__tests__/SaveXYPoint.test.tsx | 12 +- .../__tests__/SaveZPoint.test.tsx | 12 +- .../__tests__/TipConfirmation.test.tsx | 13 +- .../__tests__/TipPickUp.test.tsx | 13 +- .../useConfirmCrashRecovery.test.tsx | 13 +- .../__tests__/CalibrationStatusCard.test.tsx | 40 ++-- .../__tests__/CalibrationTaskList.test.tsx | 153 +++++++------- .../ChangePipette/InstructionStep.tsx | 18 +- .../organisms/ChangePipette/LevelPipette.tsx | 9 +- .../__tests__/ChangePipette.test.tsx | 129 +++++------- .../__tests__/CheckPipettesButton.test.tsx | 37 ++-- .../__tests__/ClearDeckModal.test.tsx | 6 +- .../__tests__/ConfirmPipette.test.tsx | 142 +++++++------ .../__tests__/ExitModal.test.tsx | 8 +- .../__tests__/InstructionStep.test.tsx | 5 +- .../__tests__/Instructions.test.tsx | 88 ++++---- .../__tests__/LevelPipette.test.tsx | 10 +- .../__tests__/PipetteSelection.test.tsx | 13 +- .../CalibrationHealthCheckResults.test.tsx | 6 +- .../__tests__/CalibrationResult.test.tsx | 12 +- .../__tests__/RenderMountInformation.test.tsx | 27 ++- .../__tests__/RenderResult.test.tsx | 6 +- .../__tests__/ResultsSummary.test.tsx | 45 ++-- .../__tests__/CheckCalibration.test.tsx | 23 +- .../__tests__/ReturnTip.test.tsx | 2 + .../__tests__/ChildNavigation.test.tsx | 9 +- .../__tests__/ChooseProtocolSlideout.test.tsx | 63 +++--- .../__tests__/ChooseRobotSlideout.test.tsx | 75 +++---- .../ChooseRobotToRunProtocolSlideout.test.tsx | 198 +++++++----------- .../__tests__/CommandText.test.tsx | 5 +- .../__tests__/ConfigFormResetButton.test.tsx | 11 +- .../__tests__/ConfigFormSubmitButton.test.tsx | 7 +- .../__tests__/ConfigurePipette.test.tsx | 38 ++-- .../__fixtures__/tip-length-calibration.ts | 13 +- app/src/redux/shell/__tests__/epics.test.ts | 4 +- 51 files changed, 710 insertions(+), 836 deletions(-) diff --git a/app/src/organisms/CalibrateDeck/__tests__/CalibrateDeck.test.tsx b/app/src/organisms/CalibrateDeck/__tests__/CalibrateDeck.test.tsx index 44a2ff95db1..797cd700c7f 100644 --- a/app/src/organisms/CalibrateDeck/__tests__/CalibrateDeck.test.tsx +++ b/app/src/organisms/CalibrateDeck/__tests__/CalibrateDeck.test.tsx @@ -1,32 +1,34 @@ import * as React from 'react' -import * as Vitest from 'vitest' -import { when, resetAllWhenMocks } from 'jest-when' +import { vi, describe, beforeEach, expect, it } from 'vitest' import { fireEvent, screen } from '@testing-library/react' -import { renderWithProviders } from '@opentrons/components' +import { renderWithProviders } from '../../../__testing-utils__' +import { getDeckDefinitions } from '@opentrons/shared-data' import { i18n } from '../../../i18n' import * as Sessions from '../../../redux/sessions' import { mockDeckCalibrationSessionAttributes } from '../../../redux/sessions/__fixtures__' -import { getDeckDefinitions } from '@opentrons/shared-data' - import { CalibrateDeck } from '../index' + import type { DeckCalibrationStep } from '../../../redux/sessions/types' import type { DispatchRequestsType } from '../../../redux/robot-api' vi.mock('../../../redux/sessions/selectors') vi.mock('../../../redux/robot-api/selectors') vi.mock('../../../redux/config') +vi.mock('@opentrons/shared-data', async importOriginal => { + const actual = await importOriginal() + return { + ...actual, + getDeckDefinitions: vi.fn(), + } +}) interface CalibrateDeckSpec { heading: string currentStep: DeckCalibrationStep } -const mockGetDeckDefinitions = getDeckDefinitions as Vitest.MockedFunction< - typeof getDeckDefinitions -> - describe('CalibrateDeck', () => { let dispatchRequests: DispatchRequestsType const mockDeckCalSession: Sessions.DeckCalibrationSession = { @@ -81,11 +83,8 @@ describe('CalibrateDeck', () => { ] beforeEach(() => { - dispatchRequests = jest.fn() - when(mockGetDeckDefinitions).calledWith().mockReturnValue({}) - }) - afterEach(() => { - resetAllWhenMocks() + dispatchRequests = vi.fn() + vi.mocked(getDeckDefinitions).mockReturnValue({}) }) SPECS.forEach(spec => { diff --git a/app/src/organisms/CalibratePipetteOffset/__tests__/CalibratePipetteOffset.test.tsx b/app/src/organisms/CalibratePipetteOffset/__tests__/CalibratePipetteOffset.test.tsx index 8882e2e9a9a..febbda5ded4 100644 --- a/app/src/organisms/CalibratePipetteOffset/__tests__/CalibratePipetteOffset.test.tsx +++ b/app/src/organisms/CalibratePipetteOffset/__tests__/CalibratePipetteOffset.test.tsx @@ -1,7 +1,8 @@ import * as React from 'react' -import { when, resetAllWhenMocks } from 'jest-when' +import { vi, it, describe, expect, beforeEach } from 'vitest' +import { when } from 'vitest-when' -import { renderWithProviders } from '@opentrons/components' +import { renderWithProviders } from '../../../__testing-utils__' import { getDeckDefinitions } from '@opentrons/shared-data' import { i18n } from '../../../i18n' @@ -13,20 +14,22 @@ import type { PipetteOffsetCalibrationStep } from '../../../redux/sessions/types import { DispatchRequestsType } from '../../../redux/robot-api' import { fireEvent, screen } from '@testing-library/react' -jest.mock('@opentrons/shared-data') -jest.mock('../../../redux/sessions/selectors') -jest.mock('../../../redux/robot-api/selectors') -jest.mock('../../../redux/config') +vi.mock('@opentrons/shared-data', async importOriginal => { + const actual = await importOriginal() + return { + ...actual, + getDeckDefinitions: vi.fn(), + } +}) +vi.mock('../../../redux/sessions/selectors') +vi.mock('../../../redux/robot-api/selectors') +vi.mock('../../../redux/config') interface CalibratePipetteOffsetSpec { heading: string currentStep: PipetteOffsetCalibrationStep } -const mockGetDeckDefinitions = getDeckDefinitions as jest.MockedFunction< - typeof getDeckDefinitions -> - describe('CalibratePipetteOffset', () => { let dispatchRequests: DispatchRequestsType const render = ( @@ -71,8 +74,8 @@ describe('CalibratePipetteOffset', () => { ] beforeEach(() => { - dispatchRequests = jest.fn() - when(mockGetDeckDefinitions).calledWith().mockReturnValue({}) + dispatchRequests = vi.fn() + when(vi.mocked(getDeckDefinitions)).calledWith().thenReturn({}) mockPipOffsetCalSession = { id: 'fake_session_id', @@ -80,10 +83,6 @@ describe('CalibratePipetteOffset', () => { } }) - afterEach(() => { - resetAllWhenMocks() - }) - SPECS.forEach(spec => { it(`renders correct contents when currentStep is ${spec.currentStep}`, () => { render({ diff --git a/app/src/organisms/CalibratePipetteOffset/__tests__/useCalibratePipetteOffset.test.tsx b/app/src/organisms/CalibratePipetteOffset/__tests__/useCalibratePipetteOffset.test.tsx index c1d3e27d20a..2e72432f835 100644 --- a/app/src/organisms/CalibratePipetteOffset/__tests__/useCalibratePipetteOffset.test.tsx +++ b/app/src/organisms/CalibratePipetteOffset/__tests__/useCalibratePipetteOffset.test.tsx @@ -1,3 +1,5 @@ +import { it, describe } from 'vitest' + describe('useCalibratePipetteOffset hook', () => { it.todo('replace deprecated enzyme test') }) diff --git a/app/src/organisms/CalibrateTipLength/__tests__/AskForCalibrationBlockModal.test.tsx b/app/src/organisms/CalibrateTipLength/__tests__/AskForCalibrationBlockModal.test.tsx index 2a5197c3c09..7d1b87f1fcb 100644 --- a/app/src/organisms/CalibrateTipLength/__tests__/AskForCalibrationBlockModal.test.tsx +++ b/app/src/organisms/CalibrateTipLength/__tests__/AskForCalibrationBlockModal.test.tsx @@ -1,5 +1,7 @@ import * as React from 'react' -import { renderWithProviders } from '@opentrons/components' +import { vi, it, describe, expect } from 'vitest' + +import { renderWithProviders } from '../../../__testing-utils__' import { i18n } from '../../../i18n' import { setUseTrashSurfaceForTipCal } from '../../../redux/calibration' @@ -7,7 +9,7 @@ import { AskForCalibrationBlockModal } from '../AskForCalibrationBlockModal' import { fireEvent, screen } from '@testing-library/react' describe('AskForCalibrationBlockModal', () => { - const onResponse = jest.fn() + const onResponse = vi.fn() const render = () => { return renderWithProviders< React.ComponentProps @@ -15,16 +17,12 @@ describe('AskForCalibrationBlockModal', () => { , { i18nInstance: i18n } ) } - afterEach(() => { - jest.resetAllMocks() - }) - it('saves preference when not checked and use trash is clicked', () => { const { dispatch } = render()[1] const checkbox = screen.getByRole('checkbox') diff --git a/app/src/organisms/CalibrateTipLength/__tests__/CalibrateTipLength.test.tsx b/app/src/organisms/CalibrateTipLength/__tests__/CalibrateTipLength.test.tsx index e5e58cde0d3..90ce34d4809 100644 --- a/app/src/organisms/CalibrateTipLength/__tests__/CalibrateTipLength.test.tsx +++ b/app/src/organisms/CalibrateTipLength/__tests__/CalibrateTipLength.test.tsx @@ -1,7 +1,8 @@ import * as React from 'react' -import { when, resetAllWhenMocks } from 'jest-when' +import { vi, it, describe, expect, beforeEach, afterEach } from 'vitest' +import { when } from 'vitest-when' -import { renderWithProviders } from '@opentrons/components' +import { renderWithProviders } from '../../../__testing-utils__' import { getDeckDefinitions } from '@opentrons/shared-data' import { i18n } from '../../../i18n' @@ -12,22 +13,24 @@ import { CalibrateTipLength } from '../index' import type { TipLengthCalibrationStep } from '../../../redux/sessions/types' import { fireEvent, screen } from '@testing-library/react' -jest.mock('@opentrons/shared-data') -jest.mock('../../../redux/sessions/selectors') -jest.mock('../../../redux/robot-api/selectors') -jest.mock('../../../redux/config') +vi.mock('@opentrons/shared-data', async importOriginal => { + const actual = await importOriginal() + return { + ...actual, + getDeckDefinitions: vi.fn(), + } +}) +vi.mock('../../../redux/sessions/selectors') +vi.mock('../../../redux/robot-api/selectors') +vi.mock('../../../redux/config') interface CalibrateTipLengthSpec { heading: string currentStep: TipLengthCalibrationStep } -const mockGetDeckDefinitions = getDeckDefinitions as jest.MockedFunction< - typeof getDeckDefinitions -> - describe('CalibrateTipLength', () => { - const dispatchRequests = jest.fn() + const dispatchRequests = vi.fn() const mockTipLengthSession: Sessions.TipLengthCalibrationSession = { id: 'fake_session_id', ...mockTipLengthCalibrationSessionAttributes, @@ -72,12 +75,10 @@ describe('CalibrateTipLength', () => { ] beforeEach(() => { - when(mockGetDeckDefinitions).calledWith().mockReturnValue({}) + when(vi.mocked(getDeckDefinitions)).calledWith().thenReturn({}) }) - afterEach(() => { - resetAllWhenMocks() - jest.resetAllMocks() + vi.resetAllMocks() }) SPECS.forEach(spec => { diff --git a/app/src/organisms/CalibrationPanels/Introduction/__tests__/Body.test.tsx b/app/src/organisms/CalibrationPanels/Introduction/__tests__/Body.test.tsx index c1151bf5cf9..a1324eef28b 100644 --- a/app/src/organisms/CalibrationPanels/Introduction/__tests__/Body.test.tsx +++ b/app/src/organisms/CalibrationPanels/Introduction/__tests__/Body.test.tsx @@ -1,6 +1,7 @@ import * as React from 'react' +import { it, describe } from 'vitest' -import { renderWithProviders } from '@opentrons/components' +import { renderWithProviders } from '../../../../__testing-utils__' import * as Sessions from '../../../../redux/sessions' import { i18n } from '../../../../i18n' diff --git a/app/src/organisms/CalibrationPanels/Introduction/__tests__/Introduction.test.tsx b/app/src/organisms/CalibrationPanels/Introduction/__tests__/Introduction.test.tsx index 9043aaea665..408d4602466 100644 --- a/app/src/organisms/CalibrationPanels/Introduction/__tests__/Introduction.test.tsx +++ b/app/src/organisms/CalibrationPanels/Introduction/__tests__/Introduction.test.tsx @@ -1,23 +1,21 @@ import * as React from 'react' +import { vi, it, expect, describe, beforeEach, afterEach } from 'vitest' import { fireEvent, screen } from '@testing-library/react' -import { renderWithProviders } from '@opentrons/components' +import { renderWithProviders } from '../../../../__testing-utils__' import { mockCalibrationCheckLabware } from '../../../../redux/sessions/__fixtures__' import * as Sessions from '../../../../redux/sessions' import { i18n } from '../../../../i18n' import { Introduction } from '../' import { ChooseTipRack } from '../../ChooseTipRack' -jest.mock('../../ChooseTipRack') +vi.mock('../../ChooseTipRack') -const mockChooseTipRack = ChooseTipRack as jest.MockedFunction< - typeof ChooseTipRack -> -const mockCalInvalidationHandler = jest.fn() +const mockCalInvalidationHandler = vi.fn() describe('Introduction', () => { - const mockSendCommands = jest.fn() - const mockCleanUpAndExit = jest.fn() + const mockSendCommands = vi.fn() + const mockCleanUpAndExit = vi.fn() const render = ( props: Partial> = {} @@ -39,11 +37,11 @@ describe('Introduction', () => { ) } beforeEach(() => { - mockChooseTipRack.mockReturnValue(
mock choose tip rack
) + vi.mocked(ChooseTipRack).mockReturnValue(
mock choose tip rack
) }) afterEach(() => { - jest.resetAllMocks() + vi.resetAllMocks() }) it('renders correct text', () => { diff --git a/app/src/organisms/CalibrationPanels/Introduction/__tests__/InvalidationWarning.test.tsx b/app/src/organisms/CalibrationPanels/Introduction/__tests__/InvalidationWarning.test.tsx index 688d9cfacf4..b99c7b1d29a 100644 --- a/app/src/organisms/CalibrationPanels/Introduction/__tests__/InvalidationWarning.test.tsx +++ b/app/src/organisms/CalibrationPanels/Introduction/__tests__/InvalidationWarning.test.tsx @@ -1,7 +1,7 @@ import * as React from 'react' +import { it, describe } from 'vitest' -import { renderWithProviders } from '@opentrons/components' - +import { renderWithProviders } from '../../../../__testing-utils__' import { i18n } from '../../../../i18n' import { InvalidationWarning } from '../InvalidationWarning' diff --git a/app/src/organisms/CalibrationPanels/__tests__/ChooseTipRack.test.tsx b/app/src/organisms/CalibrationPanels/__tests__/ChooseTipRack.test.tsx index 85ad160253e..fba0c237890 100644 --- a/app/src/organisms/CalibrationPanels/__tests__/ChooseTipRack.test.tsx +++ b/app/src/organisms/CalibrationPanels/__tests__/ChooseTipRack.test.tsx @@ -1,8 +1,11 @@ import * as React from 'react' import { fireEvent } from '@testing-library/react' -import { renderWithProviders } from '@opentrons/components' +import { vi, it, describe, expect, beforeEach } from 'vitest' + import { usePipettesQuery } from '@opentrons/react-api-client' import { LEFT } from '@opentrons/shared-data' + +import { renderWithProviders } from '../../../__testing-utils__' import { i18n } from '../../../i18n' import { mockAttachedPipette } from '../../../redux/pipettes/__fixtures__' import { mockDeckCalTipRack } from '../../../redux/sessions/__fixtures__' @@ -18,34 +21,17 @@ import { ChooseTipRack } from '../ChooseTipRack' import type { AttachedPipettesByMount } from '../../../redux/pipettes/types' -jest.mock('@opentrons/react-api-client') -jest.mock('../../../redux/pipettes/selectors') -jest.mock('../../../redux/calibration/') -jest.mock('../../../redux/custom-labware/selectors') -jest.mock('../../../atoms/SelectField/Select') +vi.mock('@opentrons/react-api-client') +vi.mock('../../../redux/pipettes/selectors') +vi.mock('../../../redux/calibration') +vi.mock('../../../redux/custom-labware/selectors') +vi.mock('../../../atoms/SelectField/Select') const mockAttachedPipettes: AttachedPipettesByMount = { left: mockAttachedPipette, right: null, } as any -const mockGetCalibrationForPipette = getCalibrationForPipette as jest.MockedFunction< - typeof getCalibrationForPipette -> -const mockGetTipLengthForPipetteAndTiprack = getTipLengthForPipetteAndTiprack as jest.MockedFunction< - typeof getTipLengthForPipetteAndTiprack -> -const mockGetTipLengthCalibrations = getTipLengthCalibrations as jest.MockedFunction< - typeof getTipLengthCalibrations -> -const mockUsePipettesQuery = usePipettesQuery as jest.MockedFunction< - typeof usePipettesQuery -> -const mockGetCustomTipRackDefinitions = getCustomTipRackDefinitions as jest.MockedFunction< - typeof getCustomTipRackDefinitions -> -const mockSelect = Select as jest.MockedFunction - const render = (props: React.ComponentProps) => { return renderWithProviders(, { i18nInstance: i18n, @@ -56,14 +42,14 @@ describe('ChooseTipRack', () => { let props: React.ComponentProps beforeEach(() => { - mockSelect.mockReturnValue(
mock select
) - mockGetCalibrationForPipette.mockReturnValue(null) - mockGetTipLengthForPipetteAndTiprack.mockReturnValue(null) - mockGetTipLengthCalibrations.mockReturnValue([]) - mockUsePipettesQuery.mockReturnValue({ + vi.mocked(Select).mockReturnValue(
mock select
) + vi.mocked(getCalibrationForPipette).mockReturnValue(null) + vi.mocked(getTipLengthForPipetteAndTiprack).mockReturnValue(null) + vi.mocked(getTipLengthCalibrations).mockReturnValue([]) + vi.mocked(usePipettesQuery).mockReturnValue({ data: mockAttachedPipettes, } as any) - mockGetCustomTipRackDefinitions.mockReturnValue([ + vi.mocked(getCustomTipRackDefinitions).mockReturnValue([ mockTipRackDefinition, mockDeckCalTipRack.definition, ]) @@ -71,16 +57,12 @@ describe('ChooseTipRack', () => { tipRack: mockDeckCalTipRack, mount: LEFT, chosenTipRack: null, - handleChosenTipRack: jest.fn(), - closeModal: jest.fn(), + handleChosenTipRack: vi.fn(), + closeModal: vi.fn(), robotName: 'otie', } }) - afterEach(() => { - jest.resetAllMocks() - }) - it('renders the correct text', () => { const { getByText, getByAltText } = render(props) getByText('Choose a tip rack') diff --git a/app/src/organisms/CalibrationPanels/__tests__/ChosenTipRackRender.test.tsx b/app/src/organisms/CalibrationPanels/__tests__/ChosenTipRackRender.test.tsx index 802eefa8955..1ec4717b6fb 100644 --- a/app/src/organisms/CalibrationPanels/__tests__/ChosenTipRackRender.test.tsx +++ b/app/src/organisms/CalibrationPanels/__tests__/ChosenTipRackRender.test.tsx @@ -1,6 +1,8 @@ import * as React from 'react' +import { it, describe, beforeEach } from 'vitest' + import { i18n } from '../../../i18n' -import { renderWithProviders } from '@opentrons/components' +import { renderWithProviders } from '../../../__testing-utils__' import { ChosenTipRackRender } from '../ChosenTipRackRender' import type { SelectOption } from '../../../atoms/SelectField/Select' @@ -23,10 +25,6 @@ describe('ChosenTipRackRender', () => { } }) - afterEach(() => { - jest.resetAllMocks() - }) - it('renders text and image alt text when tip rack is Opentrons 96 1000uL', () => { const { getByText, getByAltText } = render(props) getByText('Opentrons 96 tip rack 1000ul') diff --git a/app/src/organisms/CalibrationPanels/__tests__/CompleteConfirmation.test.tsx b/app/src/organisms/CalibrationPanels/__tests__/CompleteConfirmation.test.tsx index 4f1258d40a5..29b757b8d88 100644 --- a/app/src/organisms/CalibrationPanels/__tests__/CompleteConfirmation.test.tsx +++ b/app/src/organisms/CalibrationPanels/__tests__/CompleteConfirmation.test.tsx @@ -1,12 +1,14 @@ import * as React from 'react' import { fireEvent, screen } from '@testing-library/react' -import { renderWithProviders } from '@opentrons/components' +import { vi, it, describe, expect } from 'vitest' + +import { renderWithProviders } from '../../../__testing-utils__' import { i18n } from '../../../i18n' import { CompleteConfirmation } from '../CompleteConfirmation' describe('CompleteConfirmation', () => { - const mockCleanUpAndExit = jest.fn() + const mockCleanUpAndExit = vi.fn() const render = ( props: Partial> = {} ) => { @@ -22,10 +24,6 @@ describe('CompleteConfirmation', () => { ) } - afterEach(() => { - jest.resetAllMocks() - }) - it('clicking continue sends exit command and deletes session', () => { render() const button = screen.getByRole('button', { name: 'exit' }) diff --git a/app/src/organisms/CalibrationPanels/__tests__/ConfirmCrashRecovery.test.tsx b/app/src/organisms/CalibrationPanels/__tests__/ConfirmCrashRecovery.test.tsx index 0ea1ecd69c7..8f56a66a7c5 100644 --- a/app/src/organisms/CalibrationPanels/__tests__/ConfirmCrashRecovery.test.tsx +++ b/app/src/organisms/CalibrationPanels/__tests__/ConfirmCrashRecovery.test.tsx @@ -1,13 +1,14 @@ import * as React from 'react' import { fireEvent, screen } from '@testing-library/react' -import { renderWithProviders } from '@opentrons/components' +import { vi, it, describe, expect } from 'vitest' +import { renderWithProviders } from '../../../__testing-utils__' import { i18n } from '../../../i18n' import { ConfirmCrashRecovery } from '../ConfirmCrashRecovery' describe('ConfirmCrashRecovery', () => { - const mockBack = jest.fn() - const mockConfirm = jest.fn() + const mockBack = vi.fn() + const mockConfirm = vi.fn() const render = ( props: Partial> = {} ) => { @@ -18,10 +19,6 @@ describe('ConfirmCrashRecovery', () => { ) } - afterEach(() => { - jest.resetAllMocks() - }) - it('clicking resume goes back', () => { render() const button = screen.getByRole('button', { name: 'resume' }) diff --git a/app/src/organisms/CalibrationPanels/__tests__/ConfirmExit.test.tsx b/app/src/organisms/CalibrationPanels/__tests__/ConfirmExit.test.tsx index 9350ae7415e..b28c224329a 100644 --- a/app/src/organisms/CalibrationPanels/__tests__/ConfirmExit.test.tsx +++ b/app/src/organisms/CalibrationPanels/__tests__/ConfirmExit.test.tsx @@ -1,13 +1,15 @@ import * as React from 'react' import { fireEvent, screen } from '@testing-library/react' -import { renderWithProviders } from '@opentrons/components' +import { vi, it, describe, expect } from 'vitest' + +import { renderWithProviders } from '../../../__testing-utils__' import { i18n } from '../../../i18n' import { ConfirmExit } from '../ConfirmExit' describe('ConfirmExit', () => { - const mockBack = jest.fn() - const mockExit = jest.fn() + const mockBack = vi.fn() + const mockExit = vi.fn() const render = ( props: Partial> = {} ) => { @@ -23,10 +25,6 @@ describe('ConfirmExit', () => { ) } - afterEach(() => { - jest.resetAllMocks() - }) - it('clicking confirm exit calls exit', () => { render() const button = screen.getByRole('button', { name: 'exit' }) diff --git a/app/src/organisms/CalibrationPanels/__tests__/DeckSetup.test.tsx b/app/src/organisms/CalibrationPanels/__tests__/DeckSetup.test.tsx index ae51f644e1a..3e8317e0473 100644 --- a/app/src/organisms/CalibrationPanels/__tests__/DeckSetup.test.tsx +++ b/app/src/organisms/CalibrationPanels/__tests__/DeckSetup.test.tsx @@ -1,7 +1,9 @@ import * as React from 'react' import { fireEvent, screen } from '@testing-library/react' -import { renderWithProviders } from '@opentrons/components' import { getDeckDefinitions } from '@opentrons/shared-data' +import { vi, it, describe, expect, beforeEach } from 'vitest' + +import { renderWithProviders } from '../../../__testing-utils__' import { i18n } from '../../../i18n' import { mockDeckCalTipRack, @@ -12,19 +14,22 @@ import * as Sessions from '../../../redux/sessions' import { DeckSetup } from '../DeckSetup' -jest.mock('../../../assets/labware/getLabware') -jest.mock('@opentrons/shared-data') -jest.mock('@opentrons/components/src/hardware-sim/Deck/RobotWorkSpace', () => ({ - RobotWorkSpace: () => <>, -})) - -const mockGetDeckDefinitions = getDeckDefinitions as jest.MockedFunction< - typeof getDeckDefinitions -> +vi.mock('../../../assets/labware/getLabware') +vi.mock('@opentrons/shared-data') +vi.mock( + '@opentrons/components/src/hardware-sim/Deck/RobotWorkSpace', + async importOriginal => { + const actual = (await importOriginal()) as any + return { + ...actual, + RobotWorkSpace: () => <>, + } + } +) describe('DeckSetup', () => { - const mockSendCommands = jest.fn() - const mockDeleteSession = jest.fn() + const mockSendCommands = vi.fn() + const mockDeleteSession = vi.fn() const render = ( props: Partial> = {} @@ -57,11 +62,7 @@ describe('DeckSetup', () => { } beforeEach(() => { - mockGetDeckDefinitions.mockReturnValue({}) - }) - - afterEach(() => { - jest.resetAllMocks() + vi.mocked(getDeckDefinitions).mockReturnValue({}) }) it('clicking continue proceeds to next step', () => { diff --git a/app/src/organisms/CalibrationPanels/__tests__/MeasureNozzle.test.tsx b/app/src/organisms/CalibrationPanels/__tests__/MeasureNozzle.test.tsx index c4e8a02643b..9bd2e580969 100644 --- a/app/src/organisms/CalibrationPanels/__tests__/MeasureNozzle.test.tsx +++ b/app/src/organisms/CalibrationPanels/__tests__/MeasureNozzle.test.tsx @@ -1,18 +1,19 @@ import * as React from 'react' import { fireEvent, screen } from '@testing-library/react' -import { renderWithProviders } from '@opentrons/components' +import { vi, it, describe, expect } from 'vitest' + +import { renderWithProviders } from '../../../__testing-utils__' import { i18n } from '../../../i18n' import { mockTipLengthCalBlock, mockTipLengthTipRack, } from '../../../redux/sessions/__fixtures__' import * as Sessions from '../../../redux/sessions' - import { MeasureNozzle } from '../MeasureNozzle' describe('MeasureNozzle', () => { - const mockSendCommands = jest.fn() - const mockDeleteSession = jest.fn() + const mockSendCommands = vi.fn() + const mockDeleteSession = vi.fn() const render = ( props: Partial> = {} ) => { @@ -41,10 +42,6 @@ describe('MeasureNozzle', () => { ) } - afterEach(() => { - jest.resetAllMocks() - }) - it('renders the confirm crash modal when invoked', () => { render() expect( diff --git a/app/src/organisms/CalibrationPanels/__tests__/MeasureTip.test.tsx b/app/src/organisms/CalibrationPanels/__tests__/MeasureTip.test.tsx index 1e1b9b2c857..60787ebdefd 100644 --- a/app/src/organisms/CalibrationPanels/__tests__/MeasureTip.test.tsx +++ b/app/src/organisms/CalibrationPanels/__tests__/MeasureTip.test.tsx @@ -1,6 +1,8 @@ import * as React from 'react' import { fireEvent, screen } from '@testing-library/react' -import { renderWithProviders } from '@opentrons/components' +import { vi, it, describe, expect } from 'vitest' + +import { renderWithProviders } from '../../../__testing-utils__' import { i18n } from '../../../i18n' import { mockTipLengthCalBlock, @@ -11,8 +13,8 @@ import * as Sessions from '../../../redux/sessions' import { MeasureTip } from '../MeasureTip' describe('MeasureTip', () => { - const mockSendCommands = jest.fn() - const mockDeleteSession = jest.fn() + const mockSendCommands = vi.fn() + const mockDeleteSession = vi.fn() const render = ( props: Partial> = {} ) => { @@ -41,10 +43,6 @@ describe('MeasureTip', () => { ) } - afterEach(() => { - jest.resetAllMocks() - }) - it('renders the confirm crash modal when invoked', () => { render() expect( diff --git a/app/src/organisms/CalibrationPanels/__tests__/SaveXYPoint.test.tsx b/app/src/organisms/CalibrationPanels/__tests__/SaveXYPoint.test.tsx index 7048b03c6ac..917c22b4c9e 100644 --- a/app/src/organisms/CalibrationPanels/__tests__/SaveXYPoint.test.tsx +++ b/app/src/organisms/CalibrationPanels/__tests__/SaveXYPoint.test.tsx @@ -1,6 +1,8 @@ import * as React from 'react' import { fireEvent, screen } from '@testing-library/react' -import { renderWithProviders } from '@opentrons/components' +import { vi, it, describe, expect } from 'vitest' + +import { renderWithProviders } from '../../../__testing-utils__' import { i18n } from '../../../i18n' import { mockDeckCalTipRack } from '../../../redux/sessions/__fixtures__' @@ -8,8 +10,8 @@ import * as Sessions from '../../../redux/sessions' import { SaveXYPoint } from '../SaveXYPoint' describe('SaveXYPoint', () => { - const mockSendCommands = jest.fn() - const mockDeleteSession = jest.fn() + const mockSendCommands = vi.fn() + const mockDeleteSession = vi.fn() const render = ( props: Partial> = {} ) => { @@ -36,10 +38,6 @@ describe('SaveXYPoint', () => { ) } - afterEach(() => { - jest.resetAllMocks() - }) - it('displays proper assets for slot 1 left multi', () => { render({ mount: 'left', diff --git a/app/src/organisms/CalibrationPanels/__tests__/SaveZPoint.test.tsx b/app/src/organisms/CalibrationPanels/__tests__/SaveZPoint.test.tsx index 67ea6a9be10..2dceb85d562 100644 --- a/app/src/organisms/CalibrationPanels/__tests__/SaveZPoint.test.tsx +++ b/app/src/organisms/CalibrationPanels/__tests__/SaveZPoint.test.tsx @@ -1,6 +1,8 @@ import * as React from 'react' import { fireEvent, screen } from '@testing-library/react' -import { renderWithProviders } from '@opentrons/components' +import { vi, it, describe, expect } from 'vitest' + +import { renderWithProviders } from '../../../__testing-utils__' import { i18n } from '../../../i18n' import { @@ -11,8 +13,8 @@ import * as Sessions from '../../../redux/sessions' import { SaveZPoint } from '../SaveZPoint' describe('SaveZPoint', () => { - const mockSendCommands = jest.fn() - const mockDeleteSession = jest.fn() + const mockSendCommands = vi.fn() + const mockDeleteSession = vi.fn() const render = ( props: Partial> = {} @@ -42,10 +44,6 @@ describe('SaveZPoint', () => { ) } - afterEach(() => { - jest.resetAllMocks() - }) - it('displays proper asset for left multi', () => { render({ mount: 'left', isMulti: true }) screen.getByLabelText('left multi channel pipette moving to slot 5') diff --git a/app/src/organisms/CalibrationPanels/__tests__/TipConfirmation.test.tsx b/app/src/organisms/CalibrationPanels/__tests__/TipConfirmation.test.tsx index 6a7c03f3037..d6d1fa5e438 100644 --- a/app/src/organisms/CalibrationPanels/__tests__/TipConfirmation.test.tsx +++ b/app/src/organisms/CalibrationPanels/__tests__/TipConfirmation.test.tsx @@ -1,15 +1,16 @@ import * as React from 'react' import { fireEvent, screen } from '@testing-library/react' -import { renderWithProviders } from '@opentrons/components' +import { vi, it, describe, expect } from 'vitest' + +import { renderWithProviders } from '../../../__testing-utils__' import { i18n } from '../../../i18n' import { mockDeckCalTipRack } from '../../../redux/sessions/__fixtures__' import * as Sessions from '../../../redux/sessions' - import { TipConfirmation } from '../TipConfirmation' describe('TipConfirmation', () => { - const mockSendCommands = jest.fn() - const mockDeleteSession = jest.fn() + const mockSendCommands = vi.fn() + const mockDeleteSession = vi.fn() const render = ( props: Partial> = {} ) => { @@ -36,10 +37,6 @@ describe('TipConfirmation', () => { ) } - afterEach(() => { - jest.resetAllMocks() - }) - it('renders correct heading', () => { render() screen.getByRole('heading', { diff --git a/app/src/organisms/CalibrationPanels/__tests__/TipPickUp.test.tsx b/app/src/organisms/CalibrationPanels/__tests__/TipPickUp.test.tsx index d9ed1ae694c..30406213d98 100644 --- a/app/src/organisms/CalibrationPanels/__tests__/TipPickUp.test.tsx +++ b/app/src/organisms/CalibrationPanels/__tests__/TipPickUp.test.tsx @@ -1,15 +1,16 @@ import * as React from 'react' import { fireEvent, screen } from '@testing-library/react' -import { renderWithProviders } from '@opentrons/components' +import { vi, it, describe, expect } from 'vitest' + +import { renderWithProviders } from '../../../__testing-utils__' import { i18n } from '../../../i18n' import { mockDeckCalTipRack } from '../../../redux/sessions/__fixtures__' import * as Sessions from '../../../redux/sessions' - import { TipPickUp } from '../TipPickUp' describe('TipPickUp', () => { - const mockSendCommands = jest.fn() - const mockDeleteSession = jest.fn() + const mockSendCommands = vi.fn() + const mockDeleteSession = vi.fn() const render = ( props: Partial> = {} ) => { @@ -36,10 +37,6 @@ describe('TipPickUp', () => { ) } - afterEach(() => { - jest.resetAllMocks() - }) - it('jogging sends command', () => { render() const button = screen.getByRole('button', { name: 'forward' }) diff --git a/app/src/organisms/CalibrationPanels/__tests__/useConfirmCrashRecovery.test.tsx b/app/src/organisms/CalibrationPanels/__tests__/useConfirmCrashRecovery.test.tsx index 63700d26d66..ca94bcb897e 100644 --- a/app/src/organisms/CalibrationPanels/__tests__/useConfirmCrashRecovery.test.tsx +++ b/app/src/organisms/CalibrationPanels/__tests__/useConfirmCrashRecovery.test.tsx @@ -1,8 +1,11 @@ import * as React from 'react' import { fireEvent, renderHook } from '@testing-library/react' import { I18nextProvider } from 'react-i18next' +import { vi, it, describe, expect } from 'vitest' + import { LEFT } from '@opentrons/shared-data' -import { renderWithProviders } from '@opentrons/components' + +import { renderWithProviders } from '../../../__testing-utils__' import { i18n } from '../../../i18n' import { useConfirmCrashRecovery } from '../useConfirmCrashRecovery' import { mockCalibrationCheckLabware } from '../../../redux/sessions/__fixtures__' @@ -13,9 +16,9 @@ import { } from '../../../redux/sessions' describe('useConfirmCrashRecovery', () => { - const mockSendCommands = jest.fn() + const mockSendCommands = vi.fn() const mockProps = { - cleanUpAndExit: jest.fn(), + cleanUpAndExit: vi.fn(), tipRack: mockCalibrationCheckLabware, isMulti: false, mount: LEFT, @@ -23,10 +26,6 @@ describe('useConfirmCrashRecovery', () => { sessionType: SESSION_TYPE_DECK_CALIBRATION, } - afterEach(() => { - jest.resetAllMocks() - }) - it('renders the link text', () => { const { result } = renderHook( () => diff --git a/app/src/organisms/CalibrationStatusCard/__tests__/CalibrationStatusCard.test.tsx b/app/src/organisms/CalibrationStatusCard/__tests__/CalibrationStatusCard.test.tsx index d89de5ae57c..b41e8b79599 100644 --- a/app/src/organisms/CalibrationStatusCard/__tests__/CalibrationStatusCard.test.tsx +++ b/app/src/organisms/CalibrationStatusCard/__tests__/CalibrationStatusCard.test.tsx @@ -1,10 +1,9 @@ import * as React from 'react' import { MemoryRouter } from 'react-router-dom' +import { vi, it, describe, expect, beforeEach } from 'vitest' import { fireEvent, screen } from '@testing-library/react' -import { resetAllWhenMocks } from 'jest-when' - -import { renderWithProviders } from '@opentrons/components' +import { renderWithProviders } from '../../../__testing-utils__' import { i18n } from '../../../i18n' import { CalibrationStatusCard } from '..' import { useCalibrationTaskList } from '../../Devices/hooks' @@ -19,11 +18,7 @@ import { expectedTaskList, } from '../../Devices/hooks/__fixtures__/taskListFixtures' -jest.mock('../../Devices/hooks') - -const mockUseCalibrationTaskList = useCalibrationTaskList as jest.MockedFunction< - typeof useCalibrationTaskList -> +vi.mock('../../Devices/hooks') const render = (props: React.ComponentProps) => { return renderWithProviders( @@ -36,16 +31,11 @@ const render = (props: React.ComponentProps) => { ) } -const mockSetShowHowCalibrationWorksModal = jest.fn() +const mockSetShowHowCalibrationWorksModal = vi.fn() describe('CalibrationStatusCard', () => { beforeEach(() => { - mockUseCalibrationTaskList.mockReturnValue(expectedTaskList) - }) - - afterEach(() => { - jest.resetAllMocks() - resetAllWhenMocks() + vi.mocked(useCalibrationTaskList).mockReturnValue(expectedTaskList) }) const props: React.ComponentProps = { @@ -67,7 +57,7 @@ describe('CalibrationStatusCard', () => { }) it('renders a missing status label', () => { - mockUseCalibrationTaskList.mockReturnValue( + vi.mocked(useCalibrationTaskList).mockReturnValue( expectedIncompleteDeckCalTaskList ) render(props) @@ -75,13 +65,13 @@ describe('CalibrationStatusCard', () => { }) it('renders a recommended status label when the deck is bad', () => { - mockUseCalibrationTaskList.mockReturnValue(expectedBadDeckTaskList) + vi.mocked(useCalibrationTaskList).mockReturnValue(expectedBadDeckTaskList) render(props) screen.getByText('Calibration recommended') }) it('renders a recommended status label when both the deck and offset is bad', () => { - mockUseCalibrationTaskList.mockReturnValue( + vi.mocked(useCalibrationTaskList).mockReturnValue( expectedBadDeckAndPipetteOffsetTaskList ) render(props) @@ -89,25 +79,31 @@ describe('CalibrationStatusCard', () => { }) it('renders a recommended status label when everything is bad', () => { - mockUseCalibrationTaskList.mockReturnValue(expectedBadEverythingTaskList) + vi.mocked(useCalibrationTaskList).mockReturnValue( + expectedBadEverythingTaskList + ) render(props) screen.getByText('Calibration recommended') }) it('renders a recommended status label when the offset is bad', () => { - mockUseCalibrationTaskList.mockReturnValue(expectedBadPipetteOffsetTaskList) + vi.mocked(useCalibrationTaskList).mockReturnValue( + expectedBadPipetteOffsetTaskList + ) render(props) screen.getByText('Calibration recommended') }) it('renders a recommended status label when the tip length is bad', () => { - mockUseCalibrationTaskList.mockReturnValue(expectedBadTipLengthTaskList) + vi.mocked(useCalibrationTaskList).mockReturnValue( + expectedBadTipLengthTaskList + ) render(props) screen.getByText('Calibration recommended') }) it('renders a recommended status label when both the tip length and offset is bad', () => { - mockUseCalibrationTaskList.mockReturnValue( + vi.mocked(useCalibrationTaskList).mockReturnValue( expectedBadTipLengthAndOffsetTaskList ) render(props) diff --git a/app/src/organisms/CalibrationTaskList/__tests__/CalibrationTaskList.test.tsx b/app/src/organisms/CalibrationTaskList/__tests__/CalibrationTaskList.test.tsx index 75aed8b1fc9..2211a27d689 100644 --- a/app/src/organisms/CalibrationTaskList/__tests__/CalibrationTaskList.test.tsx +++ b/app/src/organisms/CalibrationTaskList/__tests__/CalibrationTaskList.test.tsx @@ -1,6 +1,9 @@ import * as React from 'react' -import { renderWithProviders } from '@opentrons/components' import { StaticRouter } from 'react-router-dom' +import { vi, it, describe, expect, beforeEach, afterEach } from 'vitest' +import { fireEvent, screen } from '@testing-library/react' + +import { renderWithProviders } from '../../../__testing-utils__' import { i18n } from '../../../i18n' import { CalibrationTaskList } from '..' import { @@ -21,20 +24,9 @@ import { useAttachedPipettes, } from '../../Devices/hooks' import { mockLeftProtoPipette } from '../../../redux/pipettes/__fixtures__' -import { fireEvent } from '@testing-library/react' - -jest.mock('../../Devices/hooks') -jest.mock('../../ProtocolUpload/hooks') -const mockUseCalibrationTaskList = useCalibrationTaskList as jest.MockedFunction< - typeof useCalibrationTaskList -> -const mockUseRunHasStarted = useRunHasStarted as jest.MockedFunction< - typeof useRunHasStarted -> -const mockUseAttachedPipettes = useAttachedPipettes as jest.MockedFunction< - typeof useAttachedPipettes -> +vi.mock('../../Devices/hooks') +vi.mock('../../ProtocolUpload/hooks') const render = (robotName: string = 'otie') => { return renderWithProviders( @@ -55,22 +47,23 @@ const render = (robotName: string = 'otie') => { describe('CalibrationTaskList', () => { beforeEach(() => { - mockUseCalibrationTaskList.mockReturnValue(expectedTaskList) - mockUseRunHasStarted.mockReturnValue(false) - mockUseAttachedPipettes.mockReturnValue({ + vi.mocked(useCalibrationTaskList).mockReturnValue(expectedTaskList) + vi.mocked(useRunHasStarted).mockReturnValue(false) + vi.mocked(useAttachedPipettes).mockReturnValue({ left: mockLeftProtoPipette, right: null, }) }) afterEach(() => { - jest.resetAllMocks() + vi.resetAllMocks() }) + it('renders the Calibration Task List', () => { - const [{ getByText }] = render() - getByText('Deck Calibration') - getByText('Left Mount') - getByText('Right Mount') + render() + screen.getByText('Deck Calibration') + screen.getByText('Left Mount') + screen.getByText('Right Mount') }) it('does not show the Calibrations complete screen when viewing a completed task list', () => { @@ -81,13 +74,13 @@ describe('CalibrationTaskList', () => { it('shows the Calibrations complete screen after the calibrations are completed', () => { // initial render has incomplete calibrations, the rerender will use the completed calibrations mock response // this triggers the useEffect that causes the Calibrations complete screen to render - mockUseCalibrationTaskList.mockReturnValueOnce( + vi.mocked(useCalibrationTaskList).mockReturnValueOnce( expectedIncompleteDeckCalTaskList ) - const [{ getByText, rerender }] = render() - expect(getByText('Calibrate')).toBeTruthy() + const [{ rerender }] = render() + expect(screen.getByText('Calibrate')).toBeTruthy() // Complete screen will only render if a wizard has been launched - fireEvent.click(getByText('Calibrate')) + fireEvent.click(screen.getByText('Calibrate')) rerender( { /> ) - expect(getByText('Calibrations complete!')).toBeTruthy() + expect(screen.getByText('Calibrations complete!')).toBeTruthy() }) it('renders the Calibration Task List properly when both tip length and offset are bad', () => { - mockUseCalibrationTaskList.mockReturnValueOnce( + vi.mocked(useCalibrationTaskList).mockReturnValueOnce( expectedBadTipLengthAndOffsetTaskList ) - const [{ getAllByText, getByRole, getByText, rerender }] = render() - getByText('Deck Calibration') - expect(getByText('Recalibrate')).toBeTruthy() - getByText('Left Mount') - expect(getAllByText('Calibration recommended')).toHaveLength(3) - expect(getByRole('button', { name: 'Calibrate' })).toBeTruthy() - getByText('Right Mount') - fireEvent.click(getByText('Calibrate')) + const [{ rerender }] = render() + screen.getByText('Deck Calibration') + expect(screen.getByText('Recalibrate')).toBeTruthy() + screen.getByText('Left Mount') + expect(screen.getAllByText('Calibration recommended')).toHaveLength(3) + expect(screen.getByRole('button', { name: 'Calibrate' })).toBeTruthy() + screen.getByText('Right Mount') + fireEvent.click(screen.getByText('Calibrate')) rerender( { /> ) - expect(getByText('Calibrations complete!')).toBeTruthy() + expect(screen.getByText('Calibrations complete!')).toBeTruthy() }) it('renders the Calibration Task List properly when both deck and offset are bad', () => { - mockUseCalibrationTaskList.mockReturnValueOnce( + vi.mocked(useCalibrationTaskList).mockReturnValueOnce( expectedBadDeckAndPipetteOffsetTaskList ) - const [{ getAllByText, getByRole, getByText, rerender }] = render() - getByText('Deck Calibration') - expect(getAllByText('Calibration recommended')).toHaveLength(2) - expect(getByRole('button', { name: 'Calibrate' })).toBeTruthy() - getByText('Left Mount') - getByText('Right Mount') - fireEvent.click(getByText('Calibrate')) + const [{ rerender }] = render() + screen.getByText('Deck Calibration') + expect(screen.getAllByText('Calibration recommended')).toHaveLength(2) + expect(screen.getByRole('button', { name: 'Calibrate' })).toBeTruthy() + screen.getByText('Left Mount') + screen.getByText('Right Mount') + fireEvent.click(screen.getByText('Calibrate')) rerender( { /> ) - expect(getByText('Calibrations complete!')).toBeTruthy() + expect(screen.getByText('Calibrations complete!')).toBeTruthy() }) it('renders the Calibration Task List properly when everything is bad', () => { - mockUseCalibrationTaskList.mockReturnValueOnce( + vi.mocked(useCalibrationTaskList).mockReturnValueOnce( expectedBadEverythingTaskList ) - const [{ getAllByText, getByRole, getByText, rerender }] = render() - getByText('Deck Calibration') - expect(getAllByText('Calibration recommended')).toHaveLength(2) - expect(getByRole('button', { name: 'Calibrate' })).toBeTruthy() - getByText('Left Mount') - getByText('Right Mount') - fireEvent.click(getByText('Calibrate')) + const [{ rerender }] = render() + screen.getByText('Deck Calibration') + expect(screen.getAllByText('Calibration recommended')).toHaveLength(2) + expect(screen.getByRole('button', { name: 'Calibrate' })).toBeTruthy() + screen.getByText('Left Mount') + screen.getByText('Right Mount') + fireEvent.click(screen.getByText('Calibrate')) rerender( { /> ) - expect(getByText('Calibrations complete!')).toBeTruthy() + expect(screen.getByText('Calibrations complete!')).toBeTruthy() }) it('launching a recalibrate wizard from a subtask will allow the calibration complete screen to show', () => { - mockUseCalibrationTaskList.mockReturnValueOnce( + vi.mocked(useCalibrationTaskList).mockReturnValueOnce( expectedIncompleteRightMountTaskList ) - const [{ getAllByText, getByText, rerender }] = render() - fireEvent.click(getByText('Left Mount')) - const recalibrateLinks = getAllByText('Recalibrate') // this includes the deck and Left Mount subtasks CTAs + const [{ rerender }] = render() + fireEvent.click(screen.getByText('Left Mount')) + const recalibrateLinks = screen.getAllByText('Recalibrate') // this includes the deck and Left Mount subtasks CTAs expect(recalibrateLinks).toHaveLength(3) fireEvent.click(recalibrateLinks[2]) rerender( @@ -199,17 +192,17 @@ describe('CalibrationTaskList', () => { /> ) - expect(getByText('Calibrations complete!')).toBeTruthy() + expect(screen.getByText('Calibrations complete!')).toBeTruthy() }) it('launching a recalibrate wizard from a task will allow the calibration complete screen to show', () => { - mockUseCalibrationTaskList.mockReturnValueOnce( + vi.mocked(useCalibrationTaskList).mockReturnValueOnce( expectedIncompleteRightMountTaskList ) - const [{ getAllByText, getByText, rerender }] = render() - fireEvent.click(getByText('Left Mount')) - const recalibrateLinks = getAllByText('Recalibrate') + const [{ rerender }] = render() + fireEvent.click(screen.getByText('Left Mount')) + const recalibrateLinks = screen.getAllByText('Recalibrate') expect(recalibrateLinks).toHaveLength(3) fireEvent.click(recalibrateLinks[0]) rerender( @@ -223,16 +216,16 @@ describe('CalibrationTaskList', () => { /> ) - expect(getByText('Calibrations complete!')).toBeTruthy() + expect(screen.getByText('Calibrations complete!')).toBeTruthy() }) it('exiting a recalibrate wizard from a task will allow the current calibrations screen to show', () => { - mockUseCalibrationTaskList.mockReturnValueOnce( + vi.mocked(useCalibrationTaskList).mockReturnValueOnce( expectedIncompleteRightMountTaskList ) - const [{ getByText, rerender }] = render() - const recalibrateLink = getByText('Recalibrate') + const [{ rerender }] = render() + const recalibrateLink = screen.getByText('Recalibrate') fireEvent.click(recalibrateLink) rerender( @@ -245,17 +238,17 @@ describe('CalibrationTaskList', () => { /> ) - expect(getByText('Using current calibrations.')).toBeTruthy() + expect(screen.getByText('Using current calibrations.')).toBeTruthy() }) it('prevents the user from launching calibrations or recalibrations from a task when a protocol run is active', () => { - mockUseCalibrationTaskList.mockReturnValueOnce( + vi.mocked(useCalibrationTaskList).mockReturnValueOnce( expectedIncompleteDeckCalTaskList ) - mockUseRunHasStarted.mockReturnValue(true) + vi.mocked(useRunHasStarted).mockReturnValue(true) - const [{ getAllByText, rerender }] = render() - const calibrateButtons = getAllByText('Calibrate') + const [{ rerender }] = render() + const calibrateButtons = screen.getAllByText('Calibrate') expect(calibrateButtons).toHaveLength(1) // only deck's calibration button should be shown fireEvent.click(calibrateButtons[0]) expect(mockDeckCalLauncher).not.toHaveBeenCalled() @@ -270,20 +263,20 @@ describe('CalibrationTaskList', () => { /> ) - const recalibrateLinks = getAllByText('Recalibrate') + const recalibrateLinks = screen.getAllByText('Recalibrate') expect(recalibrateLinks).toHaveLength(1) // only deck's recalibration link should be shown fireEvent.click(recalibrateLinks[0]) expect(mockDeckCalLauncher).not.toHaveBeenCalled() }) it('prevents the user from launching calibrations or recalibrations from a subtask when a protocol run is active', () => { - mockUseCalibrationTaskList.mockReturnValueOnce( + vi.mocked(useCalibrationTaskList).mockReturnValueOnce( expectedIncompleteLeftMountTaskList ) - mockUseRunHasStarted.mockReturnValue(true) + vi.mocked(useRunHasStarted).mockReturnValue(true) - const [{ getAllByText, getByText, rerender }] = render() - const calibrateButtons = getAllByText('Calibrate') + const [{ rerender }] = render() + const calibrateButtons = screen.getAllByText('Calibrate') expect(calibrateButtons).toHaveLength(1) // only the left mounts tip length button should show fireEvent.click(calibrateButtons[0]) expect(mockTipLengthCalLauncher).not.toHaveBeenCalled() @@ -298,8 +291,8 @@ describe('CalibrationTaskList', () => { /> ) - fireEvent.click(getByText('Left Mount')) - const recalibrateLinks = getAllByText('Recalibrate') + fireEvent.click(screen.getByText('Left Mount')) + const recalibrateLinks = screen.getAllByText('Recalibrate') expect(recalibrateLinks).toHaveLength(3) // deck and left mounts links are showing fireEvent.click(recalibrateLinks[1]) expect(mockTipLengthCalLauncher).not.toHaveBeenCalled() diff --git a/app/src/organisms/ChangePipette/InstructionStep.tsx b/app/src/organisms/ChangePipette/InstructionStep.tsx index 0bd70000280..d70c6f9e69f 100644 --- a/app/src/organisms/ChangePipette/InstructionStep.tsx +++ b/app/src/organisms/ChangePipette/InstructionStep.tsx @@ -29,12 +29,18 @@ export function InstructionStep(props: Props): JSX.Element { const display = displayCategory === 'GEN2' - ? require(`../../assets/images/change-pip/${direction}-${String( - mount - )}-${channelsKey}-GEN2-${diagram}@3x.png`) - : require(`../../assets/images/change-pip/${direction}-${String( - mount - )}-${channelsKey}-${diagram}@3x.png`) + ? new URL( + `../../assets/images/change-pip/${direction}-${String( + mount + )}-${channelsKey}-GEN2-${diagram}@3x.png`, + import.meta.url + ).href + : new URL( + `../../assets/images/change-pip/${direction}-${String( + mount + )}-${channelsKey}-${diagram}@3x.png`, + import.meta.url + ).href return ( diff --git a/app/src/organisms/ChangePipette/LevelPipette.tsx b/app/src/organisms/ChangePipette/LevelPipette.tsx index ba74059339b..9ccc51ca80d 100644 --- a/app/src/organisms/ChangePipette/LevelPipette.tsx +++ b/app/src/organisms/ChangePipette/LevelPipette.tsx @@ -22,7 +22,7 @@ interface LevelPipetteProps { confirm: () => void } -function LevelingVideo(props: { +export function LevelingVideo(props: { pipetteName: string mount: Mount }): JSX.Element { @@ -40,7 +40,12 @@ function LevelingVideo(props: { controls={true} > ) diff --git a/app/src/organisms/ChangePipette/__tests__/ChangePipette.test.tsx b/app/src/organisms/ChangePipette/__tests__/ChangePipette.test.tsx index 94c9796188f..4e05137cfab 100644 --- a/app/src/organisms/ChangePipette/__tests__/ChangePipette.test.tsx +++ b/app/src/organisms/ChangePipette/__tests__/ChangePipette.test.tsx @@ -1,8 +1,11 @@ import * as React from 'react' +import { vi, it, describe, expect, beforeEach } from 'vitest' import { fireEvent } from '@testing-library/react' -import { when } from 'jest-when' -import { renderWithProviders } from '@opentrons/components' +import { useHistory } from 'react-router-dom' + import { getPipetteNameSpecs } from '@opentrons/shared-data' + +import { renderWithProviders } from '../../../__testing-utils__' import { i18n } from '../../../i18n' import { getHasCalibrationBlock } from '../../../redux/config' import { getMovementStatus } from '../../../redux/robot-controls' @@ -23,65 +26,33 @@ import type { PipetteNameSpecs } from '@opentrons/shared-data' import type { AttachedPipette } from '../../../redux/pipettes/types' import type { DispatchApiRequestType } from '../../../redux/robot-api' -const mockPush = jest.fn() +const mockPush = vi.fn() -jest.mock('react-router-dom', () => { - const reactRouterDom = jest.requireActual('react-router-dom') +vi.mock('react-router-dom', async importOriginal => { + const actual = await importOriginal() return { - ...reactRouterDom, - useHistory: () => ({ push: mockPush } as any), + ...actual, + useHistory: () => ({ push: mockPush }), } }) -jest.mock('@opentrons/shared-data', () => { - const actualSharedData = jest.requireActual('@opentrons/shared-data') +vi.mock('@opentrons/shared-data', async importOriginal => { + const actual = await importOriginal() return { - ...actualSharedData, - getPipetteNameSpecs: jest.fn(), + ...actual, + getPipetteNameSpecs: vi.fn(), } }) -jest.mock('../../../redux/config') -jest.mock('../../../redux/robot-controls') -jest.mock('../../../redux/calibration') -jest.mock('../../../redux/robot-api') -jest.mock('../PipetteSelection') -jest.mock('../ExitModal') -jest.mock('../../../molecules/InProgressModal/InProgressModal') -jest.mock('../ConfirmPipette') -jest.mock('../../Devices/hooks') - -const mockGetPipetteNameSpecs = getPipetteNameSpecs as jest.MockedFunction< - typeof getPipetteNameSpecs -> -const mockUseAttachedPipettes = useAttachedPipettes as jest.MockedFunction< - typeof useAttachedPipettes -> -const mockGetMovementStatus = getMovementStatus as jest.MockedFunction< - typeof getMovementStatus -> -const mockGetCalibrationForPipette = getCalibrationForPipette as jest.MockedFunction< - typeof getCalibrationForPipette -> -const mockGetHasCalibrationBlock = getHasCalibrationBlock as jest.MockedFunction< - typeof getHasCalibrationBlock -> -const mockGetRequestById = getRequestById as jest.MockedFunction< - typeof getRequestById -> -const mockUseDispatchApiRequests = useDispatchApiRequests as jest.MockedFunction< - typeof useDispatchApiRequests -> -const mockPipetteSelection = PipetteSelection as jest.MockedFunction< - typeof PipetteSelection -> -const mockInProgress = InProgressModal as jest.MockedFunction< - typeof InProgressModal -> -const mockConfirmPipette = ConfirmPipette as jest.MockedFunction< - typeof ConfirmPipette -> - -const mockExitModal = ExitModal as jest.MockedFunction +vi.mock('../../../redux/config') +vi.mock('../../../redux/robot-controls') +vi.mock('../../../redux/calibration') +vi.mock('../../../redux/robot-api') +vi.mock('../PipetteSelection') +vi.mock('../ExitModal') +vi.mock('../../../molecules/InProgressModal/InProgressModal') +vi.mock('../ConfirmPipette') +vi.mock('../../Devices/hooks') +vi.mock('../../../assets/images') const render = (props: React.ComponentProps) => { return renderWithProviders(, { @@ -114,36 +85,36 @@ describe('ChangePipette', () => { props = { robotName: 'otie', mount: 'left', - closeModal: jest.fn(), + closeModal: vi.fn(), } - dispatchApiRequest = jest.fn() - mockUseAttachedPipettes.mockReturnValue({ left: null, right: null }) - mockGetRequestById.mockReturnValue(null) - mockGetCalibrationForPipette.mockReturnValue(null) - mockGetHasCalibrationBlock.mockReturnValue(false) - mockGetMovementStatus.mockReturnValue(null) - mockGetPipetteNameSpecs.mockReturnValue(null) - when(mockUseDispatchApiRequests).mockReturnValue([ + dispatchApiRequest = vi.fn() + vi.mocked(useAttachedPipettes).mockReturnValue({ left: null, right: null }) + vi.mocked(getRequestById).mockReturnValue(null) + vi.mocked(getCalibrationForPipette).mockReturnValue(null) + vi.mocked(getHasCalibrationBlock).mockReturnValue(false) + vi.mocked(getMovementStatus).mockReturnValue(null) + vi.mocked(getPipetteNameSpecs).mockReturnValue(null) + vi.mocked(useDispatchApiRequests).mockReturnValue([ dispatchApiRequest, ['id'], ]) }) - afterEach(() => { - jest.resetAllMocks() - }) - it('renders the in progress modal when the movement status is moving', () => { - mockGetMovementStatus.mockReturnValue('moving') - mockInProgress.mockReturnValue(
mock in progress modal
) + vi.mocked(getMovementStatus).mockReturnValue('moving') + vi.mocked(InProgressModal).mockReturnValue( +
mock in progress modal
+ ) const { getByText } = render(props) getByText('Attach a pipette') getByText('mock in progress modal') }) it('renders the wizard pages for attaching a pipette and clicking on the exit button will render the exit modal', () => { - mockPipetteSelection.mockReturnValue(
mock pipette selection
) - mockExitModal.mockReturnValue(
mock exit modal
) + vi.mocked(PipetteSelection).mockReturnValue( +
mock pipette selection
+ ) + vi.mocked(ExitModal).mockReturnValue(
mock exit modal
) const { getByText, getByLabelText, getByRole } = render(props) // Clear deck modal page @@ -171,7 +142,9 @@ describe('ChangePipette', () => { }) it('the go back button functions as expected', () => { - mockPipetteSelection.mockReturnValue(
mock pipette selection
) + vi.mocked(PipetteSelection).mockReturnValue( +
mock pipette selection
+ ) const { getByText, getByRole } = render(props) // Clear deck modal page @@ -186,7 +159,9 @@ describe('ChangePipette', () => { }) it('renders the wizard pages for attaching a pipette and goes through flow', () => { - mockPipetteSelection.mockReturnValue(
mock pipette selection
) + vi.mocked(PipetteSelection).mockReturnValue( +
mock pipette selection
+ ) const { getByText, getByRole } = render(props) // Clear deck modal page const cont = getByRole('button', { name: 'Get started' }) @@ -197,8 +172,8 @@ describe('ChangePipette', () => { }) it('renders the wizard pages for detaching a single channel pipette and exits on the 2nd page rendering exit modal', () => { - mockExitModal.mockReturnValue(
mock exit modal
) - mockGetRequestById.mockReturnValue({ + vi.mocked(ExitModal).mockReturnValue(
mock exit modal
) + vi.mocked(getRequestById).mockReturnValue({ status: SUCCESS, response: { method: 'POST', @@ -207,7 +182,7 @@ describe('ChangePipette', () => { status: 200, }, }) - mockUseAttachedPipettes.mockReturnValue({ + vi.mocked(useAttachedPipettes).mockReturnValue({ left: mockAttachedPipettes as AttachedPipette, right: null, }) @@ -251,8 +226,8 @@ describe('ChangePipette', () => { }) it('renders the wizard pages for detaching a single channel pipette and goes through the whole flow', () => { - mockConfirmPipette.mockReturnValue(
mock confirm pipette
) - mockUseAttachedPipettes.mockReturnValue({ + vi.mocked(ConfirmPipette).mockReturnValue(
mock confirm pipette
) + vi.mocked(useAttachedPipettes).mockReturnValue({ left: mockAttachedPipettes as AttachedPipette, right: null, }) diff --git a/app/src/organisms/ChangePipette/__tests__/CheckPipettesButton.test.tsx b/app/src/organisms/ChangePipette/__tests__/CheckPipettesButton.test.tsx index b52266a0574..918dfd171b8 100644 --- a/app/src/organisms/ChangePipette/__tests__/CheckPipettesButton.test.tsx +++ b/app/src/organisms/ChangePipette/__tests__/CheckPipettesButton.test.tsx @@ -1,15 +1,15 @@ import * as React from 'react' import { fireEvent } from '@testing-library/react' +import { vi, it, describe, expect, beforeEach } from 'vitest' + import { usePipettesQuery } from '@opentrons/react-api-client' -import { renderWithProviders } from '@opentrons/components' + +import { renderWithProviders } from '../../../__testing-utils__' import { i18n } from '../../../i18n' import { CheckPipettesButton } from '../CheckPipettesButton' -jest.mock('@opentrons/react-api-client') +vi.mock('@opentrons/react-api-client') -const mockUsePipettesQuery = usePipettesQuery as jest.MockedFunction< - typeof usePipettesQuery -> const render = (props: React.ComponentProps) => { return renderWithProviders(, { i18nInstance: i18n, @@ -22,22 +22,19 @@ describe('CheckPipettesButton', () => { props = { robotName: 'otie', children:
btn text
, - onDone: jest.fn(), + onDone: vi.fn(), } }) - afterEach(() => { - jest.resetAllMocks() - }) it('renders the confirm attachment btn and clicking on it calls fetchPipettes', () => { - const refetch = jest.fn(() => Promise.resolve()) - mockUsePipettesQuery.mockReturnValue({ + const refetch = vi.fn(() => Promise.resolve()) + vi.mocked(usePipettesQuery).mockReturnValue({ refetch, isFetching: false, } as any) props = { robotName: 'otie', - onDone: jest.fn(), + onDone: vi.fn(), direction: 'attach', } const { getByLabelText, getByText } = render(props) @@ -48,14 +45,14 @@ describe('CheckPipettesButton', () => { }) it('renders the confirm detachment btn and clicking on it calls fetchPipettes', () => { - const refetch = jest.fn(() => Promise.resolve()) - mockUsePipettesQuery.mockReturnValue({ + const refetch = vi.fn(() => Promise.resolve()) + vi.mocked(usePipettesQuery).mockReturnValue({ refetch, isFetching: false, } as any) props = { robotName: 'otie', - onDone: jest.fn(), + onDone: vi.fn(), direction: 'detach', } const { getByLabelText, getByText } = render(props) @@ -66,13 +63,13 @@ describe('CheckPipettesButton', () => { }) it('renders button disabled when pipettes query status is loading', () => { - const refetch = jest.fn(() => Promise.resolve()) - mockUsePipettesQuery.mockReturnValue({ + const refetch = vi.fn(() => Promise.resolve()) + vi.mocked(usePipettesQuery).mockReturnValue({ refetch, } as any) props = { robotName: 'otie', - onDone: jest.fn(), + onDone: vi.fn(), } const { getByLabelText } = render(props) const btn = getByLabelText('Confirm') @@ -81,8 +78,8 @@ describe('CheckPipettesButton', () => { }) it('renders the confirm detachment btn and with children and clicking on it calls fetchPipettes', () => { - const refetch = jest.fn(() => Promise.resolve()) - mockUsePipettesQuery.mockReturnValue({ + const refetch = vi.fn(() => Promise.resolve()) + vi.mocked(usePipettesQuery).mockReturnValue({ refetch, isFetching: false, } as any) diff --git a/app/src/organisms/ChangePipette/__tests__/ClearDeckModal.test.tsx b/app/src/organisms/ChangePipette/__tests__/ClearDeckModal.test.tsx index dfef2b8c1ad..01079a32fcc 100644 --- a/app/src/organisms/ChangePipette/__tests__/ClearDeckModal.test.tsx +++ b/app/src/organisms/ChangePipette/__tests__/ClearDeckModal.test.tsx @@ -1,6 +1,8 @@ import * as React from 'react' import { fireEvent } from '@testing-library/react' -import { renderWithProviders } from '@opentrons/components' +import { vi, it, describe, expect, beforeEach } from 'vitest' + +import { renderWithProviders } from '../../../__testing-utils__' import { i18n } from '../../../i18n' import { ClearDeckModal } from '../ClearDeckModal' @@ -13,7 +15,7 @@ describe('ClearDeckModal', () => { let props: React.ComponentProps beforeEach(() => { props = { - onContinueClick: jest.fn(), + onContinueClick: vi.fn(), } }) it('renders the correct information when pipette is not attached', () => { diff --git a/app/src/organisms/ChangePipette/__tests__/ConfirmPipette.test.tsx b/app/src/organisms/ChangePipette/__tests__/ConfirmPipette.test.tsx index b689214fb02..9cc9b232db8 100644 --- a/app/src/organisms/ChangePipette/__tests__/ConfirmPipette.test.tsx +++ b/app/src/organisms/ChangePipette/__tests__/ConfirmPipette.test.tsx @@ -1,11 +1,14 @@ import * as React from 'react' -import { renderWithProviders } from '@opentrons/components' import { fireEvent, screen } from '@testing-library/react' +import { vi, it, describe, expect } from 'vitest' + +import { renderWithProviders } from '../../../__testing-utils__' import { i18n } from '../../../i18n' import { LEFT } from '@opentrons/shared-data' import { mockPipetteInfo } from '../../../redux/pipettes/__fixtures__' import { CheckPipettesButton } from '../CheckPipettesButton' import { ConfirmPipette } from '../ConfirmPipette' +import { LevelingVideo } from '../LevelPipette' import type { PipetteModelSpecs, @@ -13,11 +16,14 @@ import type { } from '@opentrons/shared-data' import type { PipetteOffsetCalibration } from '../../../redux/calibration/types' -jest.mock('../CheckPipettesButton') - -const mockCheckPipettesButton = CheckPipettesButton as jest.MockedFunction< - typeof CheckPipettesButton -> +vi.mock('../CheckPipettesButton') +vi.mock('../LevelPipette', async importOriginal => { + const actual = await importOriginal() + return { + ...actual, + LevelingVideo: vi.fn(), + } +}) const render = (props: React.ComponentProps) => { return renderWithProviders(, { @@ -93,15 +99,15 @@ describe('ConfirmPipette', () => { actualPipetteOffset: {} as PipetteOffsetCalibration, displayName: 'P10', displayCategory: 'GEN1', - tryAgain: jest.fn(), - exit: jest.fn(), - toCalibrationDashboard: jest.fn(), + tryAgain: vi.fn(), + exit: vi.fn(), + toCalibrationDashboard: vi.fn(), mount: LEFT, - setWrongWantedPipette: jest.fn(), + setWrongWantedPipette: vi.fn(), wrongWantedPipette: null, confirmPipetteLevel: false, - nextStep: jest.fn(), - setConfirmPipetteLevel: jest.fn(), + nextStep: vi.fn(), + setConfirmPipetteLevel: vi.fn(), isDisabled: false, } @@ -122,15 +128,15 @@ describe('ConfirmPipette', () => { actualPipetteOffset: {} as PipetteOffsetCalibration, displayName: 'P10', displayCategory: 'GEN1', - tryAgain: jest.fn(), - exit: jest.fn(), - toCalibrationDashboard: jest.fn(), + tryAgain: vi.fn(), + exit: vi.fn(), + toCalibrationDashboard: vi.fn(), mount: LEFT, - setWrongWantedPipette: jest.fn(), + setWrongWantedPipette: vi.fn(), wrongWantedPipette: null, confirmPipetteLevel: false, - nextStep: jest.fn(), - setConfirmPipetteLevel: jest.fn(), + nextStep: vi.fn(), + setConfirmPipetteLevel: vi.fn(), isDisabled: false, } @@ -159,15 +165,15 @@ describe('ConfirmPipette', () => { actualPipetteOffset: {} as PipetteOffsetCalibration, displayName: '', displayCategory: null, - tryAgain: jest.fn(), - exit: jest.fn(), - toCalibrationDashboard: jest.fn(), + tryAgain: vi.fn(), + exit: vi.fn(), + toCalibrationDashboard: vi.fn(), mount: LEFT, - setWrongWantedPipette: jest.fn(), + setWrongWantedPipette: vi.fn(), wrongWantedPipette: null, confirmPipetteLevel: false, - nextStep: jest.fn(), - setConfirmPipetteLevel: jest.fn(), + nextStep: vi.fn(), + setConfirmPipetteLevel: vi.fn(), isDisabled: false, } @@ -196,15 +202,15 @@ describe('ConfirmPipette', () => { actualPipetteOffset: {} as PipetteOffsetCalibration, displayName: '', displayCategory: null, - tryAgain: jest.fn(), - exit: jest.fn(), - toCalibrationDashboard: jest.fn(), + tryAgain: vi.fn(), + exit: vi.fn(), + toCalibrationDashboard: vi.fn(), mount: LEFT, - setWrongWantedPipette: jest.fn(), + setWrongWantedPipette: vi.fn(), wrongWantedPipette: MOCK_ACTUAL_PIPETTE, confirmPipetteLevel: false, - nextStep: jest.fn(), - setConfirmPipetteLevel: jest.fn(), + nextStep: vi.fn(), + setConfirmPipetteLevel: vi.fn(), isDisabled: false, } @@ -229,15 +235,15 @@ describe('ConfirmPipette', () => { actualPipetteOffset: {} as PipetteOffsetCalibration, displayName: '', displayCategory: null, - tryAgain: jest.fn(), - exit: jest.fn(), - toCalibrationDashboard: jest.fn(), + tryAgain: vi.fn(), + exit: vi.fn(), + toCalibrationDashboard: vi.fn(), mount: LEFT, - setWrongWantedPipette: jest.fn(), + setWrongWantedPipette: vi.fn(), wrongWantedPipette: null, confirmPipetteLevel: false, - nextStep: jest.fn(), - setConfirmPipetteLevel: jest.fn(), + nextStep: vi.fn(), + setConfirmPipetteLevel: vi.fn(), isDisabled: false, } @@ -266,15 +272,15 @@ describe('ConfirmPipette', () => { actualPipetteOffset: {} as PipetteOffsetCalibration, displayName: '', displayCategory: null, - tryAgain: jest.fn(), - exit: jest.fn(), - toCalibrationDashboard: jest.fn(), + tryAgain: vi.fn(), + exit: vi.fn(), + toCalibrationDashboard: vi.fn(), mount: LEFT, - setWrongWantedPipette: jest.fn(), + setWrongWantedPipette: vi.fn(), wrongWantedPipette: MOCK_WANTED_PIPETTE, confirmPipetteLevel: false, - nextStep: jest.fn(), - setConfirmPipetteLevel: jest.fn(), + nextStep: vi.fn(), + setConfirmPipetteLevel: vi.fn(), isDisabled: false, } @@ -295,15 +301,15 @@ describe('ConfirmPipette', () => { actualPipetteOffset: null, displayName: '', displayCategory: null, - tryAgain: jest.fn(), - exit: jest.fn(), - toCalibrationDashboard: jest.fn(), + tryAgain: vi.fn(), + exit: vi.fn(), + toCalibrationDashboard: vi.fn(), mount: LEFT, - setWrongWantedPipette: jest.fn(), + setWrongWantedPipette: vi.fn(), wrongWantedPipette: MOCK_WANTED_PIPETTE, confirmPipetteLevel: true, - nextStep: jest.fn(), - setConfirmPipetteLevel: jest.fn(), + nextStep: vi.fn(), + setConfirmPipetteLevel: vi.fn(), isDisabled: false, } @@ -319,7 +325,9 @@ describe('ConfirmPipette', () => { }) it('Should show unable to detect pipette when a pipette is not connected', () => { - mockCheckPipettesButton.mockReturnValue(
mock re-check connection
) + vi.mocked(CheckPipettesButton).mockReturnValue( +
mock re-check connection
+ ) props = { robotName: 'otie', success: false, @@ -329,15 +337,15 @@ describe('ConfirmPipette', () => { actualPipetteOffset: {} as PipetteOffsetCalibration, displayName: '', displayCategory: null, - tryAgain: jest.fn(), - exit: jest.fn(), - toCalibrationDashboard: jest.fn(), + tryAgain: vi.fn(), + exit: vi.fn(), + toCalibrationDashboard: vi.fn(), mount: LEFT, - setWrongWantedPipette: jest.fn(), + setWrongWantedPipette: vi.fn(), wrongWantedPipette: null, confirmPipetteLevel: false, - nextStep: jest.fn(), - setConfirmPipetteLevel: jest.fn(), + nextStep: vi.fn(), + setConfirmPipetteLevel: vi.fn(), isDisabled: false, } @@ -366,15 +374,15 @@ describe('ConfirmPipette', () => { actualPipetteOffset: {} as PipetteOffsetCalibration, displayName: '', displayCategory: null, - tryAgain: jest.fn(), - exit: jest.fn(), - toCalibrationDashboard: jest.fn(), + tryAgain: vi.fn(), + exit: vi.fn(), + toCalibrationDashboard: vi.fn(), mount: LEFT, - setWrongWantedPipette: jest.fn(), + setWrongWantedPipette: vi.fn(), wrongWantedPipette: null, confirmPipetteLevel: false, - nextStep: jest.fn(), - setConfirmPipetteLevel: jest.fn(), + nextStep: vi.fn(), + setConfirmPipetteLevel: vi.fn(), isDisabled: false, } @@ -396,15 +404,15 @@ describe('ConfirmPipette', () => { actualPipetteOffset: null, displayName: '', displayCategory: null, - tryAgain: jest.fn(), - exit: jest.fn(), - toCalibrationDashboard: jest.fn(), + tryAgain: vi.fn(), + exit: vi.fn(), + toCalibrationDashboard: vi.fn(), mount: LEFT, - setWrongWantedPipette: jest.fn(), + setWrongWantedPipette: vi.fn(), wrongWantedPipette: null, confirmPipetteLevel: false, - nextStep: jest.fn(), - setConfirmPipetteLevel: jest.fn(), + nextStep: vi.fn(), + setConfirmPipetteLevel: vi.fn(), isDisabled: false, } diff --git a/app/src/organisms/ChangePipette/__tests__/ExitModal.test.tsx b/app/src/organisms/ChangePipette/__tests__/ExitModal.test.tsx index a2163185cf1..f5f89b11467 100644 --- a/app/src/organisms/ChangePipette/__tests__/ExitModal.test.tsx +++ b/app/src/organisms/ChangePipette/__tests__/ExitModal.test.tsx @@ -1,6 +1,8 @@ import * as React from 'react' import { fireEvent } from '@testing-library/react' -import { renderWithProviders } from '@opentrons/components' +import { vi, it, describe, expect, beforeEach } from 'vitest' + +import { renderWithProviders } from '../../../__testing-utils__' import { i18n } from '../../../i18n' import { ExitModal } from '../ExitModal' @@ -13,8 +15,8 @@ describe('ExitModal', () => { let props: React.ComponentProps beforeEach(() => { props = { - back: jest.fn(), - exit: jest.fn(), + back: vi.fn(), + exit: vi.fn(), direction: 'attach', isDisabled: false, } diff --git a/app/src/organisms/ChangePipette/__tests__/InstructionStep.test.tsx b/app/src/organisms/ChangePipette/__tests__/InstructionStep.test.tsx index a37edfd40aa..b53db93e219 100644 --- a/app/src/organisms/ChangePipette/__tests__/InstructionStep.test.tsx +++ b/app/src/organisms/ChangePipette/__tests__/InstructionStep.test.tsx @@ -1,6 +1,9 @@ import * as React from 'react' -import { renderWithProviders } from '@opentrons/components' +import { it, describe, beforeEach } from 'vitest' + import { GEN1, GEN2, LEFT, RIGHT } from '@opentrons/shared-data' + +import { renderWithProviders } from '../../../__testing-utils__' import { i18n } from '../../../i18n' import { InstructionStep } from '../InstructionStep' diff --git a/app/src/organisms/ChangePipette/__tests__/Instructions.test.tsx b/app/src/organisms/ChangePipette/__tests__/Instructions.test.tsx index 48d469e0d27..4d58def85ac 100644 --- a/app/src/organisms/ChangePipette/__tests__/Instructions.test.tsx +++ b/app/src/organisms/ChangePipette/__tests__/Instructions.test.tsx @@ -1,19 +1,21 @@ import * as React from 'react' -import { nestedTextMatcher, renderWithProviders } from '@opentrons/components' +import { vi, it, describe, expect, beforeEach } from 'vitest' import { fireEvent, screen } from '@testing-library/react' + +import type { PipetteModelSpecs } from '@opentrons/shared-data' + +import { + nestedTextMatcher, + renderWithProviders, +} from '../../../__testing-utils__' import { LEFT } from '@opentrons/shared-data' import { fixtureP10Multi } from '@opentrons/shared-data/pipette/fixtures/name' import { i18n } from '../../../i18n' import { mockPipetteInfo } from '../../../redux/pipettes/__fixtures__' import { Instructions } from '../Instructions' import { CheckPipettesButton } from '../CheckPipettesButton' -import type { PipetteModelSpecs } from '@opentrons/shared-data' - -jest.mock('../CheckPipettesButton') -const mockCheckPipettesButton = CheckPipettesButton as jest.MockedFunction< - typeof CheckPipettesButton -> +vi.mock('../CheckPipettesButton') const render = (props: React.ComponentProps) => { return renderWithProviders(, { @@ -40,15 +42,15 @@ describe('Instructions', () => { actualPipette: MOCK_ACTUAL_PIPETTE, displayCategory: 'GEN1', direction: 'detach', - setWantedName: jest.fn(), - confirm: jest.fn(), - back: jest.fn(), - nextStep: jest.fn(), - prevStep: jest.fn(), + setWantedName: vi.fn(), + confirm: vi.fn(), + back: vi.fn(), + nextStep: vi.fn(), + prevStep: vi.fn(), currentStepCount: 1, attachedWrong: false, } - mockCheckPipettesButton.mockReturnValue( + vi.mocked(CheckPipettesButton).mockReturnValue(
mock check pipettes button
) }) @@ -92,11 +94,11 @@ describe('Instructions', () => { actualPipette: null, displayCategory: null, direction: 'attach', - setWantedName: jest.fn(), - confirm: jest.fn(), - back: jest.fn(), - nextStep: jest.fn(), - prevStep: jest.fn(), + setWantedName: vi.fn(), + confirm: vi.fn(), + back: vi.fn(), + nextStep: vi.fn(), + prevStep: vi.fn(), currentStepCount: 0, attachedWrong: false, } @@ -116,11 +118,11 @@ describe('Instructions', () => { actualPipette: null, displayCategory: 'GEN1', direction: 'attach', - setWantedName: jest.fn(), - confirm: jest.fn(), - back: jest.fn(), - nextStep: jest.fn(), - prevStep: jest.fn(), + setWantedName: vi.fn(), + confirm: vi.fn(), + back: vi.fn(), + nextStep: vi.fn(), + prevStep: vi.fn(), currentStepCount: 1, attachedWrong: false, } @@ -149,11 +151,11 @@ describe('Instructions', () => { actualPipette: null, displayCategory: 'GEN1', direction: 'attach', - setWantedName: jest.fn(), - confirm: jest.fn(), - back: jest.fn(), - nextStep: jest.fn(), - prevStep: jest.fn(), + setWantedName: vi.fn(), + confirm: vi.fn(), + back: vi.fn(), + nextStep: vi.fn(), + prevStep: vi.fn(), currentStepCount: 2, attachedWrong: false, } @@ -177,11 +179,11 @@ describe('Instructions', () => { actualPipette: null, displayCategory: 'GEN1', direction: 'attach', - setWantedName: jest.fn(), - confirm: jest.fn(), - back: jest.fn(), - nextStep: jest.fn(), - prevStep: jest.fn(), + setWantedName: vi.fn(), + confirm: vi.fn(), + back: vi.fn(), + nextStep: vi.fn(), + prevStep: vi.fn(), currentStepCount: 1, attachedWrong: false, } @@ -209,11 +211,11 @@ describe('Instructions', () => { actualPipette: null, displayCategory: 'GEN1', direction: 'attach', - setWantedName: jest.fn(), - confirm: jest.fn(), - back: jest.fn(), - nextStep: jest.fn(), - prevStep: jest.fn(), + setWantedName: vi.fn(), + confirm: vi.fn(), + back: vi.fn(), + nextStep: vi.fn(), + prevStep: vi.fn(), currentStepCount: 2, attachedWrong: false, } @@ -237,11 +239,11 @@ describe('Instructions', () => { actualPipette: null, displayCategory: 'GEN1', direction: 'attach', - setWantedName: jest.fn(), - confirm: jest.fn(), - back: jest.fn(), - nextStep: jest.fn(), - prevStep: jest.fn(), + setWantedName: vi.fn(), + confirm: vi.fn(), + back: vi.fn(), + nextStep: vi.fn(), + prevStep: vi.fn(), currentStepCount: 2, attachedWrong: true, } diff --git a/app/src/organisms/ChangePipette/__tests__/LevelPipette.test.tsx b/app/src/organisms/ChangePipette/__tests__/LevelPipette.test.tsx index fb336d85a36..66526673ca1 100644 --- a/app/src/organisms/ChangePipette/__tests__/LevelPipette.test.tsx +++ b/app/src/organisms/ChangePipette/__tests__/LevelPipette.test.tsx @@ -1,7 +1,13 @@ import * as React from 'react' +import { vi, it, describe, expect, beforeEach } from 'vitest' import { fireEvent } from '@testing-library/react' -import { nestedTextMatcher, renderWithProviders } from '@opentrons/components' + import { LEFT, PipetteNameSpecs } from '@opentrons/shared-data' + +import { + nestedTextMatcher, + renderWithProviders, +} from '../../../__testing-utils__' import { i18n } from '../../../i18n' import { LevelPipette } from '../LevelPipette' @@ -60,7 +66,7 @@ describe('LevelPipette', () => { props = { mount: LEFT, pipetteModelName: MOCK_WANTED_PIPETTE.name, - confirm: jest.fn(), + confirm: vi.fn(), } }) diff --git a/app/src/organisms/ChangePipette/__tests__/PipetteSelection.test.tsx b/app/src/organisms/ChangePipette/__tests__/PipetteSelection.test.tsx index 2f27bc03c2e..d86bab1c814 100644 --- a/app/src/organisms/ChangePipette/__tests__/PipetteSelection.test.tsx +++ b/app/src/organisms/ChangePipette/__tests__/PipetteSelection.test.tsx @@ -1,14 +1,13 @@ import * as React from 'react' -import { renderWithProviders } from '@opentrons/components' +import { vi, it, describe, beforeEach } from 'vitest' + +import { renderWithProviders } from '../../../__testing-utils__' import { i18n } from '../../../i18n' import { PipetteSelect } from '../../../molecules/PipetteSelect' import { PipetteSelection } from '../PipetteSelection' -jest.mock('../../../molecules/PipetteSelect') +vi.mock('../../../molecules/PipetteSelect') -const mockPipetteSelect = PipetteSelect as jest.MockedFunction< - typeof PipetteSelect -> const render = (props: React.ComponentProps) => { return renderWithProviders(, { i18nInstance: i18n, @@ -19,9 +18,9 @@ describe('PipetteSelection', () => { beforeEach(() => { props = { pipetteName: null, - onPipetteChange: jest.fn(), + onPipetteChange: vi.fn(), } - mockPipetteSelect.mockReturnValue(
mock pipette select
) + vi.mocked(PipetteSelect).mockReturnValue(
mock pipette select
) }) it('renders the text for pipette selection', () => { const { getByText } = render(props) diff --git a/app/src/organisms/CheckCalibration/ResultsSummary/__tests__/CalibrationHealthCheckResults.test.tsx b/app/src/organisms/CheckCalibration/ResultsSummary/__tests__/CalibrationHealthCheckResults.test.tsx index 4e72d2fb78e..10d39a309b5 100644 --- a/app/src/organisms/CheckCalibration/ResultsSummary/__tests__/CalibrationHealthCheckResults.test.tsx +++ b/app/src/organisms/CheckCalibration/ResultsSummary/__tests__/CalibrationHealthCheckResults.test.tsx @@ -1,5 +1,9 @@ import * as React from 'react' -import { renderWithProviders, COLORS, TYPOGRAPHY } from '@opentrons/components' +import { it, describe, expect, beforeEach } from 'vitest' + +import { COLORS, TYPOGRAPHY } from '@opentrons/components' + +import { renderWithProviders } from '../../../../__testing-utils__' import { i18n } from '../../../../i18n' import { CalibrationHealthCheckResults } from '../CalibrationHealthCheckResults' diff --git a/app/src/organisms/CheckCalibration/ResultsSummary/__tests__/CalibrationResult.test.tsx b/app/src/organisms/CheckCalibration/ResultsSummary/__tests__/CalibrationResult.test.tsx index a5364a786eb..d1f0958806c 100644 --- a/app/src/organisms/CheckCalibration/ResultsSummary/__tests__/CalibrationResult.test.tsx +++ b/app/src/organisms/CheckCalibration/ResultsSummary/__tests__/CalibrationResult.test.tsx @@ -1,14 +1,12 @@ import * as React from 'react' -import { renderWithProviders } from '@opentrons/components' +import { vi, it, describe, beforeEach } from 'vitest' + +import { renderWithProviders } from '../../../../__testing-utils__' import { i18n } from '../../../../i18n' import { RenderResult } from '../RenderResult' import { CalibrationResult } from '../CalibrationResult' -jest.mock('../RenderResult') - -const mockRenderResult = RenderResult as jest.MockedFunction< - typeof RenderResult -> +vi.mock('../RenderResult') const render = (props: React.ComponentProps) => { return renderWithProviders(, { @@ -24,7 +22,7 @@ describe('PipetteCalibrationResult', () => { calType: 'pipetteOffset', isBadCal: false, } - mockRenderResult.mockReturnValue(
render result
) + vi.mocked(RenderResult).mockReturnValue(
render result
) }) it('should render pipette offset calibration title and RenderResult - isBadCal: false', () => { diff --git a/app/src/organisms/CheckCalibration/ResultsSummary/__tests__/RenderMountInformation.test.tsx b/app/src/organisms/CheckCalibration/ResultsSummary/__tests__/RenderMountInformation.test.tsx index 02558302aa9..e695bbf2320 100644 --- a/app/src/organisms/CheckCalibration/ResultsSummary/__tests__/RenderMountInformation.test.tsx +++ b/app/src/organisms/CheckCalibration/ResultsSummary/__tests__/RenderMountInformation.test.tsx @@ -1,25 +1,24 @@ import * as React from 'react' -import { renderWithProviders } from '@opentrons/components' +import { vi, it, describe, beforeEach } from 'vitest' + import { getPipetteModelSpecs } from '@opentrons/shared-data' + +import { renderWithProviders } from '../../../../__testing-utils__' import { i18n } from '../../../../i18n' import { LEFT, RIGHT } from '../../../../redux/pipettes' import * as Fixtures from '../../../../redux/sessions/__fixtures__' import { RenderMountInformation } from '../RenderMountInformation' -jest.mock('@opentrons/shared-data', () => ({ - getAllPipetteNames: jest.fn( - jest.requireActual('@opentrons/shared-data').getAllPipetteNames - ), - getPipetteNameSpecs: jest.fn( - jest.requireActual('@opentrons/shared-data').getPipetteNameSpecs - ), - getPipetteModelSpecs: jest.fn(), -})) +vi.mock('@opentrons/shared-data', async importOriginal => { + const actual = await importOriginal() + return { + ...actual, + getPipetteModelSpecs: vi.fn(), + } +}) const mockSessionDetails = Fixtures.mockRobotCalibrationCheckSessionDetails -const mockGetPipetteModelSpecs = getPipetteModelSpecs as jest.MockedFunction< - typeof getPipetteModelSpecs -> + const render = (props: React.ComponentProps) => { return renderWithProviders(, { i18nInstance: i18n, @@ -34,7 +33,7 @@ describe('RenderMountInformation', () => { mount: LEFT, pipette: mockSessionDetails.instruments[0], } - mockGetPipetteModelSpecs.mockReturnValue({ + vi.mocked(getPipetteModelSpecs).mockReturnValue({ displayName: 'mock pipette display name', } as any) }) diff --git a/app/src/organisms/CheckCalibration/ResultsSummary/__tests__/RenderResult.test.tsx b/app/src/organisms/CheckCalibration/ResultsSummary/__tests__/RenderResult.test.tsx index c2f463b5c6d..a2065ed198f 100644 --- a/app/src/organisms/CheckCalibration/ResultsSummary/__tests__/RenderResult.test.tsx +++ b/app/src/organisms/CheckCalibration/ResultsSummary/__tests__/RenderResult.test.tsx @@ -1,5 +1,9 @@ import * as React from 'react' -import { renderWithProviders, COLORS, SIZE_1 } from '@opentrons/components' +import { it, describe, expect, beforeEach } from 'vitest' + +import { COLORS, SIZE_1 } from '@opentrons/components' + +import { renderWithProviders } from '../../../../__testing-utils__' import { i18n } from '../../../../i18n' import { RenderResult } from '../RenderResult' diff --git a/app/src/organisms/CheckCalibration/ResultsSummary/__tests__/ResultsSummary.test.tsx b/app/src/organisms/CheckCalibration/ResultsSummary/__tests__/ResultsSummary.test.tsx index f1888f3bfea..499861dcae5 100644 --- a/app/src/organisms/CheckCalibration/ResultsSummary/__tests__/ResultsSummary.test.tsx +++ b/app/src/organisms/CheckCalibration/ResultsSummary/__tests__/ResultsSummary.test.tsx @@ -1,8 +1,9 @@ import * as React from 'react' +import { vi, it, describe, expect, beforeEach } from 'vitest' import { saveAs } from 'file-saver' import { fireEvent } from '@testing-library/react' -import { renderWithProviders } from '@opentrons/components' +import { renderWithProviders } from '../../../../__testing-utils__' import { i18n } from '../../../../i18n' import * as Fixtures from '../../../../redux/sessions/__fixtures__' import * as Sessions from '../../../../redux/sessions' @@ -14,29 +15,25 @@ import { ResultsSummary } from '../' import type { CalibrationPanelProps } from '../../../../organisms/CalibrationPanels/types' -jest.mock('file-saver') -jest.mock('../../../../redux/sessions') -jest.mock('../../../../redux/pipettes') -jest.mock('../CalibrationHealthCheckResults') -jest.mock('../RenderMountInformation') -jest.mock('../CalibrationResult') +vi.mock('file-saver', async importOriginal => { + const actual = await importOriginal() + return { + ...actual, + saveAs: vi.fn(), + } +}) +vi.mock('../../../../redux/sessions') +vi.mock('../../../../redux/pipettes') +vi.mock('../CalibrationHealthCheckResults') +vi.mock('../RenderMountInformation') +vi.mock('../CalibrationResult') -const mockSaveAs = saveAs as jest.MockedFunction -const mockDeleteSession = jest.fn() +const mockDeleteSession = vi.fn() const mockSessionDetails = Fixtures.mockRobotCalibrationCheckSessionDetails -const mockCalibrationHealthCheckResults = CalibrationHealthCheckResults as jest.MockedFunction< - typeof CalibrationHealthCheckResults -> -const mockRenderMountInformation = RenderMountInformation as jest.MockedFunction< - typeof RenderMountInformation -> -const mockCalibrationResult = CalibrationResult as jest.MockedFunction< - typeof CalibrationResult -> const mockIsMulti = false const mockMount = 'left' -const mockSendCommands = jest.fn() +const mockSendCommands = vi.fn() const render = (props: CalibrationPanelProps) => { return renderWithProviders(, { @@ -61,13 +58,15 @@ describe('ResultsSummary', () => { comparisonsByPipette: mockSessionDetails.comparisonsByPipette, checkBothPipettes: true, } - mockCalibrationHealthCheckResults.mockReturnValue( + vi.mocked(CalibrationHealthCheckResults).mockReturnValue(
mock calibration health check results
) - mockRenderMountInformation.mockReturnValue( + vi.mocked(RenderMountInformation).mockReturnValue(
mock render mount information
) - mockCalibrationResult.mockReturnValue(
mock calibration result
) + vi.mocked(CalibrationResult).mockReturnValue( +
mock calibration result
+ ) }) it('should render components', () => { @@ -82,7 +81,7 @@ describe('ResultsSummary', () => { const { getByTestId } = render(props) const button = getByTestId('ResultsSummary_Download_Button') fireEvent.click(button) - expect(mockSaveAs).toHaveBeenCalled() + expect(vi.mocked(saveAs)).toHaveBeenCalled() }) it('calls mock function when clicking finish', () => { diff --git a/app/src/organisms/CheckCalibration/__tests__/CheckCalibration.test.tsx b/app/src/organisms/CheckCalibration/__tests__/CheckCalibration.test.tsx index 641ea9fef8a..d2f2862ea65 100644 --- a/app/src/organisms/CheckCalibration/__tests__/CheckCalibration.test.tsx +++ b/app/src/organisms/CheckCalibration/__tests__/CheckCalibration.test.tsx @@ -1,9 +1,11 @@ import * as React from 'react' import { fireEvent, screen } from '@testing-library/react' -import { when, resetAllWhenMocks } from 'jest-when' +import { when } from 'vitest-when' +import { vi, it, describe, expect, beforeEach } from 'vitest' -import { renderWithProviders } from '@opentrons/components' import { getDeckDefinitions } from '@opentrons/shared-data' + +import { renderWithProviders } from '../../../__testing-utils__' import { i18n } from '../../../i18n' import * as Sessions from '../../../redux/sessions' import { mockCalibrationCheckSessionAttributes } from '../../../redux/sessions/__fixtures__' @@ -11,19 +13,15 @@ import { mockCalibrationCheckSessionAttributes } from '../../../redux/sessions/_ import { CheckCalibration } from '../index' import type { RobotCalibrationCheckStep } from '../../../redux/sessions/types' -jest.mock('@opentrons/shared-data') -jest.mock('../../../redux/calibration/selectors') -jest.mock('../../../redux/config') +vi.mock('@opentrons/shared-data') +vi.mock('../../../redux/calibration/selectors') +vi.mock('../../../redux/config') interface CheckCalibrationSpec { heading: string currentStep: RobotCalibrationCheckStep } -const mockGetDeckDefinitions = getDeckDefinitions as jest.MockedFunction< - typeof getDeckDefinitions -> - describe('CheckCalibration', () => { const dispatchRequests = jest.fn() const mockCalibrationCheckSession: Sessions.CalibrationCheckSession = { @@ -84,12 +82,7 @@ describe('CheckCalibration', () => { ] beforeEach(() => { - when(mockGetDeckDefinitions).calledWith().mockReturnValue({}) - }) - - afterEach(() => { - resetAllWhenMocks() - jest.resetAllMocks() + when(vi.mocked(getDeckDefinitions)).calledWith().thenReturn({}) }) SPECS.forEach(spec => { diff --git a/app/src/organisms/CheckCalibration/__tests__/ReturnTip.test.tsx b/app/src/organisms/CheckCalibration/__tests__/ReturnTip.test.tsx index a16ef3ebd23..e70a7e5eb4b 100644 --- a/app/src/organisms/CheckCalibration/__tests__/ReturnTip.test.tsx +++ b/app/src/organisms/CheckCalibration/__tests__/ReturnTip.test.tsx @@ -1,3 +1,5 @@ +import { it, describe } from 'vitest' + describe('ReturnTip', () => { it.todo('replace deprecated enzyme test') }) diff --git a/app/src/organisms/ChildNavigation/__tests__/ChildNavigation.test.tsx b/app/src/organisms/ChildNavigation/__tests__/ChildNavigation.test.tsx index 81380cf9ffe..8f53b640187 100644 --- a/app/src/organisms/ChildNavigation/__tests__/ChildNavigation.test.tsx +++ b/app/src/organisms/ChildNavigation/__tests__/ChildNavigation.test.tsx @@ -1,16 +1,17 @@ import * as React from 'react' import { fireEvent, screen } from '@testing-library/react' +import { vi, it, describe, expect, beforeEach } from 'vitest' -import { renderWithProviders } from '@opentrons/components' +import { renderWithProviders } from '../../../__testing-utils__' import { SmallButton } from '../../../atoms/buttons' import { ChildNavigation } from '..' const render = (props: React.ComponentProps) => renderWithProviders() -const mockOnClickBack = jest.fn() -const mockOnClickButton = jest.fn() -const mockOnClickSecondaryButton = jest.fn() +const mockOnClickBack = vi.fn() +const mockOnClickButton = vi.fn() +const mockOnClickSecondaryButton = vi.fn() const mockSecondaryButtonProps: React.ComponentProps = { onClick: mockOnClickSecondaryButton, diff --git a/app/src/organisms/ChooseProtocolSlideout/__tests__/ChooseProtocolSlideout.test.tsx b/app/src/organisms/ChooseProtocolSlideout/__tests__/ChooseProtocolSlideout.test.tsx index 2c841e4f91d..54c8b08a159 100644 --- a/app/src/organisms/ChooseProtocolSlideout/__tests__/ChooseProtocolSlideout.test.tsx +++ b/app/src/organisms/ChooseProtocolSlideout/__tests__/ChooseProtocolSlideout.test.tsx @@ -1,7 +1,9 @@ import * as React from 'react' -import { renderWithProviders } from '@opentrons/components' +import { vi, it, describe, expect, beforeEach } from 'vitest' import { StaticRouter } from 'react-router-dom' import { fireEvent, screen } from '@testing-library/react' + +import { renderWithProviders } from '../../../__testing-utils__' import { i18n } from '../../../i18n' import { getStoredProtocols } from '../../../redux/protocol-storage' import { mockConnectableRobot } from '../../../redux/discovery/__fixtures__' @@ -10,20 +12,10 @@ import { useTrackCreateProtocolRunEvent } from '../../../organisms/Devices/hooks import { useCreateRunFromProtocol } from '../../ChooseRobotToRunProtocolSlideout/useCreateRunFromProtocol' import { ChooseProtocolSlideout } from '../' -jest.mock('../../ChooseRobotToRunProtocolSlideout/useCreateRunFromProtocol') -jest.mock('../../../redux/protocol-storage') -jest.mock('../../../organisms/Devices/hooks') -jest.mock('../../../redux/config') - -const mockGetStoredProtocols = getStoredProtocols as jest.MockedFunction< - typeof getStoredProtocols -> -const mockUseCreateRunFromProtocol = useCreateRunFromProtocol as jest.MockedFunction< - typeof useCreateRunFromProtocol -> -const mockUseTrackCreateProtocolRunEvent = useTrackCreateProtocolRunEvent as jest.MockedFunction< - typeof useTrackCreateProtocolRunEvent -> +vi.mock('../../ChooseRobotToRunProtocolSlideout/useCreateRunFromProtocol') +vi.mock('../../../redux/protocol-storage') +vi.mock('../../../organisms/Devices/hooks') +vi.mock('../../../redux/config') const render = (props: React.ComponentProps) => { return renderWithProviders( @@ -37,30 +29,27 @@ const render = (props: React.ComponentProps) => { } describe('ChooseProtocolSlideout', () => { - let mockCreateRunFromProtocol: jest.Mock - let mockTrackCreateProtocolRunEvent: jest.Mock + let mockCreateRunFromProtocol = vi.fn() + let mockTrackCreateProtocolRunEvent = vi.fn() beforeEach(() => { - mockCreateRunFromProtocol = jest.fn() - mockTrackCreateProtocolRunEvent = jest.fn( + mockCreateRunFromProtocol = vi.fn() + mockTrackCreateProtocolRunEvent = vi.fn( () => new Promise(resolve => resolve({})) ) - mockGetStoredProtocols.mockReturnValue([storedProtocolDataFixture]) - mockUseCreateRunFromProtocol.mockReturnValue({ + vi.mocked(getStoredProtocols).mockReturnValue([storedProtocolDataFixture]) + vi.mocked(useCreateRunFromProtocol).mockReturnValue({ createRunFromProtocolSource: mockCreateRunFromProtocol, - reset: jest.fn(), + reset: vi.fn(), } as any) - mockUseTrackCreateProtocolRunEvent.mockReturnValue({ + vi.mocked(useTrackCreateProtocolRunEvent).mockReturnValue({ trackCreateProtocolRunEvent: mockTrackCreateProtocolRunEvent, }) }) - afterEach(() => { - jest.resetAllMocks() - }) it('renders slideout if showSlideout true', () => { render({ robot: mockConnectableRobot, - onCloseClick: jest.fn(), + onCloseClick: vi.fn(), showSlideout: true, }) screen.getByText(/choose protocol to run/i) @@ -69,7 +58,7 @@ describe('ChooseProtocolSlideout', () => { it('renders an available protocol option for every stored protocol if any', () => { render({ robot: mockConnectableRobot, - onCloseClick: jest.fn(), + onCloseClick: vi.fn(), showSlideout: true, }) screen.getByLabelText('protocol deck map') @@ -79,10 +68,10 @@ describe('ChooseProtocolSlideout', () => { ).toBeNull() }) it('renders an empty state if no protocol options', () => { - mockGetStoredProtocols.mockReturnValue([]) + vi.mocked(getStoredProtocols).mockReturnValue([]) render({ robot: mockConnectableRobot, - onCloseClick: jest.fn(), + onCloseClick: vi.fn(), showSlideout: true, }) expect(screen.queryByLabelText('protocol deck map')).toBeNull() @@ -94,7 +83,7 @@ describe('ChooseProtocolSlideout', () => { it('calls createRunFromProtocolSource if CTA clicked', () => { render({ robot: mockConnectableRobot, - onCloseClick: jest.fn(), + onCloseClick: vi.fn(), showSlideout: true, }) const proceedButton = screen.getByRole('button', { @@ -108,16 +97,16 @@ describe('ChooseProtocolSlideout', () => { expect(mockTrackCreateProtocolRunEvent).toHaveBeenCalled() }) it('renders error state when there is a run creation error', () => { - mockUseCreateRunFromProtocol.mockReturnValue({ + vi.mocked(useCreateRunFromProtocol).mockReturnValue({ runCreationError: 'run creation error', createRunFromProtocolSource: mockCreateRunFromProtocol, isCreatingRun: false, - reset: jest.fn(), + reset: vi.fn(), runCreationErrorCode: 500, }) render({ robot: mockConnectableRobot, - onCloseClick: jest.fn(), + onCloseClick: vi.fn(), showSlideout: true, }) const proceedButton = screen.getByRole('button', { @@ -133,16 +122,16 @@ describe('ChooseProtocolSlideout', () => { }) it('renders error state when run creation error code is 409', () => { - mockUseCreateRunFromProtocol.mockReturnValue({ + vi.mocked(useCreateRunFromProtocol).mockReturnValue({ runCreationError: 'Current run is not idle or stopped.', createRunFromProtocolSource: mockCreateRunFromProtocol, isCreatingRun: false, - reset: jest.fn(), + reset: vi.fn(), runCreationErrorCode: 409, }) render({ robot: mockConnectableRobot, - onCloseClick: jest.fn(), + onCloseClick: vi.fn(), showSlideout: true, }) const proceedButton = screen.getByRole('button', { diff --git a/app/src/organisms/ChooseRobotSlideout/__tests__/ChooseRobotSlideout.test.tsx b/app/src/organisms/ChooseRobotSlideout/__tests__/ChooseRobotSlideout.test.tsx index 2a4ec6fda28..5392a57b2a5 100644 --- a/app/src/organisms/ChooseRobotSlideout/__tests__/ChooseRobotSlideout.test.tsx +++ b/app/src/organisms/ChooseRobotSlideout/__tests__/ChooseRobotSlideout.test.tsx @@ -1,8 +1,10 @@ import * as React from 'react' -import { renderWithProviders } from '@opentrons/components' +import { vi, it, describe, expect, beforeEach } from 'vitest' + import { StaticRouter } from 'react-router-dom' import { fireEvent, screen } from '@testing-library/react' +import { renderWithProviders } from '../../../__testing-utils__' import { i18n } from '../../../i18n' import { getConnectableRobots, @@ -19,26 +21,9 @@ import { import { getNetworkInterfaces } from '../../../redux/networking' import { ChooseRobotSlideout } from '..' -jest.mock('../../../redux/discovery') -jest.mock('../../../redux/robot-update') -jest.mock('../../../redux/networking') - -const mockGetConnectableRobots = getConnectableRobots as jest.MockedFunction< - typeof getConnectableRobots -> -const mockGetReachableRobots = getReachableRobots as jest.MockedFunction< - typeof getReachableRobots -> -const mockGetUnreachableRobots = getUnreachableRobots as jest.MockedFunction< - typeof getUnreachableRobots -> -const mockGetScanning = getScanning as jest.MockedFunction -const mockStartDiscovery = startDiscovery as jest.MockedFunction< - typeof startDiscovery -> -const mockGetNetworkInterfaces = getNetworkInterfaces as jest.MockedFunction< - typeof getNetworkInterfaces -> +vi.mock('../../../redux/discovery') +vi.mock('../../../redux/robot-update') +vi.mock('../../../redux/networking') const render = (props: React.ComponentProps) => { return renderWithProviders( @@ -51,28 +36,30 @@ const render = (props: React.ComponentProps) => { ) } -const mockSetSelectedRobot = jest.fn() +const mockSetSelectedRobot = vi.fn() describe('ChooseRobotSlideout', () => { beforeEach(() => { - mockGetConnectableRobots.mockReturnValue([mockConnectableRobot]) - mockGetUnreachableRobots.mockReturnValue([mockUnreachableRobot]) - mockGetReachableRobots.mockReturnValue([mockReachableRobot]) - mockGetScanning.mockReturnValue(false) - mockStartDiscovery.mockReturnValue({ type: 'mockStartDiscovery' } as any) - mockGetNetworkInterfaces.mockReturnValue({ wifi: null, ethernet: null }) - }) - afterEach(() => { - jest.resetAllMocks() + vi.mocked(getConnectableRobots).mockReturnValue([mockConnectableRobot]) + vi.mocked(getUnreachableRobots).mockReturnValue([mockUnreachableRobot]) + vi.mocked(getReachableRobots).mockReturnValue([mockReachableRobot]) + vi.mocked(getScanning).mockReturnValue(false) + vi.mocked(startDiscovery).mockReturnValue({ + type: 'mockStartDiscovery', + } as any) + vi.mocked(getNetworkInterfaces).mockReturnValue({ + wifi: null, + ethernet: null, + }) }) it('renders slideout if isExpanded true', () => { render({ - onCloseClick: jest.fn(), + onCloseClick: vi.fn(), isExpanded: true, isSelectedRobotOnDifferentSoftwareVersion: false, selectedRobot: null, - setSelectedRobot: jest.fn(), + setSelectedRobot: vi.fn(), title: 'choose robot slideout title', robotType: 'OT-2 Standard', }) @@ -80,11 +67,11 @@ describe('ChooseRobotSlideout', () => { }) it('shows a warning if the protocol has failed analysis', () => { render({ - onCloseClick: jest.fn(), + onCloseClick: vi.fn(), isExpanded: true, isSelectedRobotOnDifferentSoftwareVersion: false, selectedRobot: null, - setSelectedRobot: jest.fn(), + setSelectedRobot: vi.fn(), title: 'choose robot slideout title', isAnalysisError: true, robotType: 'OT-2 Standard', @@ -95,11 +82,11 @@ describe('ChooseRobotSlideout', () => { }) it('renders an available robot option for every connectable robot, and link for other robots', () => { render({ - onCloseClick: jest.fn(), + onCloseClick: vi.fn(), isExpanded: true, isSelectedRobotOnDifferentSoftwareVersion: false, selectedRobot: null, - setSelectedRobot: jest.fn(), + setSelectedRobot: vi.fn(), title: 'choose robot slideout title', robotType: 'OT-2 Standard', }) @@ -107,13 +94,13 @@ describe('ChooseRobotSlideout', () => { screen.getByText('2 unavailable robots are not listed.') }) it('if scanning, show robots, but do not show link to other devices', () => { - mockGetScanning.mockReturnValue(true) + vi.mocked(getScanning).mockReturnValue(true) render({ - onCloseClick: jest.fn(), + onCloseClick: vi.fn(), isExpanded: true, isSelectedRobotOnDifferentSoftwareVersion: false, selectedRobot: null, - setSelectedRobot: jest.fn(), + setSelectedRobot: vi.fn(), title: 'choose robot slideout title', robotType: 'OT-2 Standard', }) @@ -124,7 +111,7 @@ describe('ChooseRobotSlideout', () => { }) it('if not scanning, show refresh button, start discovery if clicked', () => { const { dispatch } = render({ - onCloseClick: jest.fn(), + onCloseClick: vi.fn(), isExpanded: true, isSelectedRobotOnDifferentSoftwareVersion: false, selectedRobot: null, @@ -134,16 +121,16 @@ describe('ChooseRobotSlideout', () => { })[1] const refreshButton = screen.getByRole('button', { name: 'refresh' }) fireEvent.click(refreshButton) - expect(mockStartDiscovery).toHaveBeenCalled() + expect(vi.mocked(startDiscovery)).toHaveBeenCalled() expect(dispatch).toHaveBeenCalledWith({ type: 'mockStartDiscovery' }) }) it('defaults to first available robot and allows an available robot to be selected', () => { - mockGetConnectableRobots.mockReturnValue([ + vi.mocked(getConnectableRobots).mockReturnValue([ { ...mockConnectableRobot, name: 'otherRobot', ip: 'otherIp' }, mockConnectableRobot, ]) render({ - onCloseClick: jest.fn(), + onCloseClick: vi.fn(), isExpanded: true, isSelectedRobotOnDifferentSoftwareVersion: false, selectedRobot: null, diff --git a/app/src/organisms/ChooseRobotToRunProtocolSlideout/__tests__/ChooseRobotToRunProtocolSlideout.test.tsx b/app/src/organisms/ChooseRobotToRunProtocolSlideout/__tests__/ChooseRobotToRunProtocolSlideout.test.tsx index 39304bd76c7..c7c4ba03804 100644 --- a/app/src/organisms/ChooseRobotToRunProtocolSlideout/__tests__/ChooseRobotToRunProtocolSlideout.test.tsx +++ b/app/src/organisms/ChooseRobotToRunProtocolSlideout/__tests__/ChooseRobotToRunProtocolSlideout.test.tsx @@ -1,9 +1,10 @@ import * as React from 'react' -import { renderWithProviders } from '@opentrons/components' +import { vi, it, describe, expect, beforeEach, afterEach } from 'vitest' import { StaticRouter } from 'react-router-dom' import { fireEvent, screen } from '@testing-library/react' -import { when, resetAllWhenMocks } from 'jest-when' +import { when } from 'vitest-when' +import { renderWithProviders } from '../../../__testing-utils__' import { i18n } from '../../../i18n' import { useTrackCreateProtocolRunEvent } from '../../../organisms/Devices/hooks' import { @@ -32,56 +33,15 @@ import { ChooseRobotToRunProtocolSlideout } from '../' import type { State } from '../../../redux/types' -jest.mock('../../../organisms/Devices/hooks') -jest.mock('../../../organisms/ProtocolUpload/hooks') -jest.mock('../../../organisms/RunTimeControl/hooks') -jest.mock('../../../redux/discovery') -jest.mock('../../../redux/robot-update') -jest.mock('../../../redux/networking') -jest.mock('../../../redux/config') -jest.mock('../useCreateRunFromProtocol') -jest.mock('../../ApplyHistoricOffsets/hooks/useOffsetCandidatesForAnalysis') - -const mockUseOffsetCandidatesForAnalysis = useOffsetCandidatesForAnalysis as jest.MockedFunction< - typeof useOffsetCandidatesForAnalysis -> -const mockGetBuildrootUpdateDisplayInfo = getRobotUpdateDisplayInfo as jest.MockedFunction< - typeof getRobotUpdateDisplayInfo -> -const mockGetConnectableRobots = getConnectableRobots as jest.MockedFunction< - typeof getConnectableRobots -> -const mockGetReachableRobots = getReachableRobots as jest.MockedFunction< - typeof getReachableRobots -> -const mockGetUnreachableRobots = getUnreachableRobots as jest.MockedFunction< - typeof getUnreachableRobots -> -const mockGetScanning = getScanning as jest.MockedFunction -const mockStartDiscovery = startDiscovery as jest.MockedFunction< - typeof startDiscovery -> -const mockUseCloseCurrentRun = useCloseCurrentRun as jest.MockedFunction< - typeof useCloseCurrentRun -> - -const mockUseCurrentRunId = useCurrentRunId as jest.MockedFunction< - typeof useCurrentRunId -> - -const mockUseCurrentRunStatus = useCurrentRunStatus as jest.MockedFunction< - typeof useCurrentRunStatus -> - -const mockUseCreateRunFromProtocol = useCreateRunFromProtocol as jest.MockedFunction< - typeof useCreateRunFromProtocol -> -const mockUseTrackCreateProtocolRunEvent = useTrackCreateProtocolRunEvent as jest.MockedFunction< - typeof useTrackCreateProtocolRunEvent -> -const mockGetNetworkInterfaces = getNetworkInterfaces as jest.MockedFunction< - typeof getNetworkInterfaces -> +vi.mock('../../../organisms/Devices/hooks') +vi.mock('../../../organisms/ProtocolUpload/hooks') +vi.mock('../../../organisms/RunTimeControl/hooks') +vi.mock('../../../redux/discovery') +vi.mock('../../../redux/robot-update') +vi.mock('../../../redux/networking') +vi.mock('../../../redux/config') +vi.mock('../useCreateRunFromProtocol') +vi.mock('../../ApplyHistoricOffsets/hooks/useOffsetCandidatesForAnalysis') const render = ( props: React.ComponentProps @@ -96,76 +56,76 @@ const render = ( ) } -let mockCloseCurrentRun: jest.Mock -let mockResetCreateRun: jest.Mock -let mockCreateRunFromProtocolSource: jest.Mock -let mockTrackCreateProtocolRunEvent: jest.Mock - describe('ChooseRobotToRunProtocolSlideout', () => { + let mockCloseCurrentRun = vi.fn() + let mockResetCreateRun = vi.fn() + let mockCreateRunFromProtocolSource = vi.fn() + let mockTrackCreateProtocolRunEvent = vi.fn() beforeEach(() => { - mockCloseCurrentRun = jest.fn() - mockResetCreateRun = jest.fn() - mockCreateRunFromProtocolSource = jest.fn() - mockTrackCreateProtocolRunEvent = jest.fn( + mockCloseCurrentRun = vi.fn() + mockResetCreateRun = vi.fn() + mockCreateRunFromProtocolSource = vi.fn() + mockTrackCreateProtocolRunEvent = vi.fn( () => new Promise(resolve => resolve({})) ) - mockGetBuildrootUpdateDisplayInfo.mockReturnValue({ + vi.mocked(getRobotUpdateDisplayInfo).mockReturnValue({ autoUpdateAction: '', autoUpdateDisabledReason: null, updateFromFileDisabledReason: null, }) - mockGetConnectableRobots.mockReturnValue([mockConnectableRobot]) - mockGetUnreachableRobots.mockReturnValue([mockUnreachableRobot]) - mockGetReachableRobots.mockReturnValue([mockReachableRobot]) - mockGetScanning.mockReturnValue(false) - mockStartDiscovery.mockReturnValue({ type: 'mockStartDiscovery' } as any) - mockUseCloseCurrentRun.mockReturnValue({ + vi.mocked(getConnectableRobots).mockReturnValue([mockConnectableRobot]) + vi.mocked(getUnreachableRobots).mockReturnValue([mockUnreachableRobot]) + vi.mocked(getReachableRobots).mockReturnValue([mockReachableRobot]) + vi.mocked(getScanning).mockReturnValue(false) + vi.mocked(startDiscovery).mockReturnValue({ + type: 'mockStartDiscovery', + } as any) + vi.mocked(useCloseCurrentRun).mockReturnValue({ isClosingCurrentRun: false, closeCurrentRun: mockCloseCurrentRun, }) - mockUseCurrentRunId.mockReturnValue(null) - mockUseCurrentRunStatus.mockReturnValue(null) - when(mockUseCreateRunFromProtocol) + vi.mocked(useCurrentRunId).mockReturnValue(null) + vi.mocked(useCurrentRunStatus).mockReturnValue(null) + when(vi.mocked(useCreateRunFromProtocol)) .calledWith( expect.any(Object), { hostname: expect.any(String) }, expect.any(Array) ) - .mockReturnValue({ + .thenReturn({ createRunFromProtocolSource: mockCreateRunFromProtocolSource, reset: mockResetCreateRun, } as any) - when(mockUseCreateRunFromProtocol) + when(vi.mocked(useCreateRunFromProtocol)) .calledWith(expect.any(Object), null, expect.any(Array)) - .mockReturnValue({ + .thenReturn({ createRunFromProtocolSource: mockCreateRunFromProtocolSource, reset: mockResetCreateRun, } as any) - mockUseTrackCreateProtocolRunEvent.mockReturnValue({ + vi.mocked(useTrackCreateProtocolRunEvent).mockReturnValue({ trackCreateProtocolRunEvent: mockTrackCreateProtocolRunEvent, }) - when(mockUseOffsetCandidatesForAnalysis) + when(vi.mocked(useOffsetCandidatesForAnalysis)) .calledWith(storedProtocolDataFixture.mostRecentAnalysis, null) - .mockReturnValue([]) - when(mockUseOffsetCandidatesForAnalysis) + .thenReturn([]) + when(vi.mocked(useOffsetCandidatesForAnalysis)) .calledWith( storedProtocolDataFixture.mostRecentAnalysis, expect.any(String) ) - .mockReturnValue([]) - when(mockGetNetworkInterfaces) + .thenReturn([]) + when(vi.mocked(getNetworkInterfaces)) .calledWith({} as State, expect.any(String)) - .mockReturnValue({ wifi: null, ethernet: null }) + .thenReturn({ wifi: null, ethernet: null }) }) afterEach(() => { - jest.resetAllMocks() - resetAllWhenMocks() + vi.resetAllMocks() }) it('renders slideout if showSlideout true', () => { render({ storedProtocolData: storedProtocolDataFixture, - onCloseClick: jest.fn(), + onCloseClick: vi.fn(), showSlideout: true, }) screen.getByText(/Choose Robot to Run/i) @@ -174,23 +134,23 @@ describe('ChooseRobotToRunProtocolSlideout', () => { it('renders an available robot option for every connectable robot, and link for other robots', () => { render({ storedProtocolData: storedProtocolDataFixture, - onCloseClick: jest.fn(), + onCloseClick: vi.fn(), showSlideout: true, }) - mockGetUnreachableRobots.mockReturnValue([ + vi.mocked(getUnreachableRobots).mockReturnValue([ { ...mockUnreachableRobot, robotModel: 'OT-3 Standard' }, ]) - mockGetReachableRobots.mockReturnValue([ + vi.mocked(getReachableRobots).mockReturnValue([ { ...mockReachableRobot, robotModel: 'OT-3 Standard' }, ]) screen.getByText('opentrons-robot-name') screen.getByText('2 unavailable or busy robots are not listed.') }) it('if scanning, show robots, but do not show link to other devices', () => { - mockGetScanning.mockReturnValue(true) + vi.mocked(getScanning).mockReturnValue(true) render({ storedProtocolData: storedProtocolDataFixture, - onCloseClick: jest.fn(), + onCloseClick: vi.fn(), showSlideout: true, }) screen.getByText('opentrons-robot-name') @@ -201,22 +161,22 @@ describe('ChooseRobotToRunProtocolSlideout', () => { it('if not scanning, show refresh button, start discovery if clicked', () => { const { dispatch } = render({ storedProtocolData: storedProtocolDataFixture, - onCloseClick: jest.fn(), + onCloseClick: vi.fn(), showSlideout: true, })[1] const refreshButton = screen.getByRole('button', { name: 'refresh' }) fireEvent.click(refreshButton) - expect(mockStartDiscovery).toHaveBeenCalled() + expect(vi.mocked(startDiscovery)).toHaveBeenCalled() expect(dispatch).toHaveBeenCalledWith({ type: 'mockStartDiscovery' }) }) it('defaults to first available robot and allows an available robot to be selected', () => { - mockGetConnectableRobots.mockReturnValue([ + vi.mocked(getConnectableRobots).mockReturnValue([ { ...mockConnectableRobot, name: 'otherRobot', ip: 'otherIp' }, mockConnectableRobot, ]) render({ storedProtocolData: storedProtocolDataFixture, - onCloseClick: jest.fn(), + onCloseClick: vi.fn(), showSlideout: true, }) const proceedButton = screen.getByRole('button', { @@ -237,16 +197,14 @@ describe('ChooseRobotToRunProtocolSlideout', () => { expect(mockTrackCreateProtocolRunEvent).toHaveBeenCalled() }) it('if selected robot is on a different version of the software than the app, disable CTA and show link to device details in options', () => { - when(mockGetBuildrootUpdateDisplayInfo) - .calledWith(({} as any) as State, 'opentrons-robot-name') - .mockReturnValue({ - autoUpdateAction: 'upgrade', - autoUpdateDisabledReason: null, - updateFromFileDisabledReason: null, - }) + vi.mocked(getRobotUpdateDisplayInfo).mockReturnValue({ + autoUpdateAction: 'upgrade', + autoUpdateDisabledReason: null, + updateFromFileDisabledReason: null, + }) render({ storedProtocolData: storedProtocolDataFixture, - onCloseClick: jest.fn(), + onCloseClick: vi.fn(), showSlideout: true, }) const proceedButton = screen.getByRole('button', { @@ -261,16 +219,16 @@ describe('ChooseRobotToRunProtocolSlideout', () => { }) it('renders error state when there is a run creation error', () => { - mockUseCreateRunFromProtocol.mockReturnValue({ + vi.mocked(useCreateRunFromProtocol).mockReturnValue({ runCreationError: 'run creation error', createRunFromProtocolSource: mockCreateRunFromProtocolSource, isCreatingRun: false, - reset: jest.fn(), + reset: vi.fn(), runCreationErrorCode: 500, }) render({ storedProtocolData: storedProtocolDataFixture, - onCloseClick: jest.fn(), + onCloseClick: vi.fn(), showSlideout: true, }) const proceedButton = screen.getByRole('button', { @@ -286,16 +244,16 @@ describe('ChooseRobotToRunProtocolSlideout', () => { }) it('renders error state when run creation error code is 409', () => { - mockUseCreateRunFromProtocol.mockReturnValue({ + vi.mocked(useCreateRunFromProtocol).mockReturnValue({ runCreationError: 'Current run is not idle or stopped.', createRunFromProtocolSource: mockCreateRunFromProtocolSource, isCreatingRun: false, - reset: jest.fn(), + reset: vi.fn(), runCreationErrorCode: 409, }) render({ storedProtocolData: storedProtocolDataFixture, - onCloseClick: jest.fn(), + onCloseClick: vi.fn(), showSlideout: true, }) const proceedButton = screen.getByRole('button', { @@ -325,19 +283,19 @@ describe('ChooseRobotToRunProtocolSlideout', () => { createdAt: '2022-05-11T13:34:51.012179+00:00', runCreatedAt: '2022-05-11T13:33:51.012179+00:00', } - when(mockUseOffsetCandidatesForAnalysis) + when(vi.mocked(useOffsetCandidatesForAnalysis)) .calledWith(storedProtocolDataFixture.mostRecentAnalysis, '127.0.0.1') - .mockReturnValue([mockOffsetCandidate]) - mockGetConnectableRobots.mockReturnValue([ + .thenReturn([mockOffsetCandidate]) + vi.mocked(getConnectableRobots).mockReturnValue([ mockConnectableRobot, { ...mockConnectableRobot, name: 'otherRobot', ip: 'otherIp' }, ]) render({ storedProtocolData: storedProtocolDataFixture, - onCloseClick: jest.fn(), + onCloseClick: vi.fn(), showSlideout: true, }) - expect(mockUseCreateRunFromProtocol).toHaveBeenCalledWith( + expect(vi.mocked(useCreateRunFromProtocol)).toHaveBeenCalledWith( expect.any(Object), { hostname: '127.0.0.1' }, [ @@ -369,19 +327,19 @@ describe('ChooseRobotToRunProtocolSlideout', () => { createdAt: '2022-05-11T13:34:51.012179+00:00', runCreatedAt: '2022-05-11T13:33:51.012179+00:00', } - when(mockUseOffsetCandidatesForAnalysis) + when(vi.mocked(useOffsetCandidatesForAnalysis)) .calledWith(storedProtocolDataFixture.mostRecentAnalysis, '127.0.0.1') - .mockReturnValue([mockOffsetCandidate]) - when(mockUseOffsetCandidatesForAnalysis) + .thenReturn([mockOffsetCandidate]) + when(vi.mocked(useOffsetCandidatesForAnalysis)) .calledWith(storedProtocolDataFixture.mostRecentAnalysis, 'otherIp') - .mockReturnValue([]) - mockGetConnectableRobots.mockReturnValue([ + .thenReturn([]) + vi.mocked(getConnectableRobots).mockReturnValue([ mockConnectableRobot, { ...mockConnectableRobot, name: 'otherRobot', ip: 'otherIp' }, ]) render({ storedProtocolData: storedProtocolDataFixture, - onCloseClick: jest.fn(), + onCloseClick: vi.fn(), showSlideout: true, }) const otherRobot = screen.getByText('otherRobot') @@ -392,7 +350,7 @@ describe('ChooseRobotToRunProtocolSlideout', () => { name: 'Proceed to setup', }) fireEvent.click(proceedButton) - expect(mockUseCreateRunFromProtocol).nthCalledWith( + expect(vi.mocked(useCreateRunFromProtocol)).nthCalledWith( 2, expect.any(Object), { hostname: '127.0.0.1' }, @@ -404,7 +362,7 @@ describe('ChooseRobotToRunProtocolSlideout', () => { }, ] ) - expect(mockUseCreateRunFromProtocol).nthCalledWith( + expect(vi.mocked(useCreateRunFromProtocol)).nthCalledWith( 3, expect.any(Object), { hostname: 'otherIp' }, diff --git a/app/src/organisms/CommandText/__tests__/CommandText.test.tsx b/app/src/organisms/CommandText/__tests__/CommandText.test.tsx index 9bc879b7b4d..a773157192e 100644 --- a/app/src/organisms/CommandText/__tests__/CommandText.test.tsx +++ b/app/src/organisms/CommandText/__tests__/CommandText.test.tsx @@ -1,11 +1,14 @@ import * as React from 'react' -import { renderWithProviders } from '@opentrons/components' +import { it, expect, describe } from 'vitest' + import { FLEX_ROBOT_TYPE, OT2_ROBOT_TYPE, GRIPPER_WASTE_CHUTE_ADDRESSABLE_AREA, MoveToAddressableAreaForDropTipRunTimeCommand, } from '@opentrons/shared-data' + +import { renderWithProviders } from '../../../__testing-utils__' import { i18n } from '../../../i18n' import { CommandText } from '../' import { mockRobotSideAnalysis } from '../__fixtures__' diff --git a/app/src/organisms/ConfigurePipette/__tests__/ConfigFormResetButton.test.tsx b/app/src/organisms/ConfigurePipette/__tests__/ConfigFormResetButton.test.tsx index 1f2f9d426d0..d15645c2d40 100644 --- a/app/src/organisms/ConfigurePipette/__tests__/ConfigFormResetButton.test.tsx +++ b/app/src/organisms/ConfigurePipette/__tests__/ConfigFormResetButton.test.tsx @@ -1,6 +1,8 @@ import * as React from 'react' import { fireEvent } from '@testing-library/react' -import { renderWithProviders } from '@opentrons/components' +import { vi, it, expect, describe, beforeEach } from 'vitest' + +import { renderWithProviders } from '../../../__testing-utils__' import { i18n } from '../../../i18n' import { ConfigFormResetButton } from '../ConfigFormResetButton' @@ -14,13 +16,10 @@ describe('ConfigFormResetButton', () => { let props: React.ComponentProps beforeEach(() => { props = { - onClick: jest.fn(), + onClick: vi.fn(), disabled: false, } }) - afterEach(() => { - jest.resetAllMocks() - }) it('renders text and not disabled', () => { const { getByRole, getByText } = render(props) @@ -36,7 +35,7 @@ describe('ConfigFormResetButton', () => { }) it('renders button text and is disabled', () => { props = { - onClick: jest.fn(), + onClick: vi.fn(), disabled: true, } const { getByRole } = render(props) diff --git a/app/src/organisms/ConfigurePipette/__tests__/ConfigFormSubmitButton.test.tsx b/app/src/organisms/ConfigurePipette/__tests__/ConfigFormSubmitButton.test.tsx index 7df07f80b29..63619e717c3 100644 --- a/app/src/organisms/ConfigurePipette/__tests__/ConfigFormSubmitButton.test.tsx +++ b/app/src/organisms/ConfigurePipette/__tests__/ConfigFormSubmitButton.test.tsx @@ -1,5 +1,7 @@ import * as React from 'react' -import { renderWithProviders } from '@opentrons/components' +import { it, expect, describe, beforeEach } from 'vitest' + +import { renderWithProviders } from '../../../__testing-utils__' import { i18n } from '../../../i18n' import { ConfigFormSubmitButton } from '../ConfigFormSubmitButton' @@ -17,9 +19,6 @@ describe('ConfigFormSubmitButton', () => { formId: 'id', } }) - afterEach(() => { - jest.resetAllMocks() - }) it('renders bottom button text and is not disabled', () => { const { getByRole } = render(props) diff --git a/app/src/organisms/ConfigurePipette/__tests__/ConfigurePipette.test.tsx b/app/src/organisms/ConfigurePipette/__tests__/ConfigurePipette.test.tsx index a2d9aca36e7..213d0a0a41e 100644 --- a/app/src/organisms/ConfigurePipette/__tests__/ConfigurePipette.test.tsx +++ b/app/src/organisms/ConfigurePipette/__tests__/ConfigurePipette.test.tsx @@ -1,6 +1,8 @@ import * as React from 'react' -import { when, resetAllWhenMocks } from 'jest-when' -import { renderWithProviders } from '@opentrons/components' +import { when } from 'vitest-when' +import { vi, it, expect, describe, beforeEach } from 'vitest' + +import { renderWithProviders } from '../../../__testing-utils__' import { i18n } from '../../../i18n' import * as RobotApi from '../../../redux/robot-api' import { ConfigurePipette } from '../../ConfigurePipette' @@ -10,16 +12,8 @@ import { getConfig } from '../../../redux/config' import type { DispatchApiRequestType } from '../../../redux/robot-api' import type { State } from '../../../redux/types' -jest.mock('../../../redux/robot-api') -jest.mock('../../../redux/config') - -const mockGetConfig = getConfig as jest.MockedFunction -const mockUseDispatchApiRequest = RobotApi.useDispatchApiRequest as jest.MockedFunction< - typeof RobotApi.useDispatchApiRequest -> -const mockGetRequestById = RobotApi.getRequestById as jest.MockedFunction< - typeof RobotApi.getRequestById -> +vi.mock('../../../redux/robot-api') +vi.mock('../../../redux/config') const render = (props: React.ComponentProps) => { return renderWithProviders(, { @@ -39,13 +33,13 @@ describe('ConfigurePipette', () => { updateError: null, settings: mockPipetteSettingsFieldsMap, robotName: mockRobotName, - updateSettings: jest.fn(), - closeModal: jest.fn(), + updateSettings: vi.fn(), + closeModal: vi.fn(), formId: 'id', } - when(mockGetRequestById) + when(vi.mocked(RobotApi.getRequestById)) .calledWith({} as State, 'id') - .mockReturnValue({ + .thenReturn({ status: RobotApi.SUCCESS, response: { method: 'POST', @@ -54,15 +48,11 @@ describe('ConfigurePipette', () => { status: 200, }, }) - mockGetConfig.mockReturnValue({} as any) - dispatchApiRequest = jest.fn() - when(mockUseDispatchApiRequest) + vi.mocked(getConfig).mockReturnValue({} as any) + dispatchApiRequest = vi.fn() + when(vi.mocked(RobotApi.useDispatchApiRequest)) .calledWith() - .mockReturnValue([dispatchApiRequest, ['id']]) - }) - afterEach(() => { - jest.resetAllMocks() - resetAllWhenMocks() + .thenReturn([dispatchApiRequest, ['id']]) }) it('renders correct number of text boxes given the pipette settings data supplied by getAttachedPipetteSettingsFieldsById', () => { diff --git a/app/src/redux/sessions/__fixtures__/tip-length-calibration.ts b/app/src/redux/sessions/__fixtures__/tip-length-calibration.ts index b22548ebbd7..6589e392174 100644 --- a/app/src/redux/sessions/__fixtures__/tip-length-calibration.ts +++ b/app/src/redux/sessions/__fixtures__/tip-length-calibration.ts @@ -1,16 +1,13 @@ -import { fixtureTiprack300ul } from '@opentrons/shared-data' -// import calBlockFixture from '@opentrons/shared-data/labware/definitions/2/opentrons_calibrationblock_short_side_left/1.json' -import { getLatestLabwareDef } from '../../../assets/labware/getLabware' +import { + fixtureTiprack300ul, + fixtureCalibrationBlock, +} from '@opentrons/shared-data' import type { TipLengthCalibrationSessionDetails, CalibrationLabware, } from '../types' import type { TipLengthCalibrationSessionParams } from '../tip-length-calibration/types' -const calBlockFixture = getLatestLabwareDef( - 'opentrons_calibrationblock_short_side_left' -) - export const mockTipLengthTipRack: CalibrationLabware = { slot: '8', loadName: 'opentrons_96_tiprack_300ul', @@ -26,7 +23,7 @@ export const mockTipLengthCalBlock: CalibrationLabware = { namespace: 'opentrons', version: 1, isTiprack: false, - definition: calBlockFixture as CalibrationLabware['definition'], + definition: fixtureCalibrationBlock as CalibrationLabware['definition'], } export const mockTipLengthCalibrationSessionDetails: TipLengthCalibrationSessionDetails = { diff --git a/app/src/redux/shell/__tests__/epics.test.ts b/app/src/redux/shell/__tests__/epics.test.ts index c4b8aaa73f2..d078afe01e9 100644 --- a/app/src/redux/shell/__tests__/epics.test.ts +++ b/app/src/redux/shell/__tests__/epics.test.ts @@ -19,7 +19,9 @@ vi.mock('../remote') // TODO(mc, 2020-10-08): this is a partial mock because shell/update // needs some reorg to split actions and selectors vi.mock('../update', async importOriginal => { - const actual = (await importOriginal()) as any + const actual = await importOriginal< + typeof ShellUpdate.getAvailableShellUpdate + >() return { ...actual, getAvailableShellUpdate: vi.fn(),