Skip to content

Commit

Permalink
fix app test errors
Browse files Browse the repository at this point in the history
  • Loading branch information
koji committed Mar 1, 2024
1 parent 485addb commit 8fb9f62
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 54 deletions.
35 changes: 21 additions & 14 deletions app/src/assets/labware/__tests__/findLabware.test.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,44 @@
import { describe, it, vi, afterEach, expect } from 'vitest'

import { fixtureTiprack10ul, fixtureTiprack300ul } from '@opentrons/shared-data'

import { getLatestLabwareDef } from '../getLabware'
import { findLabwareDefWithCustom } from '../findLabware'

import type { LabwareDefinition2 } from '@opentrons/shared-data'
import fixture_tiprack_10_ul from '@opentrons/shared-data/labware/fixtures/2/fixture_tiprack_10_ul.json'
import fixture_tiprack_300_ul from '@opentrons/shared-data/labware/fixtures/2/fixture_tiprack_300_ul.json'

jest.mock('../getLabware', () => ({
getLatestLabwareDef: jest.fn(),
}))
vi.mock('../getLabware', async importOriginal => {
const actual = await importOriginal<typeof getLatestLabwareDef>()
return {
...actual,
getLatestLabwareDef: vi.fn(),
}
})

const mockGetLabware = getLatestLabwareDef as jest.MockedFunction<
typeof getLatestLabwareDef
>

const fixtureTipRack10ul = fixture_tiprack_10_ul as LabwareDefinition2
const fixtureTipRack10ul = fixtureTiprack10ul as LabwareDefinition2

const fixtureTipRack10ulCustomBeta = {
...fixture_tiprack_10_ul,
...fixtureTiprack10ul,
namespace: 'custom_beta',
} as LabwareDefinition2

const fixtureTipRack10ulVersion2 = {
...fixture_tiprack_10_ul,
...fixtureTiprack10ul,
version: 2,
} as LabwareDefinition2

const fixtureTipRack300ulOpentrons = {
...fixture_tiprack_300_ul,
...fixtureTiprack300ul,
namespace: 'opentrons',
} as LabwareDefinition2

