Skip to content

Commit

Permalink
the last phase of tests under nested folders
Browse files Browse the repository at this point in the history
  • Loading branch information
koji committed Mar 1, 2024
1 parent fa44e54 commit aee12fe
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 175 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import * as React from 'react'
import { StaticRouter } from 'react-router-dom'
import _uncastedProtocolWithTC from '@opentrons/shared-data/protocol/fixtures/6/multipleTipracksWithTC.json'
import { renderWithProviders } from '@opentrons/components'
import { describe, it, beforeEach, vi, expect } from 'vitest'
import { screen } from '@testing-library/react'

import { multiple_tipacks_with_tc } from '@opentrons/shared-data'

import { renderWithProviders } from '../../../../../__testing-utils__'
import { i18n } from '../../../../../i18n'
import { mockDefinition } from '../../../../../redux/custom-labware/__fixtures__'
import { SetupLabwareList } from '../SetupLabwareList'
Expand All @@ -11,13 +15,9 @@ import type {
RunTimeCommand,
} from '@opentrons/shared-data'

jest.mock('../LabwareListItem')

const protocolWithTC = (_uncastedProtocolWithTC as unknown) as CompletedProtocolAnalysis
vi.mock('../LabwareListItem')

const mockLabwareListItem = LabwareListItem as jest.MockedFunction<
typeof LabwareListItem
>
const protocolWithTC = (multiple_tipacks_with_tc as unknown) as CompletedProtocolAnalysis

