Skip to content

Commit

Permalink
update LabwareCard test for vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
koji committed Feb 27, 2024
1 parent f1084ea commit 3ca88bc
Showing 1 changed file with 27 additions and 19 deletions.
46 changes: 27 additions & 19 deletions app/src/organisms/LabwareCard/__tests__/LabwareCard.test.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
import * as React from 'react'
import { renderWithProviders, nestedTextMatcher } from '@opentrons/components'
import { screen } from '@testing-library/react'
import { describe, it, expect, vi, beforeEach } from 'vitest'
import {
renderWithProviders,
nestedTextMatcher,
} from '../../../__testing-utils__'
import { i18n } from '../../../i18n'
import { useAllLabware } from '../../../pages/Labware/hooks'
import { mockDefinition } from '../../../redux/custom-labware/__fixtures__'
import { CustomLabwareOverflowMenu } from '../CustomLabwareOverflowMenu'
import { LabwareCard } from '..'

jest.mock('../../../pages/Labware/hooks')
jest.mock('../CustomLabwareOverflowMenu')
jest.mock('@opentrons/components', () => {
const actualComponents = jest.requireActual('@opentrons/components')
import type * as OpentronsComponents from '@opentrons/components'

vi.mock('../../../pages/Labware/hooks')
vi.mock('../CustomLabwareOverflowMenu')

vi.mock('@opentrons/components', async importOriginal => {
const actual = await importOriginal<typeof OpentronsComponents>()
return {
...actualComponents,
RobotWorkSpace: jest.fn(() => <div>mock RobotWorkSpace</div>),
...actual,
RobotWorkSpace: vi.fn(() => <div>mock RobotWorkSpace</div>),
}
})

Expand All @@ -31,34 +39,34 @@ const render = (props: React.ComponentProps<typeof LabwareCard>) => {
describe('LabwareCard', () => {
let props: React.ComponentProps<typeof LabwareCard>
beforeEach(() => {
mockCustomLabwareOverflowMenu.mockReturnValue(
vi.mocked(CustomLabwareOverflowMenu).mockReturnValue(
<div>Mock CustomLabwareOverflowMenu</div>
)
mockUseAllLabware.mockReturnValue([{ definition: mockDefinition }])
vi.mocked(useAllLabware).mockReturnValue([{ definition: mockDefinition }])
props = {
labware: {
definition: mockDefinition,
},
onClick: jest.fn(),
onClick: vi.fn(),
}
})

it('renders correct info for opentrons labware card', () => {
props.labware.definition.namespace = 'opentrons'
const [{ getByText }] = render(props)
getByText('mock RobotWorkSpace')
getByText('Well Plate')
getByText('Mock Definition')
getByText(`Opentrons Definition`)
getByText('API Name')
render(props)
screen.getByText('mock RobotWorkSpace')
screen.getByText('Well Plate')
screen.getByText('Mock Definition')
screen.getByText(`Opentrons Definition`)
screen.getByText('API Name')
})

it('renders additional info for custom labware card', () => {
props.labware.modified = 123
props.labware.filename = 'mock/filename'
props.labware.definition.namespace = 'custom'
const [{ getByText }] = render(props)
getByText('Custom Definition')
getByText(nestedTextMatcher('Added'))
render(props)
screen.getByText('Custom Definition')
screen.getByText(nestedTextMatcher('Added'))
})
})

0 comments on commit 3ca88bc

Please sign in to comment.