Skip to content

Commit

Permalink
C* components test updates
Browse files Browse the repository at this point in the history
  • Loading branch information
mjhuff committed Feb 28, 2024
1 parent 6a74fcb commit 6fcf0de
Show file tree
Hide file tree
Showing 51 changed files with 710 additions and 836 deletions.
27 changes: 13 additions & 14 deletions app/src/organisms/CalibrateDeck/__tests__/CalibrateDeck.test.tsx
Original file line number Diff line number Diff line change
@@ -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<typeof getDeckDefinitions>()
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 = {
Expand Down Expand Up @@ -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 => {
Expand Down
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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<typeof getDeckDefinitions>()
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 = (
Expand Down Expand Up @@ -71,19 +74,15 @@ describe('CalibratePipetteOffset', () => {
]

beforeEach(() => {
dispatchRequests = jest.fn()
when(mockGetDeckDefinitions).calledWith().mockReturnValue({})
dispatchRequests = vi.fn()
when(vi.mocked(getDeckDefinitions)).calledWith().thenReturn({})

mockPipOffsetCalSession = {
id: 'fake_session_id',
...mockPipetteOffsetCalibrationSessionAttributes,
}
})

afterEach(() => {
resetAllWhenMocks()
})

SPECS.forEach(spec => {
it(`renders correct contents when currentStep is ${spec.currentStep}`, () => {
render({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { it, describe } from 'vitest'

describe('useCalibratePipetteOffset hook', () => {
it.todo('replace deprecated enzyme test')
})
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
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'
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<typeof AskForCalibrationBlockModal>
>(
<AskForCalibrationBlockModal
onResponse={onResponse}
titleBarTitle="Test Cal Flow"
closePrompt={jest.fn()}
closePrompt={vi.fn()}
/>,
{ 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')
Expand Down
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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<typeof getDeckDefinitions>()
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,
Expand Down Expand Up @@ -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 => {
Expand Down
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
Original file line number Diff line number Diff line change
@@ -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<React.ComponentProps<typeof Introduction>> = {}
Expand All @@ -39,11 +37,11 @@ describe('Introduction', () => {
)
}
beforeEach(() => {
mockChooseTipRack.mockReturnValue(<div>mock choose tip rack</div>)
vi.mocked(ChooseTipRack).mockReturnValue(<div>mock choose tip rack</div>)
})

afterEach(() => {
jest.resetAllMocks()
vi.resetAllMocks()
})

it('renders correct text', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -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'

Expand Down
Original file line number Diff line number Diff line change
@@ -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__'
Expand All @@ -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<typeof Select>

const render = (props: React.ComponentProps<typeof ChooseTipRack>) => {
return renderWithProviders(<ChooseTipRack {...props} />, {
i18nInstance: i18n,
Expand All @@ -56,31 +42,27 @@ describe('ChooseTipRack', () => {
let props: React.ComponentProps<typeof ChooseTipRack>

beforeEach(() => {
mockSelect.mockReturnValue(<div>mock select</div>)
mockGetCalibrationForPipette.mockReturnValue(null)
mockGetTipLengthForPipetteAndTiprack.mockReturnValue(null)
mockGetTipLengthCalibrations.mockReturnValue([])
mockUsePipettesQuery.mockReturnValue({
vi.mocked(Select).mockReturnValue(<div>mock select</div>)
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,
])
props = {
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')
Expand Down
Loading

0 comments on commit 6fcf0de

Please sign in to comment.