const render = (props: React.ComponentProps<typeof SetupLabwareList>) => {
return renderWithProviders(
Expand Down Expand Up @@ -165,10 +165,12 @@ const mockOffDeckCommands = ([

describe('SetupLabwareList', () => {
beforeEach(() => {
mockLabwareListItem.mockReturnValue(<div>mock labware list item</div>)
vi.mocked(LabwareListItem).mockReturnValue(
<div>mock labware list item</div>
)
})
it('renders the correct headers and labware list items', () => {
const { getAllByText, getByText } = render({
render({
commands: protocolWithTC.commands,
extraAttentionModules: [],
attachedModuleInfo: {
Expand All @@ -181,13 +183,13 @@ describe('SetupLabwareList', () => {
isFlex: false,
})

getAllByText('mock labware list item')
getByText('Labware name')
getByText('Location')
getByText('Placement')
screen.getAllByText('mock labware list item')
screen.getByText('Labware name')
screen.getByText('Location')
screen.getByText('Placement')
})
it('renders null for the offdeck labware list when there are none', () => {
const { queryByText } = render({
render({
commands: protocolWithTC.commands,
extraAttentionModules: [],
attachedModuleInfo: {
Expand All @@ -199,17 +201,19 @@ describe('SetupLabwareList', () => {
} as any,
isFlex: false,
})
expect(queryByText('Additional Off-Deck Labware')).not.toBeInTheDocument()
expect(
screen.queryByText('Additional Off-Deck Labware')
).not.toBeInTheDocument()
})

it('renders offdeck labware list when there are additional offdeck labwares', () => {
const { getAllByText, getByText } = render({
render({
commands: mockOffDeckCommands,
extraAttentionModules: [],
attachedModuleInfo: {} as any,
isFlex: false,
})
getByText('Additional Off-Deck Labware')
getAllByText('mock labware list item')
screen.getByText('Additional Off-Deck Labware')
screen.getAllByText('mock labware list item')
})
})
Original file line number Diff line number Diff line change
@@ -1,49 +1,42 @@
import * as React from 'react'
import { renderWithProviders } from '@opentrons/components'
import _uncastedProtocolWithTC from '@opentrons/shared-data/protocol/fixtures/6/multipleTipracksWithTC.json'
import { getLoadedLabwareDefinitionsByUri } from '@opentrons/shared-data'
import { describe, it, beforeEach, vi, expect, afterEach } from 'vitest'
import { screen } from '@testing-library/react'

import {
getLoadedLabwareDefinitionsByUri,
multiple_tipacks_with_tc,
} from '@opentrons/shared-data'

import { renderWithProviders } from '../../../../../__testing-utils__'
import { i18n } from '../../../../../i18n'
import { getIsLabwareOffsetCodeSnippetsOn } from '../../../../../redux/config'
import { LabwarePositionCheck } from '../../../../LabwarePositionCheck'
import { useLPCDisabledReason } from '../../../hooks'
import { CurrentOffsetsTable } from '../CurrentOffsetsTable'
import { getLatestCurrentOffsets } from '../utils'
import { CurrentOffsetsTable } from '../CurrentOffsetsTable'

import type { CompletedProtocolAnalysis } from '@opentrons/shared-data'
import type { LabwareOffset } from '@opentrons/api-client'

jest.mock('../../../hooks')
jest.mock('../../../../LabwarePositionCheck')
jest.mock('../../../../../redux/config')
jest.mock('../utils')
jest.mock('@opentrons/shared-data', () => {
const actualComponents = jest.requireActual('@opentrons/shared-data')
vi.mock('../../../hooks')
vi.mock('../../../../LabwarePositionCheck')
vi.mock('../../../../../redux/config')
vi.mock('../utils')

vi.mock('@opentrons/shared-data', async importOriginal => {
const actual = await importOriginal<typeof getLoadedLabwareDefinitionsByUri>()
return {
...actualComponents,
getLoadedLabwareDefinitionsByUri: jest.fn(),
...actual,
getLoadedLabwareDefinitionsByUri: vi.fn(), // or whatever you want to override the export with
}
})
const mockGetLoadedLabwareDefinitionsByUri = getLoadedLabwareDefinitionsByUri as jest.MockedFunction<
typeof getLoadedLabwareDefinitionsByUri
>
const mockGetIsLabwareOffsetCodeSnippetsOn = getIsLabwareOffsetCodeSnippetsOn as jest.MockedFunction<
typeof getIsLabwareOffsetCodeSnippetsOn
>
const mockGetLatestCurrentOffsets = getLatestCurrentOffsets as jest.MockedFunction<
typeof getLatestCurrentOffsets
>
const mockLabwarePositionCheck = LabwarePositionCheck as jest.MockedFunction<
typeof LabwarePositionCheck
>
const mockUseLPCDisabledReason = useLPCDisabledReason as jest.MockedFunction<
typeof useLPCDisabledReason
>

const render = (props: React.ComponentProps<typeof CurrentOffsetsTable>) => {
return renderWithProviders(<CurrentOffsetsTable {...props} />, {
i18nInstance: i18n,
})[0]
}
const protocolWithTC = (_uncastedProtocolWithTC as unknown) as CompletedProtocolAnalysis
const protocolWithTC = (multiple_tipacks_with_tc as unknown) as CompletedProtocolAnalysis
const mockCurrentOffsets: LabwareOffset[] = [
{
createdAt: '2022-12-20T14:06:23.562082+00:00',
Expand Down Expand Up @@ -95,8 +88,8 @@ describe('CurrentOffsetsTable', () => {
},
],
}
mockUseLPCDisabledReason.mockReturnValue(null)
mockGetLoadedLabwareDefinitionsByUri.mockReturnValue({
vi.mocked(useLPCDisabledReason).mockReturnValue(null)
vi.mocked(getLoadedLabwareDefinitionsByUri).mockReturnValue({
fixedTrash: {
displayName: 'Trash',
definitionId: 'opentrons/opentrons_1_trash_1100ml_fixed/1',
Expand All @@ -118,11 +111,11 @@ describe('CurrentOffsetsTable', () => {
definitionId: 'opentrons/nest_96_wellplate_100ul_pcr_full_skirt/1',
},
} as any)
mockLabwarePositionCheck.mockReturnValue(
vi.mocked(LabwarePositionCheck).mockReturnValue(
<div>mock labware position check</div>
)
mockGetIsLabwareOffsetCodeSnippetsOn.mockReturnValue(false)
mockGetLatestCurrentOffsets.mockReturnValue([
vi.mocked(getIsLabwareOffsetCodeSnippetsOn).mockReturnValue(false)
vi.mocked(getLatestCurrentOffsets).mockReturnValue([
{
createdAt: '2022-12-20T14:06:23.562082+00:00',
definitionUri: 'opentrons/opentrons_96_tiprack_10ul/1',
Expand All @@ -132,25 +125,30 @@ describe('CurrentOffsetsTable', () => {
},
])
})

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

it('renders the correct text', () => {
const { getByText } = render(props)
getByText('APPLIED LABWARE OFFSET DATA')
getByText('location')
getByText('labware')
getByText('labware offset data')
render(props)
screen.getByText('APPLIED LABWARE OFFSET DATA')
screen.getByText('location')
screen.getByText('labware')
screen.getByText('labware offset data')
})

it('renders 1 offset with the correct information', () => {
const { getByText } = render(props)
getByText('opentrons/opentrons_96_tiprack_10ul/1')
getByText('Slot 2')
render(props)
screen.getByText('opentrons/opentrons_96_tiprack_10ul/1')
screen.getByText('Slot 2')
})

it('renders tabbed offset data with snippets when config option is selected', () => {
mockGetIsLabwareOffsetCodeSnippetsOn.mockReturnValue(true)
const { getByText } = render(props)
expect(getByText('Table View')).toBeTruthy()
expect(getByText('Jupyter Notebook')).toBeTruthy()
expect(getByText('Command Line Interface (SSH)')).toBeTruthy()
vi.mocked(getIsLabwareOffsetCodeSnippetsOn).mockReturnValue(true)
render(props)
expect(screen.getByText('Table View')).toBeTruthy()
expect(screen.getByText('Jupyter Notebook')).toBeTruthy()
expect(screen.getByText('Command Line Interface (SSH)')).toBeTruthy()
})
})
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, vi, beforeEach, expect } from 'vitest'

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

Expand All @@ -13,47 +15,51 @@ const render = (props: React.ComponentProps<typeof HowLPCWorksModal>) => {
describe('HowLPCWorksModal', () => {
let props: React.ComponentProps<typeof HowLPCWorksModal>
beforeEach(() => {
props = { onCloseClick: jest.fn() }
props = { onCloseClick: vi.fn() }
})

it('should render the correct header', () => {
const { getByRole } = render(props)
getByRole('heading', { name: 'How labware offsets work' })
render(props)
screen.getByRole('heading', { name: 'How labware offsets work' })
})
it('should render the correct body', () => {
const { getByText } = render(props)
getByText(
render(props)
screen.getByText(
'A Labware Offset is a type of positional adjustment that accounts for small, real-world variances in the overall position of the labware on a robot’s deck. Labware Offset data is unique to a specific combination of labware definition, deck slot, and robot.'
)
getByText(
screen.getByText(
'Labware Position Check is intended to correct for minor variances. Opentrons does not recommend using Labware Position Check to compensate for large positional adjustments. Needing to set large labware offsets could indicate a problem with robot calibration.'
)
})

it('should render a link to robot cal', () => {
const { getByRole } = render(props)
render(props)
expect(
getByRole('link', {
name: 'Learn more about Robot Calibration',
}).getAttribute('href')
screen
.getByRole('link', {
name: 'Learn more about Robot Calibration',
})
.getAttribute('href')
).toBe(
'https://support.opentrons.com/s/article/How-positional-calibration-works-on-the-OT-2'
)
})
it('should render a link to the learn more page', () => {
const { getByRole } = render(props)
render(props)
expect(
getByRole('link', {
name: 'Learn more about Labware Offset Data',
}).getAttribute('href')
screen
.getByRole('link', {
name: 'Learn more about Labware Offset Data',
})
.getAttribute('href')
).toBe(
'https://support.opentrons.com/s/article/How-Labware-Offsets-work-on-the-OT-2'
)
})
it('should call onCloseClick when the close button is pressed', () => {
const { getByRole } = render(props)
render(props)
expect(props.onCloseClick).not.toHaveBeenCalled()
const closeButton = getByRole('button', { name: 'close' })
const closeButton = screen.getByRole('button', { name: 'close' })
fireEvent.click(closeButton)
expect(props.onCloseClick).toHaveBeenCalled()
})
Expand Down
Loading

0 comments on commit aee12fe

Please sign in to comment.