From 25ad07f4f662a9d4a66b5fa0cb3d3616adbbcce4 Mon Sep 17 00:00:00 2001 From: koji Date: Tue, 27 Feb 2024 18:00:13 -0500 Subject: [PATCH] update tests that are in L* for vitest migration --- .../CustomLabwareOverflowMenu.test.tsx | 28 +++--- .../__tests__/LabwareCard.test.tsx | 2 +- .../__tests__/ExpandingTitle.test.tsx | 22 ++--- .../__tests__/LabeledValue.test.tsx | 16 ++-- .../__tests__/Dimensions.test.tsx | 15 ++-- .../LabwareDetails/__tests__/Gallery.test.tsx | 25 +++--- .../__tests__/LabwareDetails.test.tsx | 90 ++++++++----------- .../__tests__/ManufacturerDetails.test.tsx | 27 +++--- .../__tests__/WellCount.test.tsx | 11 +-- .../__tests__/WellDimensions.test.tsx | 30 ++++--- .../__tests__/WellProperties.test.tsx | 24 ++--- .../__tests__/WellSpacing.test.tsx | 26 +++--- .../__tests__/LabwareOffsetTabs.test.tsx | 5 +- .../__fixtures__/mockLabwareDef.ts | 4 +- .../__fixtures__/mockTipRackDef.ts | 4 +- .../__tests__/ReturnTip.test.tsx | 36 ++++---- .../__tests__/RobotMotionLoader.test.tsx | 10 ++- .../__tests__/useLaunchLPC.test.tsx | 74 ++++++--------- .../doesPipetteVisitAllTipracks.test.ts | 12 +-- .../__tests__/getPrimaryPipetteId.test.ts | 1 + 20 files changed, 220 insertions(+), 242 deletions(-) diff --git a/app/src/organisms/LabwareCard/__tests__/CustomLabwareOverflowMenu.test.tsx b/app/src/organisms/LabwareCard/__tests__/CustomLabwareOverflowMenu.test.tsx index 91f181c49a4..5d32f272816 100644 --- a/app/src/organisms/LabwareCard/__tests__/CustomLabwareOverflowMenu.test.tsx +++ b/app/src/organisms/LabwareCard/__tests__/CustomLabwareOverflowMenu.test.tsx @@ -67,33 +67,33 @@ describe('CustomLabwareOverflowMenu', () => { screen.getByRole('button', { name: 'Delete' }) }) - it('should call a mock function when canceling delete a labware definition', () => { + it('should call a mock function when canceling delete a labware definition', async () => { render(props) fireEvent.click(screen.getByLabelText('CustomLabwareOverflowMenu_button')) fireEvent.click(screen.getByRole('button', { name: 'Delete' })) - screen.getByText('Delete this labware definition?') - screen.getByText( + await screen.getByText('Delete this labware definition?') + await screen.getByText( 'This labware definition will be moved to this computer’s trash and may be unrecoverable.' ) - screen.getByText( + await screen.getByText( 'Robots cannot run Python protocols with missing labware definitions.' ) fireEvent.click(screen.getByText('cancel')) expect(mockCancel).toHaveBeenCalled() }) - it('should call a mock function when deleting a labware definition', () => { + it('should call a mock function when deleting a labware definition', async () => { render(props) fireEvent.click(screen.getByLabelText('CustomLabwareOverflowMenu_button')) fireEvent.click(screen.getByRole('button', { name: 'Delete' })) - // screen.getByText('Delete this labware definition?') - // screen.getByText( - // 'This labware definition will be moved to this computer’s trash and may be unrecoverable.' - // ) - // screen.getByText( - // 'Robots cannot run Python protocols with missing labware definitions.' - // ) - // fireEvent.click(screen.getByText('Yes, delete definition')) - // expect(mockConfirm).toHaveBeenCalled() + await screen.getByText('Delete this labware definition?') + await screen.getByText( + 'This labware definition will be moved to this computer’s trash and may be unrecoverable.' + ) + await screen.getByText( + 'Robots cannot run Python protocols with missing labware definitions.' + ) + fireEvent.click(screen.getByText('Yes, delete definition')) + expect(mockConfirm).toHaveBeenCalled() }) }) diff --git a/app/src/organisms/LabwareCard/__tests__/LabwareCard.test.tsx b/app/src/organisms/LabwareCard/__tests__/LabwareCard.test.tsx index 22b878ac92a..4058b6492b8 100644 --- a/app/src/organisms/LabwareCard/__tests__/LabwareCard.test.tsx +++ b/app/src/organisms/LabwareCard/__tests__/LabwareCard.test.tsx @@ -1,6 +1,6 @@ import * as React from 'react' import { screen } from '@testing-library/react' -import { describe, it, expect, vi, beforeEach } from 'vitest' +import { describe, it, vi, beforeEach } from 'vitest' import { renderWithProviders, nestedTextMatcher, diff --git a/app/src/organisms/LabwareDetails/StyledComponents/__tests__/ExpandingTitle.test.tsx b/app/src/organisms/LabwareDetails/StyledComponents/__tests__/ExpandingTitle.test.tsx index 807592f4c54..792a8eab2fa 100644 --- a/app/src/organisms/LabwareDetails/StyledComponents/__tests__/ExpandingTitle.test.tsx +++ b/app/src/organisms/LabwareDetails/StyledComponents/__tests__/ExpandingTitle.test.tsx @@ -1,6 +1,8 @@ import * as React from 'react' -import { fireEvent } from '@testing-library/react' -import { renderWithProviders, getFootprintDiagram } from '@opentrons/components' +import { fireEvent, screen } from '@testing-library/react' +import { describe, it, expect, beforeEach } from 'vitest' +import { getFootprintDiagram } from '@opentrons/components' +import { renderWithProviders } from '../../../../__testing-utils__' import { ExpandingTitle } from '../ExpandingTitle' const render = (props: React.ComponentProps) => { @@ -20,20 +22,20 @@ describe('ExpandingTitle', () => { }) it('renders correct label and button but does not render diagram initially', () => { - const [{ getByText, getByRole, queryByTestId }] = render(props) + render(props) - getByText('Title') - getByRole('button') - expect(queryByTestId(DIAGRAM_TEST_ID)).not.toBeInTheDocument() + screen.getByText('Title') + screen.getByRole('button') + expect(screen.queryByTestId(DIAGRAM_TEST_ID)).not.toBeInTheDocument() }) it('toggles rendering of diagram when button is clicked', () => { - const [{ getByRole, getByTestId, queryByTestId }] = render(props) + render(props) - const button = getByRole('button') + const button = screen.getByRole('button') fireEvent.click(button) - getByTestId(DIAGRAM_TEST_ID) + screen.getByTestId(DIAGRAM_TEST_ID) fireEvent.click(button) - expect(queryByTestId(DIAGRAM_TEST_ID)).not.toBeInTheDocument() + expect(screen.queryByTestId(DIAGRAM_TEST_ID)).not.toBeInTheDocument() }) }) diff --git a/app/src/organisms/LabwareDetails/StyledComponents/__tests__/LabeledValue.test.tsx b/app/src/organisms/LabwareDetails/StyledComponents/__tests__/LabeledValue.test.tsx index c95212add67..c410a7f556f 100644 --- a/app/src/organisms/LabwareDetails/StyledComponents/__tests__/LabeledValue.test.tsx +++ b/app/src/organisms/LabwareDetails/StyledComponents/__tests__/LabeledValue.test.tsx @@ -1,5 +1,7 @@ import * as React from 'react' -import { renderWithProviders } from '@opentrons/components' +import { screen } from '@testing-library/react' +import { describe, it, beforeEach } from 'vitest' +import { renderWithProviders } from '../../../../__testing-utils__' import { LabeledValue } from '../LabeledValue' const render = (props: React.ComponentProps) => { @@ -16,21 +18,21 @@ describe('LabeledValue', () => { }) it('renders correct label heading', () => { - const [{ getByRole }] = render(props) + render(props) - getByRole('heading', { name: 'height' }) + screen.getByRole('heading', { name: 'height' }) }) it('renders correct value when value is a string', () => { - const [{ getByText }] = render(props) + render(props) - getByText('42') + screen.getByText('42') }) it('renders correct value when value is a number', () => { props.value = 43 - const [{ getByText }] = render(props) + render(props) - getByText('43') + screen.getByText('43') }) }) diff --git a/app/src/organisms/LabwareDetails/__tests__/Dimensions.test.tsx b/app/src/organisms/LabwareDetails/__tests__/Dimensions.test.tsx index 7cd6dc82729..f6c864c9162 100644 --- a/app/src/organisms/LabwareDetails/__tests__/Dimensions.test.tsx +++ b/app/src/organisms/LabwareDetails/__tests__/Dimensions.test.tsx @@ -1,5 +1,7 @@ import * as React from 'react' -import { renderWithProviders } from '@opentrons/components' +import { screen } from '@testing-library/react' +import { describe, it, beforeEach } from 'vitest' +import { renderWithProviders } from '../../../__testing-utils__' import { i18n } from '../../../i18n' import { mockDefinition } from '../../../redux/custom-labware/__fixtures__' import { Dimensions } from '../Dimensions' @@ -19,11 +21,10 @@ describe('Dimensions', () => { }) it('renders correct label and headings', () => { - const [{ getByText, getByRole }] = render(props) - - getByText('Footprint (mm)') - getByRole('heading', { name: 'height' }) - getByRole('heading', { name: 'width' }) - getByRole('heading', { name: 'length' }) + render(props) + screen.getByText('Footprint (mm)') + screen.getByRole('heading', { name: 'height' }) + screen.getByRole('heading', { name: 'width' }) + screen.getByRole('heading', { name: 'length' }) }) }) diff --git a/app/src/organisms/LabwareDetails/__tests__/Gallery.test.tsx b/app/src/organisms/LabwareDetails/__tests__/Gallery.test.tsx index b986fe7d420..14a57ea51bc 100644 --- a/app/src/organisms/LabwareDetails/__tests__/Gallery.test.tsx +++ b/app/src/organisms/LabwareDetails/__tests__/Gallery.test.tsx @@ -1,9 +1,10 @@ import * as React from 'react' -import { renderWithProviders } from '@opentrons/components' +import { fireEvent, screen } from '@testing-library/react' +import { describe, it, expect, beforeEach } from 'vitest' +import { renderWithProviders } from '../../../__testing-utils__' import { mockDefinition } from '../../../redux/custom-labware/__fixtures__' import { labwareImages } from '../labware-images' import { Gallery } from '../Gallery' -import { fireEvent } from '@testing-library/react' const render = (props: React.ComponentProps) => { return renderWithProviders() @@ -22,33 +23,31 @@ describe('Gallery', () => { labwareImages.mock_definition = [] const [{ getByTestId, queryAllByTestId }] = render(props) - getByTestId('gallery_main_svg') + screen.getByTestId('gallery_main_svg') expect(queryAllByTestId('gallery_mini_image')).toHaveLength(0) }) it('renders one main SVG and two mini images if definition contains one image', () => { const [{ getByTestId, queryAllByTestId }] = render(props) - getByTestId('gallery_main_svg') + screen.getByTestId('gallery_main_svg') expect(queryAllByTestId('gallery_mini_image')).toHaveLength(2) }) it('renders image in main image when mini image is clicked', () => { - const [{ getAllByRole, queryAllByTestId }] = render(props) - - let images = getAllByRole('img') + render(props) + let images = screen.getAllByRole('img') expect(images).toHaveLength(1) - const miniImages = queryAllByTestId('gallery_mini_image') + const miniImages = screen.queryAllByTestId('gallery_mini_image') fireEvent.click(miniImages[1]) - images = getAllByRole('img') + images = screen.getAllByRole('img') expect(images).toHaveLength(2) }) it('renders one main SVG and three mini images if definition contains two images', () => { labwareImages.mock_definition = ['image1', 'image2'] - const [{ getByTestId, queryAllByTestId }] = render(props) - - getByTestId('gallery_main_svg') - expect(queryAllByTestId('gallery_mini_image')).toHaveLength(3) + render(props) + screen.getByTestId('gallery_main_svg') + expect(screen.queryAllByTestId('gallery_mini_image')).toHaveLength(3) }) }) diff --git a/app/src/organisms/LabwareDetails/__tests__/LabwareDetails.test.tsx b/app/src/organisms/LabwareDetails/__tests__/LabwareDetails.test.tsx index 23cb7cf4f0c..6567b404287 100644 --- a/app/src/organisms/LabwareDetails/__tests__/LabwareDetails.test.tsx +++ b/app/src/organisms/LabwareDetails/__tests__/LabwareDetails.test.tsx @@ -1,7 +1,8 @@ import * as React from 'react' import { fireEvent, screen } from '@testing-library/react' +import { describe, it, beforeEach, afterEach, vi, expect } from 'vitest' -import { renderWithProviders } from '@opentrons/components' +import { renderWithProviders } from '../../../__testing-utils__' import { i18n } from '../../../i18n' import { useAllLabware } from '../../../pages/Labware/hooks' import { mockOpentronsLabwareDetailsDefinition } from '../../../redux/custom-labware/__fixtures__' @@ -16,35 +17,15 @@ import { WellSpacing } from '../WellSpacing' import { LabwareDetails } from '..' -jest.mock('../../../pages/Labware/hooks') -jest.mock('../../LabwareCard/CustomLabwareOverflowMenu') -jest.mock('../Dimensions') -jest.mock('../Gallery') -jest.mock('../ManufacturerDetails') -jest.mock('../WellProperties') -jest.mock('../WellCount') -jest.mock('../WellDimensions') -jest.mock('../WellSpacing') - -const mockCustomLabwareOverflowMenu = CustomLabwareOverflowMenu as jest.MockedFunction< - typeof CustomLabwareOverflowMenu -> -const mockDimensions = Dimensions as jest.MockedFunction -const mockGallery = Gallery as jest.MockedFunction -const mockManufacturerDetails = ManufacturerDetails as jest.MockedFunction< - typeof ManufacturerDetails -> -const mockUseAllLabware = useAllLabware as jest.MockedFunction< - typeof useAllLabware -> -const mockWellCount = WellCount as jest.MockedFunction -const mockWellProperties = WellProperties as jest.MockedFunction< - typeof WellProperties -> -const mockWellDimensions = WellDimensions as jest.MockedFunction< - typeof WellDimensions -> -const mockWellSpacing = WellSpacing as jest.MockedFunction +vi.mock('../../../pages/Labware/hooks') +vi.mock('../../LabwareCard/CustomLabwareOverflowMenu') +vi.mock('../Dimensions') +vi.mock('../Gallery') +vi.mock('../ManufacturerDetails') +vi.mock('../WellProperties') +vi.mock('../WellCount') +vi.mock('../WellDimensions') +vi.mock('../WellSpacing') const render = ( props: React.ComponentProps @@ -57,43 +38,46 @@ const render = ( describe('LabwareDetails', () => { let props: React.ComponentProps beforeEach(() => { - mockCustomLabwareOverflowMenu.mockReturnValue( + vi.mocked(CustomLabwareOverflowMenu).mockReturnValue(
Mock CustomLabwareOverflowMenu
) - mockUseAllLabware.mockReturnValue([ + vi.mocked(useAllLabware).mockReturnValue([ { definition: mockOpentronsLabwareDetailsDefinition }, ]) - mockDimensions.mockReturnValue(
Mock Dimensions
) - mockGallery.mockReturnValue(
Mock Gallery
) - mockManufacturerDetails.mockReturnValue(
Mock ManufacturerDetails
) - mockWellCount.mockReturnValue(
Mock WellCount
) - mockWellProperties.mockReturnValue(
Mock WellProperties
) - mockWellDimensions.mockReturnValue(
Mock WellDimensions
) - mockWellSpacing.mockReturnValue(
Mock WellSpacing
) + vi.mocked(Dimensions).mockReturnValue(
Mock Dimensions
) + vi.mocked(Gallery).mockReturnValue(
Mock Gallery
) + vi.mocked(ManufacturerDetails).mockReturnValue( +
Mock ManufacturerDetails
+ ) + vi.mocked(WellCount).mockReturnValue(
Mock WellCount
) + vi.mocked(WellProperties).mockReturnValue(
Mock WellProperties
) + vi.mocked(WellDimensions).mockReturnValue(
Mock WellDimensions
) + vi.mocked(WellSpacing).mockReturnValue(
Mock WellSpacing
) + props = { labware: { definition: mockOpentronsLabwareDetailsDefinition, }, - onClose: jest.fn(), + onClose: vi.fn(), } }) afterEach(() => { - jest.resetAllMocks() + vi.resetAllMocks() }) it('should render correct info for opentrons labware', () => { - const [{ getByText }] = render(props) - getByText('Mock Definition') - getByText('Opentrons Definition') - getByText('API Name') - getByText('mock_definition') - getByText('Mock Dimensions') - getByText('Mock Gallery') - getByText('Mock ManufacturerDetails') - getByText('Mock WellCount') - getByText('Mock WellProperties') - getByText('Mock WellDimensions') - getByText('Mock WellSpacing') + render(props) + screen.getByText('Mock Definition') + screen.getByText('Opentrons Definition') + screen.getByText('API Name') + screen.getByText('mock_definition') + screen.getByText('Mock Dimensions') + screen.getByText('Mock Gallery') + screen.getByText('Mock ManufacturerDetails') + screen.getByText('Mock WellCount') + screen.getByText('Mock WellProperties') + screen.getByText('Mock WellDimensions') + screen.getByText('Mock WellSpacing') }) it('should no render Mock Well Dimensions, if a labware does not have groupMetaData', () => { diff --git a/app/src/organisms/LabwareDetails/__tests__/ManufacturerDetails.test.tsx b/app/src/organisms/LabwareDetails/__tests__/ManufacturerDetails.test.tsx index 8fb236c1386..925b8351bf4 100644 --- a/app/src/organisms/LabwareDetails/__tests__/ManufacturerDetails.test.tsx +++ b/app/src/organisms/LabwareDetails/__tests__/ManufacturerDetails.test.tsx @@ -1,5 +1,7 @@ import * as React from 'react' -import { renderWithProviders } from '@opentrons/components' +import { screen } from '@testing-library/react' +import { describe, it, expect, beforeEach } from 'vitest' +import { renderWithProviders } from '../../../__testing-utils__' import { i18n } from '../../../i18n' import { ManufacturerDetails } from '../ManufacturerDetails' @@ -18,28 +20,25 @@ describe('ManufacturerDetails', () => { }) it('renders correct heading and manufacturerValue and no links or brandId when only brand is passed as prop', () => { - const [{ getByRole, getByText, queryByRole }] = render(props) - - getByRole('heading', { name: 'manufacturer' }) - getByText('Opentrons') - expect(queryByRole('link')).not.toBeInTheDocument() + render(props) + screen.getByRole('heading', { name: 'manufacturer' }) + screen.getByText('Opentrons') + expect(screen.queryByRole('link')).not.toBeInTheDocument() expect( - queryByRole('heading', { name: 'manufacturer / catalog #' }) + screen.queryByRole('heading', { name: 'manufacturer / catalog #' }) ).not.toBeInTheDocument() }) it('renders correct number of links', () => { props.brand.links = ['https://www.opentrons.com', 'https://www.test.com'] - const [{ getAllByRole }] = render(props) - - expect(getAllByRole('link', { name: 'website' })).toHaveLength(2) + render(props) + expect(screen.getAllByRole('link', { name: 'website' })).toHaveLength(2) }) it('renders brandIds', () => { props.brand.brandId = ['mockId', 'mockId2'] - const [{ getByRole, getByText }] = render(props) - - getByRole('heading', { name: 'manufacturer / catalog #' }) - getByText('mockId, mockId2') + render(props) + screen.getByRole('heading', { name: 'manufacturer / catalog #' }) + screen.getByText('mockId, mockId2') }) }) diff --git a/app/src/organisms/LabwareDetails/__tests__/WellCount.test.tsx b/app/src/organisms/LabwareDetails/__tests__/WellCount.test.tsx index acd023bf971..b02d071a22b 100644 --- a/app/src/organisms/LabwareDetails/__tests__/WellCount.test.tsx +++ b/app/src/organisms/LabwareDetails/__tests__/WellCount.test.tsx @@ -1,5 +1,7 @@ import * as React from 'react' -import { renderWithProviders } from '@opentrons/components' +import { screen } from '@testing-library/react' +import { describe, it, beforeEach } from 'vitest' +import { renderWithProviders } from '../../../__testing-utils__' import { i18n } from '../../../i18n' import { WellCount } from '../WellCount' @@ -19,9 +21,8 @@ describe('WellCount', () => { }) it('renders correct label and count', () => { - const [{ getByText }] = render(props) - - getByText('mockLabel Count') - getByText('1') + render(props) + screen.getByText('mockLabel Count') + screen.getByText('1') }) }) diff --git a/app/src/organisms/LabwareDetails/__tests__/WellDimensions.test.tsx b/app/src/organisms/LabwareDetails/__tests__/WellDimensions.test.tsx index 993146a975a..f31ef09c86b 100644 --- a/app/src/organisms/LabwareDetails/__tests__/WellDimensions.test.tsx +++ b/app/src/organisms/LabwareDetails/__tests__/WellDimensions.test.tsx @@ -1,5 +1,7 @@ import * as React from 'react' -import { renderWithProviders } from '@opentrons/components' +import { screen } from '@testing-library/react' +import { describe, it, beforeEach, expect } from 'vitest' +import { renderWithProviders } from '../../../__testing-utils__' import { i18n } from '../../../i18n' import { mockDefinition, @@ -27,35 +29,35 @@ describe('WellDimensions', () => { }) it('renders correct label and headings for circular well', () => { - const [{ getByText, getByRole }] = render(props) + render(props) - getByText('mockLabel Measurements (mm) mockSuffix') - getByRole('heading', { name: 'depth' }) - getByRole('heading', { name: 'diameter' }) + screen.getByText('mockLabel Measurements (mm) mockSuffix') + screen.getByRole('heading', { name: 'depth' }) + screen.getByRole('heading', { name: 'diameter' }) }) it('renders correct label and headings for rectangular well', () => { props.wellProperties = mockRectangularLabwareWellGroupProperties - const [{ getByText, getByRole }] = render(props) + render(props) - getByText('mockLabel Measurements (mm) mockSuffix') - getByRole('heading', { name: 'depth' }) - getByRole('heading', { name: 'x-size' }) - getByRole('heading', { name: 'y-size' }) + screen.getByText('mockLabel Measurements (mm) mockSuffix') + screen.getByRole('heading', { name: 'depth' }) + screen.getByRole('heading', { name: 'x-size' }) + screen.getByRole('heading', { name: 'y-size' }) }) it('does not render total length heading when isTipRack is false', () => { - const [{ queryByRole }] = render(props) + render(props) expect( - queryByRole('heading', { name: 'total length' }) + screen.queryByRole('heading', { name: 'total length' }) ).not.toBeInTheDocument() }) it('renders correct heading when isTipRack is true', () => { props.labwareParams.isTiprack = true - const [{ getByRole }] = render(props) + render(props) - getByRole('heading', { name: 'total length' }) + screen.getByRole('heading', { name: 'total length' }) }) }) diff --git a/app/src/organisms/LabwareDetails/__tests__/WellProperties.test.tsx b/app/src/organisms/LabwareDetails/__tests__/WellProperties.test.tsx index 068b5fc5176..03852fd7f6f 100644 --- a/app/src/organisms/LabwareDetails/__tests__/WellProperties.test.tsx +++ b/app/src/organisms/LabwareDetails/__tests__/WellProperties.test.tsx @@ -1,5 +1,7 @@ import * as React from 'react' -import { renderWithProviders } from '@opentrons/components' +import { screen } from '@testing-library/react' +import { describe, it, expect, beforeEach } from 'vitest' +import { renderWithProviders } from '../../../__testing-utils__' import { i18n } from '../../../i18n' import { mockCircularLabwareWellGroupProperties } from '../../../redux/custom-labware/__fixtures__' import { WellProperties } from '../WellProperties' @@ -21,28 +23,28 @@ describe('WellProperties', () => { }) it('renders correct heading and label when wellBottomShape exists', () => { - const [{ getByText, getByRole }] = render(props) + render(props) - getByRole('heading', { name: 'max volume' }) - getByText('0.01 mL') - getByRole('heading', { name: 'mockLabel shape' }) - getByText('Flat_Bottom') + screen.getByRole('heading', { name: 'max volume' }) + screen.getByText('0.01 mL') + screen.getByRole('heading', { name: 'mockLabel shape' }) + screen.getByText('Flat_Bottom') }) it('does not render wellBottomShape section when wellBottomShape is null', () => { props.wellProperties.metadata.wellBottomShape = undefined - const [{ queryByRole }] = render(props) + render(props) expect( - queryByRole('heading', { name: 'mockLabel shape' }) + screen.queryByRole('heading', { name: 'mockLabel shape' }) ).not.toBeInTheDocument() }) it('renders correct label when volume is null', () => { props.wellProperties.totalLiquidVolume = null - const [{ queryByText, getByText }] = render(props) + render(props) - expect(queryByText('0.01 mL')).not.toBeInTheDocument() - getByText('various') + expect(screen.queryByText('0.01 mL')).not.toBeInTheDocument() + screen.getByText('various') }) }) diff --git a/app/src/organisms/LabwareDetails/__tests__/WellSpacing.test.tsx b/app/src/organisms/LabwareDetails/__tests__/WellSpacing.test.tsx index 1a1da021671..c2273e705ee 100644 --- a/app/src/organisms/LabwareDetails/__tests__/WellSpacing.test.tsx +++ b/app/src/organisms/LabwareDetails/__tests__/WellSpacing.test.tsx @@ -1,5 +1,7 @@ import * as React from 'react' -import { renderWithProviders } from '@opentrons/components' +import { screen } from '@testing-library/react' +import { describe, it, beforeEach, expect } from 'vitest' +import { renderWithProviders } from '../../../__testing-utils__' import { i18n } from '../../../i18n' import { mockCircularLabwareWellGroupProperties } from '../../../redux/custom-labware/__fixtures__' import { WellSpacing } from '../WellSpacing' @@ -24,18 +26,18 @@ describe('WellSpacing', () => { xSpacing: 2.22227, ySpacing: 2.22227, } - const [{ getAllByText }] = render(props) - expect(getAllByText('2.22')).toHaveLength(2) + render(props) + expect(screen.getAllByText('2.22')).toHaveLength(2) }) it('renders correct labels when xSpacing and ySpacing have values', () => { - const [{ getAllByText, getByRole }] = render(props) + render(props) - getByRole('heading', { name: 'x-offset' }) - getByRole('heading', { name: 'y-offset' }) - getByRole('heading', { name: 'x-spacing' }) - getByRole('heading', { name: 'y-spacing' }) - expect(getAllByText('1.00')).toHaveLength(4) + screen.getByRole('heading', { name: 'x-offset' }) + screen.getByRole('heading', { name: 'y-offset' }) + screen.getByRole('heading', { name: 'x-spacing' }) + screen.getByRole('heading', { name: 'y-spacing' }) + expect(screen.getAllByText('1.00')).toHaveLength(4) }) it('renders correct labels when xSpacing and ySpacing are null', () => { @@ -44,9 +46,9 @@ describe('WellSpacing', () => { xSpacing: null, ySpacing: null, } - const [{ getAllByText }] = render(props) + render(props) - expect(getAllByText('1.00')).toHaveLength(2) - expect(getAllByText('various')).toHaveLength(2) + expect(screen.getAllByText('1.00')).toHaveLength(2) + expect(screen.getAllByText('various')).toHaveLength(2) }) }) diff --git a/app/src/organisms/LabwareOffsetTabs/__tests__/LabwareOffsetTabs.test.tsx b/app/src/organisms/LabwareOffsetTabs/__tests__/LabwareOffsetTabs.test.tsx index bb871b98c56..aa313000b9c 100644 --- a/app/src/organisms/LabwareOffsetTabs/__tests__/LabwareOffsetTabs.test.tsx +++ b/app/src/organisms/LabwareOffsetTabs/__tests__/LabwareOffsetTabs.test.tsx @@ -1,8 +1,9 @@ import * as React from 'react' -import { renderWithProviders } from '@opentrons/components' +import { fireEvent, screen } from '@testing-library/react' +import { describe, it, expect } from 'vitest' +import { renderWithProviders } from '../../../__testing-utils__' import { i18n } from '../../../i18n' import { LabwareOffsetTabs } from '..' -import { fireEvent, screen } from '@testing-library/react' const mockTableComponent =
Table Component
const mockJupyterComponent =
Jupyter Component
diff --git a/app/src/organisms/LabwarePositionCheck/__fixtures__/mockLabwareDef.ts b/app/src/organisms/LabwarePositionCheck/__fixtures__/mockLabwareDef.ts index d4c4bf4c064..450d7754a98 100644 --- a/app/src/organisms/LabwarePositionCheck/__fixtures__/mockLabwareDef.ts +++ b/app/src/organisms/LabwarePositionCheck/__fixtures__/mockLabwareDef.ts @@ -1,8 +1,8 @@ +import { fixture96Plate } from '@opentrons/shared-data' import type { LabwareDefinition2 } from '@opentrons/shared-data' -import fixture_96_plate from '@opentrons/shared-data/labware/fixtures/2/fixture_96_plate.json' export const mockLabwareDef: LabwareDefinition2 = { - ...(fixture_96_plate as LabwareDefinition2), + ...(fixture96Plate as LabwareDefinition2), metadata: { displayName: 'Mock Labware Definition', displayCategory: 'wellPlate', diff --git a/app/src/organisms/LabwarePositionCheck/__fixtures__/mockTipRackDef.ts b/app/src/organisms/LabwarePositionCheck/__fixtures__/mockTipRackDef.ts index 7b75835ce92..0c7288b338a 100644 --- a/app/src/organisms/LabwarePositionCheck/__fixtures__/mockTipRackDef.ts +++ b/app/src/organisms/LabwarePositionCheck/__fixtures__/mockTipRackDef.ts @@ -1,8 +1,8 @@ +import { fixtureTiprack10ul } from '@opentrons/shared-data' import type { LabwareDefinition2 } from '@opentrons/shared-data' -import fixture_tiprack_10_ul from '@opentrons/shared-data/labware/fixtures/2/fixture_tiprack_10_ul.json' export const mockTipRackDef: LabwareDefinition2 = { - ...(fixture_tiprack_10_ul as LabwareDefinition2), + ...(fixtureTiprack10ul as LabwareDefinition2), metadata: { displayName: 'Mock TipRack Definition', displayCategory: 'tipRack', diff --git a/app/src/organisms/LabwarePositionCheck/__tests__/ReturnTip.test.tsx b/app/src/organisms/LabwarePositionCheck/__tests__/ReturnTip.test.tsx index 645f121b8df..e2667c7f4e6 100644 --- a/app/src/organisms/LabwarePositionCheck/__tests__/ReturnTip.test.tsx +++ b/app/src/organisms/LabwarePositionCheck/__tests__/ReturnTip.test.tsx @@ -1,23 +1,19 @@ import * as React from 'react' -import { renderWithProviders } from '@opentrons/components' +import { fireEvent, screen } from '@testing-library/react' +import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest' + import { FLEX_ROBOT_TYPE, HEATERSHAKER_MODULE_V1 } from '@opentrons/shared-data' + +import { renderWithProviders } from '../../../__testing-utils__' import { i18n } from '../../../i18n' -import { ReturnTip } from '../ReturnTip' import { SECTIONS } from '../constants' import { mockCompletedAnalysis } from '../__fixtures__' import { useProtocolMetadata } from '../../Devices/hooks' import { getIsOnDevice } from '../../../redux/config' -import { fireEvent, screen } from '@testing-library/react' - -jest.mock('../../Devices/hooks') -jest.mock('../../../redux/config') +import { ReturnTip } from '../ReturnTip' -const mockUseProtocolMetaData = useProtocolMetadata as jest.MockedFunction< - typeof useProtocolMetadata -> -const mockGetIsOnDevice = getIsOnDevice as jest.MockedFunction< - typeof getIsOnDevice -> +vi.mock('../../Devices/hooks') +vi.mock('../../../redux/config') const render = (props: React.ComponentProps) => { return renderWithProviders(, { @@ -30,8 +26,8 @@ describe('ReturnTip', () => { let mockChainRunCommands beforeEach(() => { - mockChainRunCommands = jest.fn().mockImplementation(() => Promise.resolve()) - mockGetIsOnDevice.mockReturnValue(false) + mockChainRunCommands = vi.fn().mockImplementation(() => Promise.resolve()) + vi.mocked(getIsOnDevice).mockReturnValue(false) props = { section: SECTIONS.RETURN_TIP, pipetteId: mockCompletedAnalysis.pipettes[0].id, @@ -39,17 +35,19 @@ describe('ReturnTip', () => { definitionUri: mockCompletedAnalysis.labware[0].definitionUri, location: { slotName: 'D1' }, protocolData: mockCompletedAnalysis, - proceed: jest.fn(), - setFatalError: jest.fn(), + proceed: vi.fn(), + setFatalError: vi.fn(), chainRunCommands: mockChainRunCommands, tipPickUpOffset: null, isRobotMoving: false, robotType: FLEX_ROBOT_TYPE, } - mockUseProtocolMetaData.mockReturnValue({ robotType: 'OT-3 Standard' }) + vi.mocked(useProtocolMetadata).mockReturnValue({ + robotType: 'OT-3 Standard', + }) }) afterEach(() => { - jest.restoreAllMocks() + vi.restoreAllMocks() }) it('renders correct copy on desktop', () => { render(props) @@ -66,7 +64,7 @@ describe('ReturnTip', () => { screen.getByRole('link', { name: 'Need help?' }) }) it('renders correct copy on device', () => { - mockGetIsOnDevice.mockReturnValue(true) + vi.mocked(getIsOnDevice).mockReturnValue(true) render(props) screen.getByRole('heading', { name: 'Return tip rack to Slot D1' }) screen.getByText('Clear all deck slots of labware') diff --git a/app/src/organisms/LabwarePositionCheck/__tests__/RobotMotionLoader.test.tsx b/app/src/organisms/LabwarePositionCheck/__tests__/RobotMotionLoader.test.tsx index beed71303b9..70b969568e6 100644 --- a/app/src/organisms/LabwarePositionCheck/__tests__/RobotMotionLoader.test.tsx +++ b/app/src/organisms/LabwarePositionCheck/__tests__/RobotMotionLoader.test.tsx @@ -1,7 +1,9 @@ import * as React from 'react' -import { renderWithProviders } from '@opentrons/components' -import { RobotMotionLoader } from '../RobotMotionLoader' +import { screen } from '@testing-library/react' +import { describe, it } from 'vitest' +import { renderWithProviders } from '../../../__testing-utils__' import { i18n } from '../../../i18n' +import { RobotMotionLoader } from '../RobotMotionLoader' const mockHeader = 'Stand back, robot needs some space right now' @@ -13,7 +15,7 @@ const render = () => { describe('Robot in Motion Modal', () => { it('should render robot in motion loader with header', () => { - const { getByRole } = render() - getByRole('heading', { name: mockHeader }) + render() + screen.getByRole('heading', { name: mockHeader }) }) }) diff --git a/app/src/organisms/LabwarePositionCheck/__tests__/useLaunchLPC.test.tsx b/app/src/organisms/LabwarePositionCheck/__tests__/useLaunchLPC.test.tsx index 3c8965a2204..164efc56076 100644 --- a/app/src/organisms/LabwarePositionCheck/__tests__/useLaunchLPC.test.tsx +++ b/app/src/organisms/LabwarePositionCheck/__tests__/useLaunchLPC.test.tsx @@ -1,7 +1,7 @@ import * as React from 'react' import { Provider } from 'react-redux' import configureStore from 'redux-mock-store' -import { when, resetAllWhenMocks } from 'jest-when' +import { when } from 'vitest-when' import { act, fireEvent, @@ -9,17 +9,18 @@ import { screen, waitFor, } from '@testing-library/react' +import { describe, it, beforeEach, afterEach, vi, expect } from 'vitest' import { QueryClient, QueryClientProvider } from 'react-query' -import { renderWithProviders } from '@opentrons/components' import { useCreateMaintenanceRunLabwareDefinitionMutation, useDeleteMaintenanceRunMutation, } from '@opentrons/react-api-client' import { FLEX_ROBOT_TYPE } from '@opentrons/shared-data' +import { renderWithProviders } from '../../../__testing-utils__' import { useCreateTargetedMaintenanceRunMutation } from '../../../resources/runs/hooks' -import fixture_tiprack_300_ul from '@opentrons/shared-data/labware/fixtures/2/fixture_tiprack_300_ul.json' +import { fixtureTiprack300ul } from '@opentrons/shared-data' import { useMostRecentCompletedAnalysis } from '../useMostRecentCompletedAnalysis' import { useNotifyRunQuery } from '../../../resources/runs/useNotifyRunQuery' import { useLaunchLPC } from '../useLaunchLPC' @@ -28,30 +29,12 @@ import { LabwarePositionCheck } from '..' import type { LabwareOffset } from '@opentrons/api-client' import type { LabwareDefinition2 } from '@opentrons/shared-data' -jest.mock('../') -jest.mock('@opentrons/react-api-client') -jest.mock('../../../resources/runs/hooks') -jest.mock('../useMostRecentCompletedAnalysis') -jest.mock('../../../resources/runs/useNotifyRunQuery') +vi.mock('../') +vi.mock('@opentrons/react-api-client') +vi.mock('../../../resources/runs/hooks') +vi.mock('../useMostRecentCompletedAnalysis') +vi.mock('../../../resources/runs/useNotifyRunQuery') -const mockUseCreateTargetedMaintenanceRunMutation = useCreateTargetedMaintenanceRunMutation as jest.MockedFunction< - typeof useCreateTargetedMaintenanceRunMutation -> -const mockUseCreateMaintenanceRunLabwareDefinitionMutation = useCreateMaintenanceRunLabwareDefinitionMutation as jest.MockedFunction< - typeof useCreateMaintenanceRunLabwareDefinitionMutation -> -const mockUseDeleteMaintenanceRunMutation = useDeleteMaintenanceRunMutation as jest.MockedFunction< - typeof useDeleteMaintenanceRunMutation -> -const mockUseNotifyRunQuery = useNotifyRunQuery as jest.MockedFunction< - typeof useNotifyRunQuery -> -const mockUseMostRecentCompletedAnalysis = useMostRecentCompletedAnalysis as jest.MockedFunction< - typeof useMostRecentCompletedAnalysis -> -const mockLabwarePositionCheck = LabwarePositionCheck as jest.MockedFunction< - typeof LabwarePositionCheck -> const MOCK_RUN_ID = 'mockRunId' const MOCK_MAINTENANCE_RUN_ID = 'mockMaintenanceRunId' const mockCurrentOffsets: LabwareOffset[] = [ @@ -71,26 +54,26 @@ const mockCurrentOffsets: LabwareOffset[] = [ vector: { x: 0, y: 0, z: 0 }, }, ] -const mockLabwareDef = fixture_tiprack_300_ul as LabwareDefinition2 +const mockLabwareDef = fixtureTiprack300ul as LabwareDefinition2 describe('useLaunchLPC hook', () => { let wrapper: React.FunctionComponent<{ children: React.ReactNode }> - let mockCreateMaintenanceRun: jest.Mock - let mockCreateLabwareDefinition: jest.Mock - let mockDeleteMaintenanceRun: jest.Mock + let mockCreateMaintenanceRun: vi.Mock + let mockCreateLabwareDefinition: vi.Mock + let mockDeleteMaintenanceRun: vi.Mock const mockStore = configureStore() beforeEach(() => { const queryClient = new QueryClient() - mockCreateMaintenanceRun = jest.fn((_data, opts) => { + mockCreateMaintenanceRun = vi.fn((_data, opts) => { const results = { data: { id: MOCK_MAINTENANCE_RUN_ID } } opts?.onSuccess(results) return Promise.resolve(results) }) - mockCreateLabwareDefinition = jest.fn(_data => + mockCreateLabwareDefinition = vi.fn(_data => Promise.resolve({ data: { definitionUri: 'fakeDefUri' } }) ) - mockDeleteMaintenanceRun = jest.fn((_data, opts) => { + mockDeleteMaintenanceRun = vi.fn((_data, opts) => { opts?.onSettled() }) const store = mockStore({ isOnDevice: false }) @@ -101,7 +84,7 @@ describe('useLaunchLPC hook', () => { ) - mockLabwarePositionCheck.mockImplementation(({ onCloseClick }) => ( + vi.mocked(LabwarePositionCheck).mockImplementation(({ onCloseClick }) => (
{ onCloseClick() @@ -110,33 +93,33 @@ describe('useLaunchLPC hook', () => { exit
)) - when(mockUseNotifyRunQuery) + when(vi.mocked(useNotifyRunQuery)) .calledWith(MOCK_RUN_ID, { staleTime: Infinity }) - .mockReturnValue({ + .thenReturn({ data: { data: { labwareOffsets: mockCurrentOffsets, }, }, } as any) - when(mockUseCreateTargetedMaintenanceRunMutation) + when(vi.mocked(useCreateTargetedMaintenanceRunMutation)) .calledWith() - .mockReturnValue({ + .thenReturn({ createTargetedMaintenanceRun: mockCreateMaintenanceRun, } as any) - when(mockUseCreateMaintenanceRunLabwareDefinitionMutation) + when(vi.mocked(useCreateMaintenanceRunLabwareDefinitionMutation)) .calledWith() - .mockReturnValue({ + .thenReturn({ createLabwareDefinition: mockCreateLabwareDefinition, } as any) - when(mockUseDeleteMaintenanceRunMutation) + when(vi.mocked(useDeleteMaintenanceRunMutation)) .calledWith() - .mockReturnValue({ + .thenReturn({ deleteMaintenanceRun: mockDeleteMaintenanceRun, } as any) - when(mockUseMostRecentCompletedAnalysis) + when(vi.mocked(useMostRecentCompletedAnalysis)) .calledWith(MOCK_RUN_ID) - .mockReturnValue({ + .thenReturn({ commands: [ { key: 'CommandKey0', @@ -162,8 +145,7 @@ describe('useLaunchLPC hook', () => { } as any) }) afterEach(() => { - resetAllWhenMocks() - jest.resetAllMocks() + vi.resetAllMocks() }) it('returns and no wizard by default', () => { diff --git a/app/src/organisms/LabwarePositionCheck/utils/__tests__/doesPipetteVisitAllTipracks.test.ts b/app/src/organisms/LabwarePositionCheck/utils/__tests__/doesPipetteVisitAllTipracks.test.ts index e5074491ceb..d3c7b511c58 100644 --- a/app/src/organisms/LabwarePositionCheck/utils/__tests__/doesPipetteVisitAllTipracks.test.ts +++ b/app/src/organisms/LabwarePositionCheck/utils/__tests__/doesPipetteVisitAllTipracks.test.ts @@ -1,6 +1,6 @@ +import { describe, it, expect } from 'vitest' import { doesPipetteVisitAllTipracks } from '../doesPipetteVisitAllTipracks' -import _uncastedProtocolMultipleTipracks from '@opentrons/shared-data/protocol/fixtures/6/multipleTipracks.json' -import _uncastedProtocolOneTiprack from '@opentrons/shared-data/protocol/fixtures/6/oneTiprack.json' +import { multiple_tipracks, one_tiprack } from '@opentrons/shared-data' import type { LoadedLabware, ProtocolAnalysisOutput, @@ -8,10 +8,10 @@ import type { } from '@opentrons/shared-data' // TODO: update these fixtures to be v6 protocols -const protocolMultipleTipracks = (_uncastedProtocolMultipleTipracks as unknown) as ProtocolAnalysisOutput -const labwareDefinitionsMultipleTipracks = _uncastedProtocolMultipleTipracks.labwareDefinitions as {} -const protocolOneTiprack = (_uncastedProtocolOneTiprack as unknown) as ProtocolAnalysisOutput -const labwareDefinitionsOneTiprack = _uncastedProtocolOneTiprack.labwareDefinitions as {} +const protocolMultipleTipracks = (multiple_tipracks as unknown) as ProtocolAnalysisOutput +const labwareDefinitionsMultipleTipracks = multiple_tipracks.labwareDefinitions as {} +const protocolOneTiprack = (one_tiprack as unknown) as ProtocolAnalysisOutput +const labwareDefinitionsOneTiprack = one_tiprack.labwareDefinitions as {} const labwareWithDefinitionUri = [ { id: 'fixedTrash', diff --git a/app/src/organisms/LabwarePositionCheck/utils/__tests__/getPrimaryPipetteId.test.ts b/app/src/organisms/LabwarePositionCheck/utils/__tests__/getPrimaryPipetteId.test.ts index 03e18437fac..7256c0245e8 100644 --- a/app/src/organisms/LabwarePositionCheck/utils/__tests__/getPrimaryPipetteId.test.ts +++ b/app/src/organisms/LabwarePositionCheck/utils/__tests__/getPrimaryPipetteId.test.ts @@ -1,3 +1,4 @@ +import { describe, it, expect } from 'vitest' import { getPrimaryPipetteId } from '../getPrimaryPipetteId' import type { LoadedPipette,