Skip to content

Commit

Permalink
the send phase of the rest tests
Browse files Browse the repository at this point in the history
  • Loading branch information
koji committed Feb 29, 2024
1 parent b3dac06 commit a6f4651
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 88 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import * as React from 'react'
import { fireEvent } from '@testing-library/react'
import { renderWithProviders } from '@opentrons/components'
import { fireEvent, screen } from '@testing-library/react'
import { describe, it, beforeEach, expect, vi } from 'vitest'

import { renderWithProviders } from '../../../../__testing-utils__'
import { i18n } from '../../../../i18n'
import { ProtocolAnalysisErrorModal } from '../ProtocolAnalysisErrorModal'

Expand All @@ -19,7 +21,7 @@ describe('ProtocolAnalysisErrorModal', () => {
props = {
displayName: 'test_protocol',
robotName: 'test_robot',
onClose: jest.fn(),
onClose: vi.fn(),
errors: [
{
id: 'error_id',
Expand All @@ -31,13 +33,13 @@ describe('ProtocolAnalysisErrorModal', () => {
}
})
it('renders error modal', () => {
const { getByText, getByLabelText } = render(props)
getByText('protocol analysis error')
getByLabelText('close_analysis_error_modal')
render(props)
screen.getByText('protocol analysis error')
screen.getByLabelText('close_analysis_error_modal')
})
it('calls onClose when close button clicked', () => {
const { getByLabelText } = render(props)
const btn = getByLabelText('close_analysis_error_modal')
render(props)
const btn = screen.getByLabelText('close_analysis_error_modal')
fireEvent.click(btn)
expect(props.onClose).toHaveBeenCalled()
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as React from 'react'
import { fireEvent } from '@testing-library/react'

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

import { renderWithProviders } from '../../../../__testing-utils__'
import { ProtocolDropTipBanner } from '../ProtocolDropTipBanner'
import { i18n } from '../../../../i18n'

Expand All @@ -17,8 +17,8 @@ describe('Module Update Banner', () => {

beforeEach(() => {
props = {
onCloseClick: jest.fn(),
onLaunchWizardClick: jest.fn(),
onCloseClick: vi.fn(),
onLaunchWizardClick: vi.fn(),
}
})

Expand All @@ -30,16 +30,16 @@ describe('Module Update Banner', () => {
})

it('launches the drop tip wizard when clicking on the appropriate banner text', () => {
const { getByText } = render(props)
render(props)
expect(props.onLaunchWizardClick).not.toHaveBeenCalled()
fireEvent.click(getByText('Remove tips'))
fireEvent.click(screen.getByText('Remove tips'))
expect(props.onLaunchWizardClick).toHaveBeenCalled()
})

it('closes the banner when clicking the appropriate button', () => {
const { getByTestId } = render(props)
render(props)
expect(props.onCloseClick).not.toHaveBeenCalled()
fireEvent.click(getByTestId('Banner_close-button'))
fireEvent.click(screen.getByTestId('Banner_close-button'))
expect(props.onCloseClick).toHaveBeenCalled()
})
})
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import * as React from 'react'
import { resetAllWhenMocks, when } from 'jest-when'
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 { renderWithProviders } from '@opentrons/components'
import { ModuleModel, ModuleType } from '@opentrons/shared-data'
import { useInstrumentsQuery } from '@opentrons/react-api-client'
import { ProtocolRunModuleControls } from '../ProtocolRunModuleControls'
Expand All @@ -14,20 +17,11 @@ import {
mockHeaterShaker,
} from '../../../../redux/modules/__fixtures__'

jest.mock('@opentrons/react-api-client')
jest.mock('../../../ModuleCard')
jest.mock('../../hooks')

const mockModuleCard = ModuleCard as jest.MockedFunction<typeof ModuleCard>
const mockUseModuleRenderInfoForProtocolById = useModuleRenderInfoForProtocolById as jest.MockedFunction<
typeof useModuleRenderInfoForProtocolById
>
const mockUseInstrumentsQuery = useInstrumentsQuery as jest.MockedFunction<
typeof useInstrumentsQuery
>
vi.mock('@opentrons/react-api-client')
vi.mock('../../../ModuleCard')
vi.mock('../../hooks')

const RUN_ID = 'test123'

const mockTempMod = {
labwareOffset: { x: 3, y: 3, z: 3 },
moduleId: 'temperature_id',
Expand Down Expand Up @@ -65,20 +59,21 @@ const render = (

describe('ProtocolRunModuleControls', () => {
beforeEach(() => {
when(mockUseInstrumentsQuery).mockReturnValue({
data: { data: [] },
} as any)
when(vi.mocked(useInstrumentsQuery))
.calledWith()
.thenReturn({
data: { data: [] },
} as any)
})

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

it('renders a magnetic module card', () => {
when(mockUseModuleRenderInfoForProtocolById)
when(vi.mocked(useModuleRenderInfoForProtocolById))
.calledWith(RUN_ID)
.mockReturnValue({
.thenReturn({
[mockMagMod.moduleId]: {
moduleId: 'magModModuleId',
x: '0',
Expand All @@ -91,19 +86,19 @@ describe('ProtocolRunModuleControls', () => {
attachedModuleMatch: mockMagneticModuleGen2,
},
} as any)
when(mockModuleCard).mockReturnValue(<div>mock Magnetic Module Card</div>)
const { getByText } = render({
when(vi.mocked(ModuleCard)).thenReturn(<div>mock Magnetic Module Card</div>)
render({
robotName: 'otie',
runId: 'test123',
})

getByText('mock Magnetic Module Card')
screen.getByText('mock Magnetic Module Card')
})

it('renders a temperature module card', () => {
when(mockUseModuleRenderInfoForProtocolById)
when(vi.mocked(useModuleRenderInfoForProtocolById))
.calledWith(RUN_ID)
.mockReturnValue({
.thenReturn({
[mockTempMod.moduleId]: {
moduleId: 'temperatureModuleId',
x: '0',
Expand All @@ -116,21 +111,21 @@ describe('ProtocolRunModuleControls', () => {
attachedModuleMatch: mockTemperatureModuleGen2,
},
} as any)
when(mockModuleCard).mockReturnValue(
when(vi.mocked(ModuleCard)).thenReturn(
<div>mock Temperature Module Card</div>
)
const { getByText } = render({
render({
robotName: 'otie',
runId: 'test123',
})

getByText('mock Temperature Module Card')
screen.getByText('mock Temperature Module Card')
})

it('renders a thermocycler module card', () => {
when(mockUseModuleRenderInfoForProtocolById)
when(vi.mocked(useModuleRenderInfoForProtocolById))
.calledWith(RUN_ID)
.mockReturnValue({
.thenReturn({
[mockTCModule.moduleId]: {
moduleId: mockTCModule.moduleId,
x: MOCK_TC_COORDS[0],
Expand All @@ -144,22 +139,22 @@ describe('ProtocolRunModuleControls', () => {
},
} as any)

when(mockModuleCard).mockReturnValue(
when(vi.mocked(ModuleCard)).thenReturn(
<div>mock Thermocycler Module Card</div>
)

const { getByText } = render({
render({
robotName: 'otie',
runId: 'test123',
})

getByText('mock Thermocycler Module Card')
screen.getByText('mock Thermocycler Module Card')
})

it('renders a heater-shaker module card', () => {
when(mockUseModuleRenderInfoForProtocolById)
when(vi.mocked(useModuleRenderInfoForProtocolById))
.calledWith(RUN_ID)
.mockReturnValue({
.thenReturn({
[mockHeaterShakerDef.moduleId]: {
moduleId: 'heaterShakerModuleId',
x: '0',
Expand All @@ -172,22 +167,22 @@ describe('ProtocolRunModuleControls', () => {
attachedModuleMatch: mockHeaterShaker,
},
} as any)
when(mockModuleCard).mockReturnValue(
when(vi.mocked(ModuleCard)).thenReturn(
<div>mock Heater-Shaker Module Card</div>
)

const { getByText } = render({
render({
robotName: 'otie',
runId: 'test123',
})

getByText('mock Heater-Shaker Module Card')
screen.getByText('mock Heater-Shaker Module Card')
})

it('renders correct text when module is not attached but required for protocol', () => {
when(mockUseModuleRenderInfoForProtocolById)
when(vi.mocked(useModuleRenderInfoForProtocolById))
.calledWith(RUN_ID)
.mockReturnValue({
.thenReturn({
[mockHeaterShakerDef.moduleId]: {
moduleId: 'heaterShakerModuleId',
x: '0',
Expand All @@ -201,11 +196,11 @@ describe('ProtocolRunModuleControls', () => {
},
} as any)

const { getByText } = render({
render({
robotName: 'otie',
runId: 'test123',
})

getByText('Connect modules to see controls')
screen.getByText('Connect modules to see controls')
})
})
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
import * as React from 'react'
import { describe, it, beforeEach, vi, expect, afterEach } from 'vitest'

import { renderWithProviders } from '@opentrons/components'

import { renderWithProviders } from '../../../../__testing-utils__'
import { i18n } from '../../../../i18n'
import { useDownloadRunLog } from '../../hooks'
import { RunFailedModal } from '../RunFailedModal'

import type { RunError } from '@opentrons/api-client'
import { fireEvent, screen } from '@testing-library/react'

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

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

const RUN_ID = '1'
const ROBOT_NAME = 'mockRobotName'
Expand All @@ -40,17 +36,17 @@ describe('RunFailedModal - DesktopApp', () => {
props = {
robotName: ROBOT_NAME,
runId: RUN_ID,
setShowRunFailedModal: jest.fn(),
setShowRunFailedModal: vi.fn(),
highestPriorityError: mockError,
}
mockUseDownloadRunLog.mockReturnValue({
downloadRunLog: jest.fn(),
vi.mocked(useDownloadRunLog).mockReturnValue({
downloadRunLog: vi.fn(),
isRunLogLoading: false,
})
})

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

it('should render text, link and button', () => {
Expand Down Expand Up @@ -80,6 +76,6 @@ describe('RunFailedModal - DesktopApp', () => {
it('should call a mock function when clicking download run log button', () => {
render(props)
fireEvent.click(screen.getByText('Download Run Log'))
expect(mockUseDownloadRunLog).toHaveBeenCalled()
expect(vi.mocked(useDownloadRunLog)).toHaveBeenCalled()
})
})
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
import * as React from 'react'
import { screen } from '@testing-library/react'
import { renderWithProviders } from '@opentrons/components'
import { when } from 'vitest-when'
import { describe, it, beforeEach, vi, afterEach } from 'vitest'

import { renderWithProviders } from '../../../../__testing-utils__'
import { i18n } from '../../../../i18n'
import { useRunHasStarted } from '../../hooks'
import { formatTimestamp } from '../../utils'
import { SetupCalibrationItem } from '../SetupCalibrationItem'
import { when, resetAllWhenMocks } from 'jest-when'

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

const mockFormatTimestamp = formatTimestamp as jest.MockedFunction<
typeof formatTimestamp
>
const mockUseRunHasStarted = useRunHasStarted as jest.MockedFunction<
typeof useRunHasStarted
>
vi.mock('../../hooks')
vi.mock('../../utils')

const RUN_ID = '1'

Expand All @@ -37,11 +31,11 @@ describe('SetupCalibrationItem', () => {
}

beforeEach(() => {
when(mockUseRunHasStarted).calledWith(RUN_ID).mockReturnValue(false)
when(vi.mocked(useRunHasStarted)).calledWith(RUN_ID).thenReturn(false)
})

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

it('renders all nodes with prop contents', () => {
Expand All @@ -51,9 +45,9 @@ describe('SetupCalibrationItem', () => {
screen.getByRole('button', { name: 'stub button' })
})
it('renders calibrated date if there is no subtext', () => {
when(mockFormatTimestamp)
when(vi.mocked(formatTimestamp))
.calledWith('Thursday, September 9, 2021')
.mockReturnValue('09/09/2021 00:00:00')
.thenReturn('09/09/2021 00:00:00')
render({
calibratedDate: 'Thursday, September 9, 2021',
})
Expand All @@ -64,7 +58,7 @@ describe('SetupCalibrationItem', () => {
screen.getByText('Not calibrated yet')
})
it('renders calibration data not available if run has started', () => {
when(mockUseRunHasStarted).calledWith(RUN_ID).mockReturnValue(true)
when(vi.mocked(useRunHasStarted)).calledWith(RUN_ID).thenReturn(true)
render()
screen.getByText('Calibration data not available once run has started')
})
Expand Down

0 comments on commit a6f4651

Please sign in to comment.