From 92f9d817aa1c0a4f4a4abdb7a1a7c4a6d4bbdf4b Mon Sep 17 00:00:00 2001 From: Jethary Date: Mon, 4 Mar 2024 14:34:53 -0500 Subject: [PATCH] migrate 3 more tests --- .../DeviceDetailsDeckConfiguration.test.tsx | 41 +- .../__tests__/CheckItem.test.tsx | 418 +++++------------- .../__tests__/ProtocolDetails.test.tsx | 17 +- 3 files changed, 134 insertions(+), 342 deletions(-) diff --git a/app/src/organisms/DeviceDetailsDeckConfiguration/__tests__/DeviceDetailsDeckConfiguration.test.tsx b/app/src/organisms/DeviceDetailsDeckConfiguration/__tests__/DeviceDetailsDeckConfiguration.test.tsx index 81f86fc1036..65ef607fc35 100644 --- a/app/src/organisms/DeviceDetailsDeckConfiguration/__tests__/DeviceDetailsDeckConfiguration.test.tsx +++ b/app/src/organisms/DeviceDetailsDeckConfiguration/__tests__/DeviceDetailsDeckConfiguration.test.tsx @@ -9,10 +9,7 @@ import { useUpdateDeckConfigurationMutation, } from '@opentrons/react-api-client' -import { - partialComponentPropsMatcher, - renderWithProviders, -} from '../../../__testing-utils__' +import { renderWithProviders } from '../../../__testing-utils__' import { i18n } from '../../../i18n' import { useIsRobotViewable, useRunStatuses } from '../../Devices/hooks' import { DeckFixtureSetupInstructionsModal } from '../DeckFixtureSetupInstructionsModal' @@ -21,8 +18,15 @@ import { DeviceDetailsDeckConfiguration } from '../' import { useNotifyCurrentMaintenanceRun } from '../../../resources/maintenance_runs/useNotifyCurrentMaintenanceRun' import type { MaintenanceRun } from '@opentrons/api-client' - -vi.mock('@opentrons/components/src/hardware-sim/DeckConfigurator/index') +import type * as OpentronsComponents from '@opentrons/components' + +vi.mock('@opentrons/components', async importOriginal => { + const actual = await importOriginal() + return { + ...actual, + DeckConfigurator: vi.fn(), + } +}) vi.mock('@opentrons/react-api-client') vi.mock('../DeckFixtureSetupInstructionsModal') vi.mock('../../Devices/hooks') @@ -63,7 +67,7 @@ describe('DeviceDetailsDeckConfiguration', () => { vi.mocked(DeckFixtureSetupInstructionsModal).mockReturnValue(
mock DeckFixtureSetupInstructionsModal
) - when(vi.mocked(DeckConfigurator)).thenReturn( + vi.mocked(DeckConfigurator).mockReturnValue(
mock DeckConfigurator
) vi.mocked(useRunStatuses).mockReturnValue(RUN_STATUSES) @@ -98,9 +102,9 @@ describe('DeviceDetailsDeckConfiguration', () => { it('should render banner and make deck configurator disabled when running', () => { RUN_STATUSES.isRunRunning = true vi.mocked(useRunStatuses).mockReturnValue(RUN_STATUSES) - when(vi.mocked(DeckConfigurator)) - .calledWith(partialComponentPropsMatcher({ readOnly: true })) - .thenReturn(
disabled mock DeckConfigurator
) + vi.mocked(DeckConfigurator).mockReturnValue( +
disabled mock DeckConfigurator
+ ) render(props) screen.getByText( 'Deck configuration is not available when run is in progress' @@ -112,9 +116,9 @@ describe('DeviceDetailsDeckConfiguration', () => { vi.mocked(useNotifyCurrentMaintenanceRun).mockReturnValue({ data: mockCurrnetMaintenanceRun, } as any) - when(vi.mocked(DeckConfigurator)) - .calledWith(partialComponentPropsMatcher({ readOnly: true })) - .thenReturn(
disabled mock DeckConfigurator
) + vi.mocked(DeckConfigurator).mockReturnValue( +
disabled mock DeckConfigurator
+ ) render(props) screen.getByText( 'Deck configuration is not available when the robot is busy' @@ -123,9 +127,8 @@ describe('DeviceDetailsDeckConfiguration', () => { }) it('should render no deck fixtures, if deck configs are not set', () => { - when(vi.mocked(useDeckConfigurationQuery)) - .calledWith() - .thenReturn([] as any) + vi.mocked(useDeckConfigurationQuery) + .mockReturnValue([] as any) render(props) screen.getByText('No deck fixtures') }) @@ -134,9 +137,9 @@ describe('DeviceDetailsDeckConfiguration', () => { when(vi.mocked(useIsEstopNotDisengaged)) .calledWith(ROBOT_NAME) .thenReturn(true) - when(vi.mocked(DeckConfigurator)) - .calledWith(partialComponentPropsMatcher({ readOnly: true })) - .thenReturn(
disabled mock DeckConfigurator
) + vi.mocked(DeckConfigurator).mockReturnValue( +
disabled mock DeckConfigurator
+ ) render(props) screen.getByText('disabled mock DeckConfigurator') }) diff --git a/app/src/organisms/LabwarePositionCheck/__tests__/CheckItem.test.tsx b/app/src/organisms/LabwarePositionCheck/__tests__/CheckItem.test.tsx index 50b3c1ff1a6..13ef9a8cb4b 100644 --- a/app/src/organisms/LabwarePositionCheck/__tests__/CheckItem.test.tsx +++ b/app/src/organisms/LabwarePositionCheck/__tests__/CheckItem.test.tsx @@ -94,45 +94,22 @@ describe('CheckItem', () => { screen.getByRole('button', { name: 'Confirm placement' }) }) it('executes correct chained commands when confirm placement CTA is clicked then go back', async () => { - when(mockChainRunCommands) - .calledWith( - [ - { - commandType: 'moveLabware', - params: { - labwareId: 'labwareId1', - newLocation: { slotName: 'D1' }, - strategy: 'manualMoveWithoutPause', - }, - }, - { - commandType: 'moveToWell', - params: { - pipetteId: 'pipetteId1', - labwareId: 'labwareId1', - wellName: 'A1', - wellLocation: { origin: 'top', offset: { x: 0, y: 0, z: 44.5 } }, - }, - }, - { commandType: 'savePosition', params: { pipetteId: 'pipetteId1' } }, - ], - false - ) - .mockImplementation(() => - Promise.resolve([ - {}, - {}, - { - data: { - commandType: 'savePosition', - result: { position: mockStartPosition }, - }, + vi.mocked(mockChainRunCommands).mockImplementation(() => + Promise.resolve([ + {}, + {}, + { + data: { + commandType: 'savePosition', + result: { position: mockStartPosition }, }, - ]) - ) + }, + ]) + ) const { getByRole } = render(props) fireEvent.click(getByRole('button', { name: 'Confirm placement' })) - await expect(props.chainRunCommands).toHaveBeenNthCalledWith( + await new Promise(r => setTimeout(r)) + expect(props.chainRunCommands).toHaveBeenNthCalledWith( 1, [ { @@ -159,7 +136,7 @@ describe('CheckItem', () => { ], false ) - await expect(props.registerPosition).toHaveBeenNthCalledWith(1, { + expect(props.registerPosition).toHaveBeenNthCalledWith(1, { type: 'initialPosition', labwareId: 'labwareId1', location: { slotName: 'D1' }, @@ -172,45 +149,22 @@ describe('CheckItem', () => { robotType: OT2_ROBOT_TYPE, location: { slotName: '1' }, } - when(mockChainRunCommands) - .calledWith( - [ - { - commandType: 'moveLabware', - params: { - labwareId: 'labwareId1', - newLocation: { slotName: '1' }, - strategy: 'manualMoveWithoutPause', - }, - }, - { - commandType: 'moveToWell', - params: { - pipetteId: 'pipetteId1', - labwareId: 'labwareId1', - wellName: 'A1', - wellLocation: { origin: 'top', offset: { x: 0, y: 0, z: 0 } }, - }, - }, - { commandType: 'savePosition', params: { pipetteId: 'pipetteId1' } }, - ], - false - ) - .mockImplementation(() => - Promise.resolve([ - {}, - {}, - { - data: { - commandType: 'savePosition', - result: { position: mockStartPosition }, - }, + vi.mocked(mockChainRunCommands).mockImplementation(() => + Promise.resolve([ + {}, + {}, + { + data: { + commandType: 'savePosition', + result: { position: mockStartPosition }, }, - ]) - ) + }, + ]) + ) const { getByRole } = render(props) fireEvent.click(getByRole('button', { name: 'Confirm placement' })) - await expect(props.chainRunCommands).toHaveBeenNthCalledWith( + await new Promise(r => setTimeout(r)) + expect(props.chainRunCommands).toHaveBeenNthCalledWith( 1, [ { @@ -237,7 +191,7 @@ describe('CheckItem', () => { ], false ) - await expect(props.registerPosition).toHaveBeenNthCalledWith(1, { + expect(props.registerPosition).toHaveBeenNthCalledWith(1, { type: 'initialPosition', labwareId: 'labwareId1', location: { slotName: '1' }, @@ -247,45 +201,22 @@ describe('CheckItem', () => { it('executes correct chained commands when confirm placement CTA is clicked then go back on Flex', async () => { props = { ...props, robotType: FLEX_ROBOT_TYPE } - when(mockChainRunCommands) - .calledWith( - [ - { - commandType: 'moveLabware', - params: { - labwareId: 'labwareId1', - newLocation: { slotName: 'D1' }, - strategy: 'manualMoveWithoutPause', - }, - }, - { - commandType: 'moveToWell', - params: { - pipetteId: 'pipetteId1', - labwareId: 'labwareId1', - wellName: 'A1', - wellLocation: { origin: 'top', offset: { x: 0, y: 0, z: 44.5 } }, - }, - }, - { commandType: 'savePosition', params: { pipetteId: 'pipetteId1' } }, - ], - false - ) - .mockImplementation(() => - Promise.resolve([ - {}, - {}, - { - data: { - commandType: 'savePosition', - result: { position: mockStartPosition }, - }, + vi.mocked(mockChainRunCommands).mockImplementation(() => + Promise.resolve([ + {}, + {}, + { + data: { + commandType: 'savePosition', + result: { position: mockStartPosition }, }, - ]) - ) + }, + ]) + ) const { getByRole } = render(props) fireEvent.click(getByRole('button', { name: 'Confirm placement' })) - await expect(props.chainRunCommands).toHaveBeenNthCalledWith( + await new Promise(r => setTimeout(r)) + expect(props.chainRunCommands).toHaveBeenNthCalledWith( 1, [ { @@ -312,7 +243,7 @@ describe('CheckItem', () => { ], false ) - await expect(props.registerPosition).toHaveBeenNthCalledWith(1, { + expect(props.registerPosition).toHaveBeenNthCalledWith(1, { type: 'initialPosition', labwareId: 'labwareId1', location: { slotName: 'D1' }, @@ -339,53 +270,22 @@ describe('CheckItem', () => { ...props, adapterId: 'labwareId2', } - when(mockChainRunCommands) - .calledWith( - [ - { - commandType: 'moveLabware', - params: { - labwareId: 'labwareId2', - newLocation: { slotName: 'D1' }, - strategy: 'manualMoveWithoutPause', - }, - }, - { - commandType: 'moveLabware', - params: { - labwareId: 'labwareId1', - newLocation: { labwareId: 'labwareId2' }, - strategy: 'manualMoveWithoutPause', - }, - }, - { - commandType: 'moveToWell', - params: { - pipetteId: 'pipetteId1', - labwareId: 'labwareId1', - wellName: 'A1', - wellLocation: { origin: 'top', offset: { x: 0, y: 0, z: 44.5 } }, - }, - }, - { commandType: 'savePosition', params: { pipetteId: 'pipetteId1' } }, - ], - false - ) - .mockImplementation(() => - Promise.resolve([ - {}, - {}, - { - data: { - commandType: 'savePosition', - result: { position: mockStartPosition }, - }, + vi.mocked(mockChainRunCommands).mockImplementation(() => + Promise.resolve([ + {}, + {}, + { + data: { + commandType: 'savePosition', + result: { position: mockStartPosition }, }, - ]) - ) + }, + ]) + ) const { getByRole } = render(props) fireEvent.click(getByRole('button', { name: 'Confirm placement' })) - await expect(props.chainRunCommands).toHaveBeenNthCalledWith( + await new Promise(r => setTimeout(r)) + expect(props.chainRunCommands).toHaveBeenNthCalledWith( 1, [ { @@ -420,7 +320,7 @@ describe('CheckItem', () => { ], false ) - await expect(props.registerPosition).toHaveBeenNthCalledWith(1, { + expect(props.registerPosition).toHaveBeenNthCalledWith(1, { type: 'initialPosition', labwareId: 'labwareId1', location: { slotName: 'D1' }, @@ -441,8 +341,8 @@ describe('CheckItem', () => { } const { getByRole } = render(props) fireEvent.click(getByRole('button', { name: 'Go back' })) - - await expect(props.chainRunCommands).toHaveBeenNthCalledWith( + await new Promise(r => setTimeout(r)) + expect(props.chainRunCommands).toHaveBeenNthCalledWith( 1, [ { commandType: 'home', params: {} }, @@ -457,7 +357,7 @@ describe('CheckItem', () => { ], false ) - await expect(props.registerPosition).toHaveBeenNthCalledWith(1, { + expect(props.registerPosition).toHaveBeenNthCalledWith(1, { type: 'initialPosition', labwareId: 'labwareId1', location: { slotName: 'D1' }, @@ -465,54 +365,18 @@ describe('CheckItem', () => { }) }) it('executes correct chained commands when confirm position clicked', async () => { - when(mockChainRunCommands) - .calledWith( - [ - { + vi.mocked(mockChainRunCommands).mockImplementation(() => + Promise.resolve([ + { + data: { commandType: 'savePosition', - params: { pipetteId: 'pipetteId1' }, - }, - { - commandType: 'retractAxis' as const, - params: { - axis: 'leftZ', - }, - }, - { - commandType: 'retractAxis' as const, - params: { - axis: 'x', - }, - }, - { - commandType: 'retractAxis' as const, - params: { - axis: 'y', - }, + result: { position: mockEndPosition }, }, - { - commandType: 'moveLabware', - params: { - labwareId: 'labwareId1', - newLocation: 'offDeck', - strategy: 'manualMoveWithoutPause', - }, - }, - ], - false - ) - .mockImplementation(() => - Promise.resolve([ - { - data: { - commandType: 'savePosition', - result: { position: mockEndPosition }, - }, - }, - {}, - {}, - ]) - ) + }, + {}, + {}, + ]) + ) props = { ...props, workingOffsets: [ @@ -526,8 +390,8 @@ describe('CheckItem', () => { } const { getByRole } = render(props) fireEvent.click(getByRole('button', { name: 'Confirm position' })) - - await expect(props.chainRunCommands).toHaveBeenNthCalledWith( + await new Promise(r => setTimeout(r)) + expect(props.chainRunCommands).toHaveBeenNthCalledWith( 1, [ { @@ -559,7 +423,7 @@ describe('CheckItem', () => { ], false ) - await expect(props.registerPosition).toHaveBeenNthCalledWith(1, { + expect(props.registerPosition).toHaveBeenNthCalledWith(1, { type: 'finalPosition', labwareId: 'labwareId1', location: { slotName: 'D1' }, @@ -592,7 +456,8 @@ describe('CheckItem', () => { }, } const { getByRole } = render(props) - await expect(props.chainRunCommands).toHaveBeenNthCalledWith( + await new Promise(r => setTimeout(r)) + expect(props.chainRunCommands).toHaveBeenNthCalledWith( 1, [ { @@ -612,7 +477,7 @@ describe('CheckItem', () => { ) fireEvent.click(getByRole('button', { name: 'Confirm placement' })) - await expect(props.chainRunCommands).toHaveBeenNthCalledWith( + expect(props.chainRunCommands).toHaveBeenNthCalledWith( 2, [ { @@ -675,75 +540,27 @@ describe('CheckItem', () => { }, ], } - when(mockChainRunCommands) - .calledWith( - [ - { + vi.mocked(mockChainRunCommands).mockImplementation(() => + Promise.resolve([ + { + data: { commandType: 'savePosition', - params: { pipetteId: 'pipetteId1' }, - }, - { - commandType: 'retractAxis' as const, - params: { - axis: 'leftZ', - }, - }, - { - commandType: 'retractAxis' as const, - params: { - axis: 'x', - }, - }, - { - commandType: 'retractAxis' as const, - params: { - axis: 'y', - }, + result: { position: mockEndPosition }, }, - { - commandType: 'heaterShaker/openLabwareLatch', - params: { moduleId: 'heaterShakerId' }, - }, - { - commandType: 'moveLabware', - params: { - labwareId: 'labwareId1', - newLocation: 'offDeck', - strategy: 'manualMoveWithoutPause', - }, - }, - { - commandType: 'moveLabware', - params: { - labwareId: 'adapterId', - newLocation: 'offDeck', - strategy: 'manualMoveWithoutPause', - }, - }, - ], - false - ) - .mockImplementation(() => - Promise.resolve([ - { - data: { - commandType: 'savePosition', - result: { position: mockEndPosition }, - }, - }, - {}, - {}, - {}, - {}, - {}, - {}, - ]) - ) + }, + {}, + {}, + {}, + {}, + {}, + {}, + ]) + ) const { getByRole } = render(props) fireEvent.click(getByRole('button', { name: 'Confirm position' })) - - await expect(props.chainRunCommands).toHaveBeenNthCalledWith( + await new Promise(r => setTimeout(r)) + expect(props.chainRunCommands).toHaveBeenNthCalledWith( 1, [ { @@ -787,7 +604,7 @@ describe('CheckItem', () => { ], false ) - await expect(props.registerPosition).toHaveBeenNthCalledWith(1, { + expect(props.registerPosition).toHaveBeenNthCalledWith(1, { type: 'finalPosition', labwareId: 'labwareId1', location: { slotName: 'D1', moduleModel: HEATERSHAKER_MODULE_V1 }, @@ -829,45 +646,22 @@ describe('CheckItem', () => { ...props, robotType: FLEX_ROBOT_TYPE, } - when(mockChainRunCommands) - .calledWith( - [ - { - commandType: 'moveLabware', - params: { - labwareId: 'labwareId1', - newLocation: { slotName: 'D1' }, - strategy: 'manualMoveWithoutPause', - }, - }, - { - commandType: 'moveToWell', - params: { - pipetteId: 'pipetteId1', - labwareId: 'labwareId1', - wellName: 'A1', - wellLocation: { origin: 'top', offset: { x: 0, y: 0, z: 44.5 } }, - }, - }, - { commandType: 'savePosition', params: { pipetteId: 'pipetteId1' } }, - ], - false - ) - .mockImplementation(() => - Promise.resolve([ - {}, - {}, - { - data: { - commandType: 'savePosition', - result: { position: mockStartPosition }, - }, + vi.mocked(mockChainRunCommands).mockImplementation(() => + Promise.resolve([ + {}, + {}, + { + data: { + commandType: 'savePosition', + result: { position: mockStartPosition }, }, - ]) - ) + }, + ]) + ) const { getByRole } = render(props) fireEvent.click(getByRole('button', { name: 'Confirm placement' })) - await expect(props.chainRunCommands).toHaveBeenNthCalledWith( + await new Promise(r => setTimeout(r)) + expect(props.chainRunCommands).toHaveBeenNthCalledWith( 1, [ { @@ -894,7 +688,7 @@ describe('CheckItem', () => { ], false ) - await expect(props.registerPosition).toHaveBeenNthCalledWith(1, { + expect(props.registerPosition).toHaveBeenNthCalledWith(1, { type: 'initialPosition', labwareId: 'labwareId1', location: { slotName: 'D1' }, diff --git a/app/src/organisms/ProtocolDetails/__tests__/ProtocolDetails.test.tsx b/app/src/organisms/ProtocolDetails/__tests__/ProtocolDetails.test.tsx index a9059a6ff27..39e6d03c407 100644 --- a/app/src/organisms/ProtocolDetails/__tests__/ProtocolDetails.test.tsx +++ b/app/src/organisms/ProtocolDetails/__tests__/ProtocolDetails.test.tsx @@ -1,13 +1,9 @@ import * as React from 'react' import { act, screen, waitFor } from '@testing-library/react' import { StaticRouter } from 'react-router-dom' -import { when } from 'vitest-when' import { describe, it, beforeEach, vi, expect, afterEach } from 'vitest' -import { - partialComponentPropsMatcher, - renderWithProviders, -} from '../../../__testing-utils__' +import { renderWithProviders } from '../../../__testing-utils__' import { i18n } from '../../../i18n' import { ChooseRobotToRunProtocolSlideout } from '../../../organisms/ChooseRobotToRunProtocolSlideout' import { @@ -72,12 +68,8 @@ describe('ProtocolDetails', () => { vi.mocked(getReachableRobots).mockReturnValue([mockReachableRobot]) vi.mocked(getScanning).mockReturnValue(false) - when(vi.mocked(ChooseRobotToRunProtocolSlideout)) - .calledWith(partialComponentPropsMatcher({ showSlideout: true })) - .thenReturn(
open ChooseRobotToRunProtocolSlideout
) - when(vi.mocked(ChooseRobotToRunProtocolSlideout)) - .calledWith(partialComponentPropsMatcher({ showSlideout: false })) - .thenReturn(
close ChooseRobotToRunProtocolSlideout
) + vi.mocked(ChooseRobotToRunProtocolSlideout) + .mockReturnValue(
close ChooseRobotToRunProtocolSlideout
) vi.mocked(getIsProtocolAnalysisInProgress).mockReturnValue(false) vi.mocked(useTrackEvent).mockReturnValue(mockTrackEvent) }) @@ -143,6 +135,9 @@ describe('ProtocolDetails', () => { screen.getByText('close ChooseRobotToRunProtocolSlideout') }) it('opens choose robot to run protocol slideout when Start setup button is clicked', async () => { + vi.mocked(ChooseRobotToRunProtocolSlideout).mockReturnValue( +
open ChooseRobotToRunProtocolSlideout
+ ) render({ mostRecentAnalysis: { ...mockMostRecentAnalysis,