describe('findLabwareDefWithCustom', () => {
afterEach(() => {
jest.resetAllMocks()
vi.resetAllMocks()
})

it('finds standard labware with namesearch', () => {
Expand Down Expand Up @@ -63,16 +70,16 @@ describe('findLabwareDefWithCustom', () => {
const SPECS = [
{
should: 'find nothing with no specs',
customLabware: [fixture_tiprack_10_ul, fixture_tiprack_300_ul],
customLabware: [fixtureTiprack10ul, fixtureTiprack300ul],
expect: null,
namespace: null,
loadName: null,
version: null,
},
{
should: 'find the first item with only namespace',
customLabware: [fixture_tiprack_10_ul, fixture_tiprack_300_ul],
expect: fixture_tiprack_10_ul,
customLabware: [fixtureTiprack10ul, fixtureTiprack300ul],
expect: fixtureTiprack10ul,
namespace: 'fixture',
loadName: null,
version: null,
Expand All @@ -92,7 +99,7 @@ describe('findLabwareDefWithCustom', () => {
{
should: 'find the right item with loadName and namespace',
customLabware: [
fixture_tiprack_10_ul,
fixtureTiprack10ul,
fixtureTipRack10ulCustomBeta,
fixtureTipRack10ulVersion2,
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react'
import { describe, it, expect, vi } from 'vitest'
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { when } from 'vitest-when'
import { renderHook, waitFor } from '@testing-library/react'
import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fixture_tiprack_10_ul from '@opentrons/shared-data/labware/fixtures/2/fixture_tiprack_10_ul.json'
import { describe, it, expect } from 'vitest'
import { fixture_tiprack_10_ul } from '@opentrons/shared-data'
import { getFinalLabwareLocation } from '../getFinalLabwareLocation'
import type { LabwareDefinition2 } from '@opentrons/shared-data'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ import { renderWithProviders } from '../../../__testing-utils__'
import { i18n } from '../../../i18n'
import { DeckConfigurationDiscardChangesModal } from '../DeckConfigurationDiscardChangesModal'

import type * as ReactRouterDom from 'react-router-dom'

const mockFunc = vi.fn()
const mockGoBack = vi.fn()
const mockPush = vi.fn()

vi.mock('react-router-dom', () => {
const reactRouterDom = vi.requireActual('react-router-dom')
vi.mock('react-router-dom', async importOriginal => {
const reactRouterDom = await importOriginal<typeof ReactRouterDom>()
return {
...reactRouterDom,
useHistory: () => ({ goBack: mockGoBack } as any),
useHistory: () => ({ push: mockPush } as any),
}
})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react'
import { when } from 'vitest-when'
import { describe, it, beforeEach, vi, afterEach, expect } from 'vitest'
import { describe, it, beforeEach, vi, afterEach } from 'vitest'
import { screen } from '@testing-library/react'

import { renderWithProviders } from '../../../../__testing-utils__'
Expand Down Expand Up @@ -59,11 +59,9 @@ const render = (

describe('ProtocolRunModuleControls', () => {
beforeEach(() => {
when(vi.mocked(useInstrumentsQuery))
.calledWith()
.thenReturn({
data: { data: [] },
} as any)
vi.mocked(useInstrumentsQuery).mockReturnValue({
data: { data: [] },
} as any)
})

afterEach(() => {
Expand All @@ -86,7 +84,7 @@ describe('ProtocolRunModuleControls', () => {
attachedModuleMatch: mockMagneticModuleGen2,
},
} as any)
when(vi.mocked(ModuleCard)).thenReturn(<div>mock Magnetic Module Card</div>)
vi.mocked(ModuleCard).mockReturnValue(<div>mock Magnetic Module Card</div>)
render({
robotName: 'otie',
runId: 'test123',
Expand All @@ -111,7 +109,7 @@ describe('ProtocolRunModuleControls', () => {
attachedModuleMatch: mockTemperatureModuleGen2,
},
} as any)
when(vi.mocked(ModuleCard)).thenReturn(
vi.mocked(ModuleCard).mockReturnValue(
<div>mock Temperature Module Card</div>
)
render({
Expand Down Expand Up @@ -139,7 +137,7 @@ describe('ProtocolRunModuleControls', () => {
},
} as any)

when(vi.mocked(ModuleCard)).thenReturn(
vi.mocked(ModuleCard).mockReturnValue(
<div>mock Thermocycler Module Card</div>
)

Expand Down Expand Up @@ -167,7 +165,7 @@ describe('ProtocolRunModuleControls', () => {
attachedModuleMatch: mockHeaterShaker,
},
} as any)
when(vi.mocked(ModuleCard)).thenReturn(
vi.mocked(ModuleCard).mockReturnValue(
<div>mock Heater-Shaker Module Card</div>
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import * as React from 'react'
import { when, resetAllWhenMocks } from 'jest-when'
import { when } from 'vitest-when'
import { describe, it, beforeEach, vi, afterEach, expect } from 'vitest'
import { screen } from '@testing-library/react'

import { renderWithProviders } from '../../../../__testing-utils__'}
import { renderWithProviders } from '../../../../__testing-utils__'
import { i18n } from '../../../../i18n'
import { mockDeckCalData } from '../../../../redux/calibration/__fixtures__'
import { mockPipetteInfo } from '../../../../redux/pipettes/__fixtures__'
import { useDeckCalibrationData } from '../../hooks'
import { SetupPipetteCalibrationItem } from '../SetupPipetteCalibrationItem'
import { MemoryRouter } from 'react-router-dom'

jest.mock('../../hooks')
vi.mock('../../hooks')

const mockUseDeckCalibrationData = useDeckCalibrationData as jest.MockedFunction<
typeof useDeckCalibrationData
Expand Down Expand Up @@ -42,23 +44,23 @@ describe('SetupPipetteCalibrationItem', () => {
}

beforeEach(() => {
when(mockUseDeckCalibrationData).calledWith(ROBOT_NAME).mockReturnValue({
when(mockUseDeckCalibrationData).calledWith(ROBOT_NAME).thenReturn({
deckCalibrationData: mockDeckCalData,
isDeckCalibrated: true,
})
})
afterEach(() => {
resetAllWhenMocks()
vi.clearAllMocks()
})

it('renders the mount and pipette name', () => {
const { getByText } = render()
getByText('Left Mount')
getByText(mockPipetteInfo.pipetteSpecs.displayName)
render()
screen.getByText('Left Mount')
screen.getByText(mockPipetteInfo.pipetteSpecs.displayName)
})

it('renders a link to the calibration dashboard if pipette attached but not calibrated', () => {
const { getByText, getByRole } = render({
render({
pipetteInfo: {
...mockPipetteInfo,
tipRacksForPipette: [],
Expand All @@ -67,23 +69,25 @@ describe('SetupPipetteCalibrationItem', () => {
},
})

getByText('Not calibrated yet')
screen.getByText('Not calibrated yet')
expect(
getByRole('link', {
name: 'Calibrate now',
}).getAttribute('href')
screen
.getByRole('link', {
name: 'Calibrate now',
})
.getAttribute('href')
).toBe('/devices/otie/robot-settings/calibration/dashboard')
})
it('renders the pipette mismatch info if pipette calibrated but an inexact match', () => {
const { getByText, getByRole } = render({
render({
pipetteInfo: {
...mockPipetteInfo,
tipRacksForPipette: [],
requestedPipetteMatch: 'inexact_match',
pipetteCalDate: 'september 3, 2020',
},
})
getByRole('link', { name: 'Learn more' })
getByText('Pipette generation mismatch.')
screen.getByRole('link', { name: 'Learn more' })
screen.getByText('Pipette generation mismatch.')
})
})
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import _protocolWithMagTempTC from '@opentrons/shared-data/protocol/fixtures/6/transferSettings.json'
import _standardDeckDef from '@opentrons/shared-data/deck/definitions/4/ot2_standard.json'
import { describe, it, expect } from 'vitest'

import { transfer_settings, ot2DeckDefV4 } from '@opentrons/shared-data'
import { getLabwareRenderInfo } from '../getLabwareRenderInfo'
import type {
CompletedProtocolAnalysis,
LoadLabwareRunTimeCommand,
} from '@opentrons/shared-data'

const protocolWithMagTempTC = (_protocolWithMagTempTC as unknown) as CompletedProtocolAnalysis
const standardDeckDef = _standardDeckDef as any
const protocolWithMagTempTC = (transfer_settings as unknown) as CompletedProtocolAnalysis
const standardDeckDef = ot2DeckDefV4 as any

describe('getLabwareRenderInfo', () => {
it('should gather labware coordinates', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, vi, expect, beforeEach } from 'vitest'
import { getLabwareDisplayName, ModuleModel } from '@opentrons/shared-data'
import { getLocationInfoNames } from '../getLocationInfoNames'

Expand Down Expand Up @@ -118,14 +119,11 @@ const MOCK_ADAPTER_COMMANDS = [
},
]

jest.mock('@opentrons/shared-data')
const mockGetLabwareDisplayName = getLabwareDisplayName as jest.MockedFunction<
typeof getLabwareDisplayName
>
vi.mock('@opentrons/shared-data')

describe('getLocationInfoNames', () => {
beforeEach(() => {
mockGetLabwareDisplayName.mockReturnValue(LABWARE_DISPLAY_NAME)
vi.mocked(getLabwareDisplayName).mockReturnValue(LABWARE_DISPLAY_NAME)
})
it('returns labware name and slot number for labware id on the deck', () => {
const expected = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest'
import { RunTimeCommand } from '@opentrons/shared-data'
import { mockDefinition } from '../../../../../redux/custom-labware/__fixtures__'
import { getSlotLabwareDefinition } from '../getSlotLabwareDefinition'
Expand Down

0 comments on commit 8fb9f62

Please sign in to comment.