Skip to content

Commit

Permalink
update P* tests for vitest migration
Browse files Browse the repository at this point in the history
  • Loading branch information
koji committed Feb 28, 2024
1 parent 4e3660d commit 0bcf663
Show file tree
Hide file tree
Showing 17 changed files with 334 additions and 325 deletions.
56 changes: 32 additions & 24 deletions app/src/organisms/PipetteWizardFlows/__tests__/AttachProbe.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,15 @@ describe('AttachProbe', () => {
} as any)
})
it('returns the correct information, buttons work as expected', async () => {
const { getByText, getByTestId, getByRole, getByLabelText } = render(props)
getByText('Attach calibration probe')
getByText(
render(props)
screen.getByText('Attach calibration probe')
screen.getByText(
'Take the calibration probe from its storage location. Ensure its collar is unlocked. Push the pipette ejector up and press the probe firmly onto the pipette nozzle. Twist the collar to lock the probe. Test that the probe is secure by gently pulling it back and forth.'
)
getByTestId('Pipette_Attach_Probe_1.webm')
const proceedBtn = getByRole('button', { name: 'Begin calibration' })
screen.getByTestId(
'/app/src/assets/videos/pipette-wizard-flows/Pipette_Attach_Probe_1.webm'
)
const proceedBtn = screen.getByRole('button', { name: 'Begin calibration' })
fireEvent.click(proceedBtn)
await waitFor(() => {
expect(props.chainRunCommands).toHaveBeenCalledWith(
Expand Down Expand Up @@ -102,7 +104,7 @@ describe('AttachProbe', () => {
expect(props.proceed).toHaveBeenCalled()
})

const backBtn = getByLabelText('back')
const backBtn = screen.getByLabelText('back')
fireEvent.click(backBtn)
expect(props.goBack).toHaveBeenCalled()
})
Expand All @@ -115,8 +117,8 @@ describe('AttachProbe', () => {
right: null,
},
}
const { getByText } = render(props)
getByText(
render(props)
screen.getByText(
nestedTextMatcher(
'Take the calibration probe from its storage location. Ensure its collar is unlocked. Push the pipette ejector up and press the probe firmly onto the backmost pipette nozzle. Twist the collar to lock the probe. Test that the probe is secure by gently pulling it back and forth.'
)
Expand All @@ -128,12 +130,14 @@ describe('AttachProbe', () => {
...props,
isRobotMoving: true,
}
const { getByText, getByTestId } = render(props)
getByText('Stand back, Flex 1-Channel 1000 μL is calibrating')
getByText(
render(props)
screen.getByText('Stand back, Flex 1-Channel 1000 μL is calibrating')
screen.getByText(
'The calibration probe will touch the sides of the calibration square in slot C2 to determine its exact position.'
)
getByTestId('Pipette_Probing_1.webm')
screen.getByTestId(
'/app/src/assets/videos/pipette-wizard-flows/Pipette_Probing_1.webm'
)
})

it('returns the correct information when robot is in motion for 96 channel', () => {
Expand All @@ -145,12 +149,14 @@ describe('AttachProbe', () => {
},
isRobotMoving: true,
}
const { getByText, getByTestId } = render(props)
getByText('Stand back, Flex 96-Channel 1000 μL is calibrating')
getByText(
render(props)
screen.getByText('Stand back, Flex 96-Channel 1000 μL is calibrating')
screen.getByText(
'The calibration probe will touch the sides of the calibration square in slot C2 to determine its exact position.'
)
getByTestId('Pipette_Probing_96.webm')
screen.getByTestId(
'/app/src/assets/videos/pipette-wizard-flows/Pipette_Probing_96.webm'
)
})

it('returns the correct information when robot is in motion during exiting', () => {
Expand All @@ -159,8 +165,8 @@ describe('AttachProbe', () => {
isRobotMoving: true,
isExiting: true,
}
const { getByText } = render(props)
getByText('Stand back, robot is in motion')
render(props)
screen.getByText('Stand back, robot is in motion')
expect(
screen.queryByText(
'The calibration probe will touch the sides of the calibration square in slot C2 to determine its exact position.'
Expand All @@ -173,11 +179,11 @@ describe('AttachProbe', () => {
...props,
errorMessage: 'error shmerror',
}
const { getByText } = render(props)
getByText(
render(props)
screen.getByText(
'Return the calibration probe to its storage location before exiting.'
)
getByText('error shmerror')
screen.getByText('error shmerror')
})

it('renders the correct text when is on device', async () => {
Expand All @@ -190,7 +196,9 @@ describe('AttachProbe', () => {
getByText(
'Take the calibration probe from its storage location. Ensure its collar is unlocked. Push the pipette ejector up and press the probe firmly onto the pipette nozzle. Twist the collar to lock the probe. Test that the probe is secure by gently pulling it back and forth.'
)
getByTestId('Pipette_Attach_Probe_1.webm')
getByTestId(
'/app/src/assets/videos/pipette-wizard-flows/Pipette_Attach_Probe_1.webm'
)
fireEvent.click(getByRole('button', { name: 'Begin calibration' }))
await waitFor(() => {
expect(props.chainRunCommands).toHaveBeenCalledWith(
Expand Down Expand Up @@ -249,8 +257,8 @@ describe('AttachProbe', () => {
right: null,
},
}
const { getByText } = render(props)
getByText(
render(props)
screen.getByText(
'Remove the waste chute from the deck plate adapter before proceeding.'
)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ describe('Carriage', () => {
it('returns the correct information, buttons work as expected when flow is attach', () => {
render(props)
screen.getByText('Unscrew z-axis carriage')
screen.getByTestId('Pipette_Zaxis_Attach_96.webm')
screen.getByTestId(
'/app/src/assets/videos/pipette-wizard-flows/Pipette_Zaxis_Attach_96.webm'
)
screen.getByRole('button', { name: 'Continue' })
expect(screen.queryByLabelText('back')).not.toBeInTheDocument()
})
Expand All @@ -57,7 +59,9 @@ describe('Carriage', () => {
screen.getByText(
'When reattached, the right mount should no longer freely move up and down.'
)
screen.getByTestId('Pipette_Zaxis_Detach_96.webm')
screen.getByTestId(
'/app/src/assets/videos/pipette-wizard-flows/Pipette_Zaxis_Detach_96.webm'
)
screen.getByRole('button', { name: 'Continue' })
fireEvent.click(screen.getByLabelText('back'))
expect(props.goBack).toHaveBeenCalled()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ describe('DetachPipette', () => {
getByText(
'Hold the pipette in place and loosen the pipette screws. (The screws are captive and will not come apart from the pipette.) Then carefully remove the pipette.'
)
getByTestId('Pipette_Detach_1_L.webm')
getByTestId(
'/app/src/assets/videos/pipette-wizard-flows/Pipette_Detach_1_L.webm'
)
getByText('Continue')
const backBtn = getByLabelText('back')
fireEvent.click(backBtn)
Expand Down Expand Up @@ -84,7 +86,9 @@ describe('DetachPipette', () => {
screen.getByText(
'Hold the pipette in place and loosen the pipette screws. (The screws are captive and will not come apart from the pipette.) Then carefully remove the pipette.'
)
screen.getByTestId('Pipette_Detach_96.webm')
screen.getByTestId(
'/app/src/assets/videos/pipette-wizard-flows/Pipette_Detach_96.webm'
)
screen.getByText('Continue')
const backBtn = screen.getByLabelText('back')
fireEvent.click(backBtn)
Expand Down Expand Up @@ -112,7 +116,9 @@ describe('DetachPipette', () => {
screen.getByText(
'Hold the pipette in place and loosen the pipette screws. (The screws are captive and will not come apart from the pipette.) Then carefully remove the pipette.'
)
screen.getByTestId('Pipette_Detach_1_L.webm')
screen.getByTestId(
'/app/src/assets/videos/pipette-wizard-flows/Pipette_Detach_1_L.webm'
)
screen.getByText('Continue')
fireEvent.click(screen.getByLabelText('back'))
expect(props.goBack).toHaveBeenCalled()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react'
import { fireEvent, screen } from '@testing-library/react'
import { describe, it, beforeEach, vi } from 'vitest'
import { describe, it, beforeEach, vi, expect } from 'vitest'

import { LEFT, SINGLE_MOUNT_PIPETTES } from '@opentrons/shared-data'

Expand Down Expand Up @@ -48,7 +48,9 @@ describe('DetachProbe', () => {
getByText(
'Unlock the calibration probe, remove it from the nozzle, and return it to its storage location.'
)
getByTestId('Pipette_Detach_Probe_1.webm')
getByTestId(
'/app/src/assets/videos/pipette-wizard-flows/Pipette_Detach_Probe_1.webm'
)
const proceedBtn = getByRole('button', { name: 'Complete calibration' })
fireEvent.click(proceedBtn)
expect(props.proceed).toHaveBeenCalled()
Expand All @@ -74,7 +76,9 @@ describe('DetachProbe', () => {
getByText(
'Unlock the calibration probe, remove it from the nozzle, and return it to its storage location.'
)
getByTestId('Pipette_Detach_Probe_1.webm')
getByTestId(
'/app/src/assets/videos/pipette-wizard-flows/Pipette_Detach_Probe_1.webm'
)
const proceedBtn = getByRole('button', { name: 'Exit calibration' })
fireEvent.click(proceedBtn)
expect(props.proceed).toHaveBeenCalled()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ describe('MountPipette', () => {
screen.getByText(
'Attach the pipette to the robot by aligning the connector and pressing to ensure a secure connection. Hold the pipette in place and use the hex screwdriver to tighten the pipette screws. Then test that the pipette is securely attached by gently pulling it side to side.'
)
screen.getByTestId('Pipette_Attach_1_8_L.webm')
screen.getByTestId(
'/app/src/assets/videos/pipette-wizard-flows/Pipette_Attach_1_8_L.webm'
)
const backBtn = screen.getByLabelText('back')
fireEvent.click(backBtn)
expect(props.goBack).toHaveBeenCalled()
Expand All @@ -75,7 +77,9 @@ describe('MountPipette', () => {
screen.getByText(
'Hold onto the pipette so it does not fall. Connect the pipette by aligning the two protruding rods on the mounting plate. Ensure a secure attachment by screwing in the four front screws with the provided screwdriver.'
)
screen.getByTestId('Pipette_Attach_96.webm')
screen.getByTestId(
'/app/src/assets/videos/pipette-wizard-flows/Pipette_Attach_96.webm'
)
const backBtn = screen.getByLabelText('back')
fireEvent.click(backBtn)
expect(props.goBack).toHaveBeenCalled()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ describe('MountingPlate', () => {
screen.getByText(
'Attach the mounting plate by aligning the pins on the plate to the slots on the gantry carriage. You may need to adjust the position of the right pipette mount to achieve proper alignment.'
)
screen.getByTestId('Pipette_Detach_Plate_96.webm')
screen.getByTestId(
'/app/src/assets/videos/pipette-wizard-flows/Pipette_Attach_Plate_96.webm'
)
const proceedBtn = screen.getByRole('button', { name: 'Continue' })
fireEvent.click(proceedBtn)
await waitFor(() => {
Expand Down Expand Up @@ -74,7 +76,9 @@ describe('MountingPlate', () => {
screen.getByText(
'Hold onto the plate so it does not fall. Then remove the pins on the plate from the slots on the gantry carriage.'
)
screen.getByTestId('Pipette_Detach_Plate_96.webm')
screen.getByTestId(
'/app/src/assets/videos/pipette-wizard-flows/Pipette_Detach_Plate_96.webm'
)
const proceedBtn = screen.getByRole('button', { name: 'Continue' })
fireEvent.click(proceedBtn)
expect(props.proceed).toHaveBeenCalled()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import * as React from 'react'
import { act, screen, waitFor } from '@testing-library/react'
import { StaticRouter } from 'react-router-dom'
import { resetAllWhenMocks, when } from 'jest-when'

import {
partialComponentPropsMatcher,
renderWithProviders,
} from '@opentrons/components'
import { when } from 'vitest-when'
import { describe, it, beforeEach, vi, expect, afterEach } from 'vitest'

import { renderWithProviders } from '../../../__testing-utils__'
import { i18n } from '../../../i18n'
import { ChooseRobotToRunProtocolSlideout } from '../../../organisms/ChooseRobotToRunProtocolSlideout'
import {
Expand All @@ -30,37 +27,15 @@ import {
import { storedProtocolData } from '../../../redux/protocol-storage/__fixtures__'
import { ProtocolDetails } from '..'

import type { Mock } from 'vitest'
import type { ProtocolAnalysisOutput } from '@opentrons/shared-data'

jest.mock('../../../redux/analytics')
jest.mock('../../../redux/custom-labware/selectors')
jest.mock('../../../redux/discovery/selectors')
jest.mock('../../../redux/protocol-storage/selectors')
jest.mock('../../../organisms/ChooseRobotToRunProtocolSlideout')
jest.mock('../../../organisms/SendProtocolToFlexSlideout')

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<typeof getScanning>
const mockGetIsProtocolAnalysisInProgress = getIsProtocolAnalysisInProgress as jest.MockedFunction<
typeof getIsProtocolAnalysisInProgress
>
const mockGetValidCustomLabwareFiles = getValidCustomLabwareFiles as jest.MockedFunction<
typeof getValidCustomLabwareFiles
>
const mockUseTrackEvent = useTrackEvent as jest.MockedFunction<
typeof useTrackEvent
>
const mockChooseRobotToRunProtocolSlideout = ChooseRobotToRunProtocolSlideout as jest.MockedFunction<
typeof ChooseRobotToRunProtocolSlideout
>
vi.mock('../../../redux/analytics')
vi.mock('../../../redux/custom-labware/selectors')
vi.mock('../../../redux/discovery/selectors')
vi.mock('../../../redux/protocol-storage/selectors')
vi.mock('../../../organisms/ChooseRobotToRunProtocolSlideout')
vi.mock('../../../organisms/SendProtocolToFlexSlideout')

const render = (
props: Partial<React.ComponentProps<typeof ProtocolDetails>> = {}
Expand All @@ -83,29 +58,28 @@ const description = 'fake protocol description'

const mockMostRecentAnalysis: ProtocolAnalysisOutput = storedProtocolData.mostRecentAnalysis as ProtocolAnalysisOutput

let mockTrackEvent: jest.Mock
let mockTrackEvent: Mock

describe('ProtocolDetails', () => {
beforeEach(() => {
mockTrackEvent = jest.fn()
mockGetValidCustomLabwareFiles.mockReturnValue([])
mockGetConnectableRobots.mockReturnValue([mockConnectableRobot])
mockGetUnreachableRobots.mockReturnValue([mockUnreachableRobot])
mockGetReachableRobots.mockReturnValue([mockReachableRobot])
mockGetScanning.mockReturnValue(false)
mockTrackEvent = vi.fn()
vi.mocked(getValidCustomLabwareFiles).mockReturnValue([])
vi.mocked(getConnectableRobots).mockReturnValue([mockConnectableRobot])
vi.mocked(getUnreachableRobots).mockReturnValue([mockUnreachableRobot])
vi.mocked(getReachableRobots).mockReturnValue([mockReachableRobot])
vi.mocked(getScanning).mockReturnValue(false)

when(mockChooseRobotToRunProtocolSlideout)
when(vi.mocked(ChooseRobotToRunProtocolSlideout))
.calledWith(partialComponentPropsMatcher({ showSlideout: true }))
.mockReturnValue(<div>open ChooseRobotToRunProtocolSlideout</div>)
when(mockChooseRobotToRunProtocolSlideout)
.thenReturn(<div>open ChooseRobotToRunProtocolSlideout</div>)
when(vi.mocked(ChooseRobotToRunProtocolSlideout))
.calledWith(partialComponentPropsMatcher({ showSlideout: false }))
.mockReturnValue(<div>close ChooseRobotToRunProtocolSlideout</div>)
mockGetIsProtocolAnalysisInProgress.mockReturnValue(false)
mockUseTrackEvent.mockReturnValue(mockTrackEvent)
.thenReturn(<div>close ChooseRobotToRunProtocolSlideout</div>)
vi.mocked(getIsProtocolAnalysisInProgress).mockReturnValue(false)
vi.mocked(useTrackEvent).mockReturnValue(mockTrackEvent)
})
afterEach(() => {
jest.resetAllMocks()
resetAllWhenMocks()
vi.resetAllMocks()
})

it('renders protocol title as display name if present in metadata', () => {
Expand Down
Loading

0 comments on commit 0bcf663

Please sign in to comment.