Skip to content

Commit

Permalink
the third phase of the rest of tests
Browse files Browse the repository at this point in the history
  • Loading branch information
koji committed Feb 29, 2024
1 parent 7a03259 commit 881ab8c
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 147 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
import * as React from 'react'
import { when, resetAllWhenMocks } from 'jest-when'
import { when } from 'vitest-when'
import { MemoryRouter } from 'react-router-dom'
import { describe, it, beforeEach, afterEach, vi, expect } from 'vitest'
import { screen } from '@testing-library/react'

import { renderWithProviders } from '@opentrons/components'

import { renderWithProviders } from '../../../../__testing-utils__'
import { i18n } from '../../../../i18n'
import { mockDeckCalData } from '../../../../redux/calibration/__fixtures__'
import { useDeckCalibrationData } from '../../hooks'
import { SetupDeckCalibration } from '../SetupDeckCalibration'

jest.mock('../../hooks')

const mockUseDeckCalibrationData = useDeckCalibrationData as jest.MockedFunction<
typeof useDeckCalibrationData
>
vi.mock('../../hooks')

const ROBOT_NAME = 'otie'
const RUN_ID = '1'
Expand All @@ -31,32 +28,34 @@ const render = () => {

describe('SetupDeckCalibration', () => {
beforeEach(() => {
when(mockUseDeckCalibrationData).calledWith(ROBOT_NAME).mockReturnValue({
when(vi.mocked(useDeckCalibrationData)).calledWith(ROBOT_NAME).thenReturn({
deckCalibrationData: mockDeckCalData,
isDeckCalibrated: true,
})
})
afterEach(() => {
resetAllWhenMocks()
vi.resetAllMocks()
})

it('renders last calibrated content when deck is calibrated', () => {
const { getByText, queryByText } = render()
getByText('Deck Calibration')
queryByText('Last calibrated:')
render()
screen.getByText('Deck Calibration')
screen.queryByText('Last calibrated:')
})
it('renders a link to the calibration dashboard if deck is not calibrated', () => {
when(mockUseDeckCalibrationData).calledWith(ROBOT_NAME).mockReturnValue({
when(vi.mocked(useDeckCalibrationData)).calledWith(ROBOT_NAME).thenReturn({
deckCalibrationData: null,
isDeckCalibrated: false,
})
const { getByRole, getByText } = render()
render()

getByText('Not calibrated yet')
screen.getByText('Not calibrated yet')
expect(
getByRole('link', {
name: 'Calibrate now',
}).getAttribute('href')
screen
.getByRole('link', {
name: 'Calibrate now',
})
.getAttribute('href')
).toBe('/devices/otie/robot-settings/calibration/dashboard')
})
})
Original file line number Diff line number Diff line change
@@ -1,32 +1,22 @@
import * as React from 'react'
import { resetAllWhenMocks } from 'jest-when'
import { MemoryRouter } from 'react-router-dom'
import { fireEvent } from '@testing-library/react'
import { fireEvent, screen } from '@testing-library/react'
import { describe, it, beforeEach, vi, afterEach } from 'vitest'

import { renderWithProviders } from '@opentrons/components'
import { useInstrumentsQuery } from '@opentrons/react-api-client'

import { renderWithProviders } from '../../../../__testing-utils__'
import { i18n } from '../../../../i18n'
import { useMostRecentCompletedAnalysis } from '../../../LabwarePositionCheck/useMostRecentCompletedAnalysis'
import { PipetteWizardFlows } from '../../../PipetteWizardFlows'
import { SetupFlexPipetteCalibrationItem } from '../SetupFlexPipetteCalibrationItem'
import _uncastedModifiedSimpleV6Protocol from '../../hooks/__fixtures__/modifiedSimpleV6.json'
import { CompletedProtocolAnalysis } from '@opentrons/shared-data'

jest.mock('@opentrons/react-api-client')
jest.mock('../../../PipetteWizardFlows')
jest.mock('../../../LabwarePositionCheck/useMostRecentCompletedAnalysis')
jest.mock('../../hooks')

const mockUseInstrumentsQuery = useInstrumentsQuery as jest.MockedFunction<
typeof useInstrumentsQuery
>
const mockUseMostRecentCompletedAnalysis = useMostRecentCompletedAnalysis as jest.MockedFunction<
typeof useMostRecentCompletedAnalysis
>
const mockPipetteWizardFlows = PipetteWizardFlows as jest.MockedFunction<
typeof PipetteWizardFlows
>
vi.mock('@opentrons/react-api-client')
vi.mock('../../../PipetteWizardFlows')
vi.mock('../../../LabwarePositionCheck/useMostRecentCompletedAnalysis')
vi.mock('../../hooks')

const RUN_ID = '1'
const modifiedSimpleV6Protocol = ({
Expand Down Expand Up @@ -60,34 +50,39 @@ describe('SetupFlexPipetteCalibrationItem', () => {
}

beforeEach(() => {
mockPipetteWizardFlows.mockReturnValue(<div>pipette wizard flows</div>)
mockUseMostRecentCompletedAnalysis.mockReturnValue(modifiedSimpleV6Protocol)
mockUseInstrumentsQuery.mockReturnValue({
vi.mocked(PipetteWizardFlows).mockReturnValue(
<div>pipette wizard flows</div>
)
vi.mocked(useMostRecentCompletedAnalysis).mockReturnValue(
modifiedSimpleV6Protocol
)
vi.mocked(useInstrumentsQuery).mockReturnValue({
data: {
data: [],
},
} as any)
})
afterEach(() => {
resetAllWhenMocks()
vi.clearAllMocks()
})

it('renders the mount and pipette name', () => {
const { getByText } = render()
getByText('Left Mount')
getByText('P10 Single-Channel GEN1')
render()
screen.getByText('Left Mount')
screen.getByText('P10 Single-Channel GEN1')
})

it('renders an attach button if on a Flex and pipette is not attached', () => {
const { getByText, getByRole } = render()
getByText('Left Mount')
getByText('P10 Single-Channel GEN1')
const attach = getByRole('button', { name: 'Attach Pipette' })
render()
screen.getByText('Left Mount')
screen.getByText('P10 Single-Channel GEN1')
const attach = screen.getByRole('button', { name: 'Attach Pipette' })
fireEvent.click(attach)
getByText('pipette wizard flows')
screen.getByText('pipette wizard flows')
})

it('renders a calibrate button if on a Flex and pipette is not calibrated', () => {
mockUseInstrumentsQuery.mockReturnValue({
vi.mocked(useInstrumentsQuery).mockReturnValue({
data: {
data: [
{
Expand All @@ -101,15 +96,16 @@ describe('SetupFlexPipetteCalibrationItem', () => {
],
},
} as any)
const { getByText, getByRole } = render()
getByText('Left Mount')
getByText('P10 Single-Channel GEN1')
const attach = getByRole('button', { name: 'Calibrate now' })
render()
screen.getByText('Left Mount')
screen.getByText('P10 Single-Channel GEN1')
const attach = screen.getByRole('button', { name: 'Calibrate now' })
fireEvent.click(attach)
getByText('pipette wizard flows')
screen.getByText('pipette wizard flows')
})

it('renders calibrated text if on a Flex and pipette is calibrated', () => {
mockUseInstrumentsQuery.mockReturnValue({
vi.mocked(useInstrumentsQuery).mockReturnValue({
data: {
data: [
{
Expand All @@ -127,9 +123,9 @@ describe('SetupFlexPipetteCalibrationItem', () => {
],
},
} as any)
const { getByText } = render()
getByText('Left Mount')
getByText('P10 Single-Channel GEN1')
getByText('Last calibrated: today')
render()
screen.getByText('Left Mount')
screen.getByText('P10 Single-Channel GEN1')
screen.getByText('Last calibrated: today')
})
})
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
import * as React from 'react'
import { when, resetAllWhenMocks } from 'jest-when'

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

import { renderWithProviders } from '../../../../__testing-utils__'
import { i18n } from '../../../../i18n'
import { mockTipRackDefinition } from '../../../../redux/custom-labware/__fixtures__'
import { useRunPipetteInfoByMount } from '../../hooks'
import { SetupPipetteCalibrationItem } from '../SetupPipetteCalibrationItem'
import { SetupInstrumentCalibration } from '../SetupInstrumentCalibration'
import type { PipetteInfo } from '../../hooks'

jest.mock('../../hooks')
jest.mock('../SetupPipetteCalibrationItem')

const mockUseRunPipetteInfoByMount = useRunPipetteInfoByMount as jest.MockedFunction<
typeof useRunPipetteInfoByMount
>
const mockSetupPipetteCalibrationItem = SetupPipetteCalibrationItem as jest.MockedFunction<
typeof SetupPipetteCalibrationItem
>
vi.mock('../../hooks')
vi.mock('../SetupPipetteCalibrationItem')

const ROBOT_NAME = 'otie'
const RUN_ID = '1'
Expand Down Expand Up @@ -49,32 +43,36 @@ const render = () => {

describe('SetupPipetteCalibration', () => {
beforeEach(() => {
when(mockUseRunPipetteInfoByMount).calledWith(RUN_ID).mockReturnValue({
when(vi.mocked(useRunPipetteInfoByMount)).calledWith(RUN_ID).thenReturn({
left: PIPETTE_INFO,
right: null,
})
when(mockSetupPipetteCalibrationItem).mockReturnValue(
vi.mocked(SetupPipetteCalibrationItem).mockReturnValue(
<div>Mock SetupPipetteCalibrationItem</div>
)
})
afterEach(() => {
resetAllWhenMocks()
vi.clearAllMocks()
})

it('renders required pipettes title', () => {
const { getByText } = render()
getByText('Required Instrument Calibrations')
render()
screen.getByText('Required Instrument Calibrations')
})
it('renders one SetupPipetteCalibrationItem when protocol run requires one pipette', () => {
const { getAllByText } = render()
expect(getAllByText('Mock SetupPipetteCalibrationItem')).toHaveLength(1)
render()
expect(
screen.getAllByText('Mock SetupPipetteCalibrationItem')
).toHaveLength(1)
})
it('renders two SetupPipetteCalibrationItems when protocol run requires two pipettes', () => {
when(mockUseRunPipetteInfoByMount).calledWith(RUN_ID).mockReturnValue({
when(vi.mocked(useRunPipetteInfoByMount)).calledWith(RUN_ID).thenReturn({
left: PIPETTE_INFO,
right: PIPETTE_INFO,
})
const { getAllByText } = render()
expect(getAllByText('Mock SetupPipetteCalibrationItem')).toHaveLength(2)
render()
expect(
screen.getAllByText('Mock SetupPipetteCalibrationItem')
).toHaveLength(2)
})
})
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import * as React from 'react'
import { when, resetAllWhenMocks } from 'jest-when'

import { renderWithProviders } from '@opentrons/components'

import { renderWithProviders } from '../../../../__testing-utils__'}
import { i18n } from '../../../../i18n'
import { mockDeckCalData } from '../../../../redux/calibration/__fixtures__'
import { mockPipetteInfo } from '../../../../redux/pipettes/__fixtures__'
Expand Down
Loading

0 comments on commit 881ab8c

Please sign in to comment.