Skip to content

Commit

Permalink
update some devices tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jerader committed Feb 26, 2024
1 parent 511c365 commit b96cb2b
Show file tree
Hide file tree
Showing 45 changed files with 907 additions and 1,188 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import * as React from 'react'
import { Provider } from 'react-redux'
import { describe, it, vi, beforeEach, expect } from 'vitest'
import '@testing-library/jest-dom/vitest'
import { createStore } from 'redux'
import { renderHook } from '@testing-library/react'
import { HEATERSHAKER_MODULE_V1 } from '@opentrons/shared-data'
Expand All @@ -10,26 +12,18 @@ import { RUN_ID_1 } from '../../../RunTimeControl/__fixtures__'
import type { Store } from 'redux'
import type { State } from '../../../../redux/types'

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

const mockUseMostRecentCompletedAnalysis = useMostRecentCompletedAnalysis as jest.MockedFunction<
typeof useMostRecentCompletedAnalysis
>
vi.mock('../../hooks')
vi.mock('../../../LabwarePositionCheck/useMostRecentCompletedAnalysis')

describe('useHeaterShakerModuleIdsFromRun', () => {
const store: Store<State> = createStore(jest.fn(), {})
const store: Store<State> = createStore(vi.fn(), {})

beforeEach(() => {
store.dispatch = jest.fn()
})

afterEach(() => {
jest.restoreAllMocks()
store.dispatch = vi.fn()
})

it('should return a heater shaker module id from protocol analysis load command result', () => {
mockUseMostRecentCompletedAnalysis.mockReturnValue({
vi.mocked(useMostRecentCompletedAnalysis).mockReturnValue({
pipettes: {},
labware: {},
modules: {
Expand Down Expand Up @@ -76,7 +70,7 @@ describe('useHeaterShakerModuleIdsFromRun', () => {
})

it('should return two heater shaker module ids if two modules are loaded in the protocol', () => {
mockUseMostRecentCompletedAnalysis.mockReturnValue({
vi.mocked(useMostRecentCompletedAnalysis).mockReturnValue({
pipettes: {},
labware: {},
modules: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import * as React from 'react'
import { renderWithProviders } from '@opentrons/components'
import { screen } from '@testing-library/react'
import { describe, it, vi, beforeEach } from 'vitest'
import '@testing-library/jest-dom/vitest'
import { renderWithProviders } from '../../../../__testing-utils__'
import { i18n } from '../../../../i18n'
import { HeaterShakerModuleCard } from '../HeaterShakerModuleCard'
import { HeaterShakerModuleData } from '../../../ModuleCard/HeaterShakerModuleData'
import { mockHeaterShaker } from '../../../../redux/modules/__fixtures__'

jest.mock('../../../ModuleCard/HeaterShakerModuleData')

const mockHeaterShakerModuleData = HeaterShakerModuleData as jest.MockedFunction<
typeof HeaterShakerModuleData
>
vi.mock('../../../ModuleCard/HeaterShakerModuleData')

const render = (props: React.ComponentProps<typeof HeaterShakerModuleCard>) => {
return renderWithProviders(<HeaterShakerModuleCard {...props} />, {
Expand All @@ -23,17 +22,17 @@ describe('HeaterShakerModuleCard', () => {
props = {
module: mockHeaterShaker,
}
mockHeaterShakerModuleData.mockReturnValue(
vi.mocked(HeaterShakerModuleData).mockReturnValue(
<div>mock heater shaker module data</div>
)
})

it('renders the correct info', () => {
const { getByText, getByAltText, getByLabelText } = render(props)
getByText('usb-1')
getByText('Heater-Shaker Module GEN1')
getByText('mock heater shaker module data')
getByAltText('Heater-Shaker')
getByLabelText('heater-shaker')
render(props)
screen.getByText('usb-1')
screen.getByText('Heater-Shaker Module GEN1')
screen.getByText('mock heater shaker module data')
screen.getByAltText('Heater-Shaker')
screen.getByLabelText('heater-shaker')
})
})
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import * as React from 'react'
import { renderWithProviders } from '@opentrons/components'
import { describe, it, vi, beforeEach, expect } from 'vitest'
import '@testing-library/jest-dom/vitest'
import { renderWithProviders } from '../../../../__testing-utils__'
import { useInstrumentsQuery } from '@opentrons/react-api-client'
import { fireEvent } from '@testing-library/react'
import { fireEvent, screen } from '@testing-library/react'
import { i18n } from '../../../../i18n'
import { AboutPipetteSlideout } from '../AboutPipetteSlideout'
import { mockLeftSpecs } from '../../../../redux/pipettes/__fixtures__'
import { LEFT } from '../../../../redux/pipettes'

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

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

const render = (props: React.ComponentProps<typeof AboutPipetteSlideout>) => {
return renderWithProviders(<AboutPipetteSlideout {...props} />, {
Expand All @@ -27,28 +25,25 @@ describe('AboutPipetteSlideout', () => {
pipetteName: mockLeftSpecs.displayName,
mount: LEFT,
isExpanded: true,
onCloseClick: jest.fn(),
onCloseClick: vi.fn(),
}
mockUseInstrumentsQuery.mockReturnValue({
vi.mocked(useInstrumentsQuery).mockReturnValue({
data: { data: [] },
} as any)
})
afterEach(() => {
jest.resetAllMocks()
})

it('renders correct info', () => {
const { getByText, getByRole } = render(props)
render(props)

getByText('About Left Pipette Pipette')
getByText('123')
getByText('SERIAL NUMBER')
const button = getByRole('button', { name: /exit/i })
screen.getByText('About Left Pipette Pipette')
screen.getByText('123')
screen.getByText('SERIAL NUMBER')
const button = screen.getByRole('button', { name: /exit/i })
fireEvent.click(button)
expect(props.onCloseClick).toHaveBeenCalled()
})
it('renders the firmware version if it exists', () => {
mockUseInstrumentsQuery.mockReturnValue({
vi.mocked(useInstrumentsQuery).mockReturnValue({
data: {
data: [
{
Expand All @@ -61,9 +56,9 @@ describe('AboutPipetteSlideout', () => {
},
} as any)

const { getByText } = render(props)
render(props)

getByText('CURRENT VERSION')
getByText('12')
screen.getByText('CURRENT VERSION')
screen.getByText('12')
})
})
Loading

0 comments on commit b96cb2b

Please sign in to comment.