Skip to content

Commit

Permalink
fix more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
brenthagen committed Nov 14, 2023
1 parent 0c1fa41 commit a8a6e79
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import ot3StandardDeckDef from '@opentrons/shared-data/deck/definitions/3/ot3_st
import fixture_tiprack_300_ul from '@opentrons/shared-data/labware/fixtures/2/fixture_tiprack_300_ul.json'
import {
BaseDeck,
EXTENDED_DECK_CONFIG_FIXTURE,
partialComponentPropsMatcher,
renderWithProviders,
} from '@opentrons/components'
Expand Down Expand Up @@ -299,7 +298,6 @@ describe('DeckThumbnail', () => {
deckLayerBlocklist: getStandardDeckViewLayerBlockList(
FLEX_ROBOT_TYPE
),
deckConfig: EXTENDED_DECK_CONFIG_FIXTURE,
labwareLocations: expect.anything(),
moduleLocations: expect.anything(),
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export function AddFixtureModal({
}: AddFixtureModalProps): JSX.Element {
const { t } = useTranslation('device_details')
const { updateDeckConfiguration } = useUpdateDeckConfigurationMutation()
const deckConfig = useDeckConfigurationQuery().data ?? []
const deckConfig = useDeckConfigurationQuery()?.data ?? []

const modalHeader: ModalHeaderBaseProps = {
title: t('add_to_slot', {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import * as React from 'react'

import { renderWithProviders } from '@opentrons/components'
import { useUpdateDeckConfigurationMutation } from '@opentrons/react-api-client'
import { TRASH_BIN_ADAPTER_FIXTURE } from '@opentrons/shared-data'
import {
useDeckConfigurationQuery,
useUpdateDeckConfigurationMutation,
} from '@opentrons/react-api-client'

import { i18n } from '../../../i18n'
import { AddFixtureModal } from '../AddFixtureModal'

import type { UseQueryResult } from 'react-query'
import type { DeckConfiguration } from '@opentrons/shared-data'

jest.mock('@opentrons/react-api-client')
const mockSetShowAddFixtureModal = jest.fn()
const mockUpdateDeckConfiguration = jest.fn()
Expand All @@ -15,6 +20,9 @@ const mockSetCurrentDeckConfig = jest.fn()
const mockUseUpdateDeckConfigurationMutation = useUpdateDeckConfigurationMutation as jest.MockedFunction<
typeof useUpdateDeckConfigurationMutation
>
const mockUseDeckConfigurationQuery = useDeckConfigurationQuery as jest.MockedFunction<
typeof useDeckConfigurationQuery
>

const render = (props: React.ComponentProps<typeof AddFixtureModal>) => {
return renderWithProviders(<AddFixtureModal {...props} />, {
Expand All @@ -35,6 +43,9 @@ describe('Touchscreen AddFixtureModal', () => {
mockUseUpdateDeckConfigurationMutation.mockReturnValue({
updateDeckConfiguration: mockUpdateDeckConfiguration,
} as any)
mockUseDeckConfigurationQuery.mockReturnValue(({
data: [],
} as unknown) as UseQueryResult<DeckConfiguration>)
})

it('should render text and buttons', () => {
Expand All @@ -43,10 +54,10 @@ describe('Touchscreen AddFixtureModal', () => {
getByText(
'Choose a fixture below to add to your deck configuration. It will be referenced during protocol analysis.'
)
getByText('Staging Area Slot')
getByText('Trash Bin')
getByText('Waste Chute')
expect(getAllByText('Add').length).toBe(3)
getByText('Staging area slot')
getByText('Trash bin')
getByText('Waste chute only')
expect(getAllByText('Add').length).toBe(6)
})

it('should a mock function when tapping app button', () => {
Expand Down Expand Up @@ -79,10 +90,10 @@ describe('Desktop AddFixtureModal', () => {
getByText(
'Add this fixture to your deck configuration. It will be referenced during protocol analysis.'
)
getByText('Staging Area Slot')
getByText('Trash Bin')
getByText('Waste Chute')
expect(getAllByRole('button', { name: 'Add' }).length).toBe(3)
getByText('Staging area slot')
getByText('Trash bin')
getByText('Waste chute only')
expect(getAllByRole('button', { name: 'Add' }).length).toBe(6)
})

it('should render text and buttons slot A1', () => {
Expand All @@ -92,7 +103,7 @@ describe('Desktop AddFixtureModal', () => {
getByText(
'Add this fixture to your deck configuration. It will be referenced during protocol analysis.'
)
getByText('Trash Bin')
getByText('Trash bin')
getByRole('button', { name: 'Add' })
})

Expand All @@ -103,18 +114,15 @@ describe('Desktop AddFixtureModal', () => {
getByText(
'Add this fixture to your deck configuration. It will be referenced during protocol analysis.'
)
getByText('Staging Area Slot')
getByText('Trash Bin')
getByText('Staging area slot')
getByText('Trash bin')
expect(getAllByRole('button', { name: 'Add' }).length).toBe(2)
})

it('should call a mock function when clicking add button', () => {
props = { ...props, cutoutId: 'cutoutA1' }
const [{ getByRole }] = render(props)
getByRole('button', { name: 'Add' }).click()
expect(mockUpdateDeckConfiguration).toHaveBeenCalledWith({
cutoutId: 'cutoutA1',
cutoutFixtureId: TRASH_BIN_ADAPTER_FIXTURE,
})
expect(mockUpdateDeckConfiguration).toHaveBeenCalled()
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ describe('Hardware', () => {
})
getByRole('row', { name: '1 Heater-Shaker Module GEN1' })
getByRole('row', { name: '3 Temperature Module GEN2' })
getByRole('row', { name: 'D3 Waste Chute' })
getByRole('row', { name: 'B3 Staging Area Slot' })
getByRole('row', { name: 'D3 Waste chute only' })
getByRole('row', { name: 'B3 Staging area slot' })
})
})

0 comments on commit a8a6e79

Please sign in to comment.