Skip to content

Commit

Permalink
add test for EditInstrumentModal
Browse files Browse the repository at this point in the history
  • Loading branch information
koji committed Jan 9, 2025
1 parent 991e9ef commit f6c6b41
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
import { fireEvent, screen } from '@testing-library/react'

import { FLEX_ROBOT_TYPE } from '@opentrons/shared-data'
Expand All @@ -7,15 +7,23 @@ import { renderWithProviders } from '../../../__testing-utils__'
import { i18n } from '../../../assets/localization'

import { getRobotType } from '../../../file-data/selectors'
import {
getAdditionalEquipment,
getInitialDeckSetup,
} from '../../../step-forms/selectors'
import { getHas96Channel } from '../../../utils'
import { usePipetteConfig } from '../usePipetteConfig'
import { PipetteOverview } from '../PipetteOverview'
import { PipetteConfiguration } from '../PipetteConfiguration'

import { EditInstrumentsModal } from '..'

import type { ComponentProps } from 'react'
import { fi } from 'date-fns/locale'

Check failure on line 22 in protocol-designer/src/organisms/EditInstrumentsModal/__tests__/EditInstrumentsModal.test.tsx

View workflow job for this annotation

GitHub Actions / js checks

'fi' is defined but never used

Check failure on line 22 in protocol-designer/src/organisms/EditInstrumentsModal/__tests__/EditInstrumentsModal.test.tsx

View workflow job for this annotation

GitHub Actions / js checks

'fi' is defined but never used

vi.mock('../../../file-data/selectors')
vi.mock('../../../step-forms/selectors')
vi.mock('../../../utils')
vi.mock('../usePipetteConfig')
vi.mock('../PipetteOverview')
vi.mock('../PipetteConfiguration')
Expand All @@ -39,7 +47,7 @@ describe('EditInstrumentsModal', () => {
vi.mocked(usePipetteConfig).mockReturnValue({
page: 'add',
mount: 'left',
pipetteType: '96',
pipetteType: 'single',
pipetteGen: 'flex',
pipetteVolume: 'p1000',
selectedTips: ['A1'],
Expand All @@ -55,12 +63,90 @@ describe('EditInstrumentsModal', () => {
vi.mocked(PipetteConfiguration).mockReturnValue(
<div>mock PipetteConfiguration</div>
)
vi.mocked(getInitialDeckSetup).mockReturnValue({
pipettes: {},
additionalEquipmentOnDeck: {},
modules: {},
labware: {},
})
vi.mocked(getHas96Channel).mockReturnValue(false)
vi.mocked(getAdditionalEquipment).mockReturnValue({})
})

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

it('should render text and buttons - pipette configuration', () => {
render(props)
screen.getByText('Edit Pipette')
screen.getByText('mock PipetteConfiguration')
screen.getByText('Save')
screen.getByText('Back')
})

it('should render text and buttons', () => {
it('should render text and buttons - pipette overview', () => {
vi.mocked(usePipetteConfig).mockReturnValue({
page: 'overview',
mount: 'left',
pipetteType: 'single',
pipetteGen: 'flex',
pipetteVolume: 'p1000',
selectedTips: ['A1'],
setPage: vi.fn(),
setMount: vi.fn(),
setPipetteType: vi.fn(),
setPipetteGen: vi.fn(),
setPipetteVolume: vi.fn(),
setSelectedTips: vi.fn(),
resetFields: vi.fn(),
})
render(props)
screen.getByText('Edit Instruments')
screen.getByText('mock PipetteOverview')
screen.getByText('Save')
screen.getByText('Cancel')
})

it('should render text and buttons - pipette overview', () => {
vi.mocked(usePipetteConfig).mockReturnValue({
page: 'overview',
mount: 'left',
pipetteType: 'single',
pipetteGen: 'flex',
pipetteVolume: 'p1000',
selectedTips: ['A1'],
setPage: vi.fn(),
setMount: vi.fn(),
setPipetteType: vi.fn(),
setPipetteGen: vi.fn(),
setPipetteVolume: vi.fn(),
setSelectedTips: vi.fn(),
resetFields: vi.fn(),
})
render(props)
fireEvent.click(screen.getByText('Save'))
expect(mockOnClose).toHaveBeenCalled()
})

it('should render text and buttons - pipette overview', () => {
vi.mocked(usePipetteConfig).mockReturnValue({
page: 'overview',
mount: 'left',
pipetteType: 'single',
pipetteGen: 'flex',
pipetteVolume: 'p1000',
selectedTips: ['A1'],
setPage: vi.fn(),
setMount: vi.fn(),
setPipetteType: vi.fn(),
setPipetteGen: vi.fn(),
setPipetteVolume: vi.fn(),
setSelectedTips: vi.fn(),
resetFields: vi.fn(),
})
render(props)
fireEvent.click(screen.getByText('Cancel'))
expect(mockOnClose).toHaveBeenCalled()
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ export function EditInstrumentsModal(
resetFields,
} = pipetteConfig

console.log('obj', JSON.stringify(pipettesOnDeck, null, 4))

const selectedPipette =
pipetteType === '96' || pipetteGen === 'GEN1'
? `${pipetteVolume}_${pipetteType}`
Expand Down

0 comments on commit f6c6b41

Please sign in to comment.