Skip to content

Commit

Permalink
fix json import and import vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
koji committed Mar 1, 2024
1 parent 32718c8 commit e4afa9d
Showing 1 changed file with 21 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { when, resetAllWhenMocks } from 'jest-when'
import { when } from 'vitest-when'
import { describe, it, beforeEach, vi, expect, afterEach } from 'vitest'

import {
CompletedProtocolAnalysis,
getLabwareDefURI,
multiple_tipacks_with_tc,
opentrons96PcrAdapterV1,
} from '@opentrons/shared-data'
import _uncastedProtocolWithTC from '@opentrons/shared-data/protocol/fixtures/6/multipleTipracksWithTC.json'
import fixture_adapter from '@opentrons/shared-data/labware/definitions/2/opentrons_96_pcr_adapter/1.json'
import { getLabwareOffsetLocation } from '../getLabwareOffsetLocation'
import { getLabwareLocation } from '../getLabwareLocation'
import { getModuleInitialLoadInfo } from '../getModuleInitialLoadInfo'
Expand All @@ -14,24 +16,17 @@ import type {
LabwareDefinition2,
} from '@opentrons/shared-data'

jest.mock('../getLabwareLocation')
jest.mock('../getModuleInitialLoadInfo')
vi.mock('../getLabwareLocation')
vi.mock('../getModuleInitialLoadInfo')

const protocolWithTC = (_uncastedProtocolWithTC as unknown) as CompletedProtocolAnalysis
const mockAdapterDef = fixture_adapter as LabwareDefinition2
const protocolWithTC = (multiple_tipacks_with_tc as unknown) as CompletedProtocolAnalysis
const mockAdapterDef = opentrons96PcrAdapterV1 as LabwareDefinition2
const mockAdapterId = 'mockAdapterId'
const TCModelInProtocol = 'thermocyclerModuleV1'
const MOCK_SLOT = '2'
const TCIdInProtocol =
'18f0c1b0-0122-11ec-88a3-f1745cf9b36c:thermocyclerModuleType' // this is just taken from the protocol fixture

const mockGetLabwareLocation = getLabwareLocation as jest.MockedFunction<
typeof getLabwareLocation
>
const mockGetModuleInitialLoadInfo = getModuleInitialLoadInfo as jest.MockedFunction<
typeof getModuleInitialLoadInfo
>

describe('getLabwareOffsetLocation', () => {
let MOCK_LABWARE_ID: string
let MOCK_COMMANDS: CompletedProtocolAnalysis['commands']
Expand All @@ -57,44 +52,43 @@ describe('getLabwareOffsetLocation', () => {
]
})
afterEach(() => {
resetAllWhenMocks()
jest.restoreAllMocks()
vi.restoreAllMocks()
})
it('should return just the slot name if the labware is not on top of a module or adapter', () => {
const MOCK_SLOT = '2'
when(mockGetLabwareLocation)
when(vi.mocked(getLabwareLocation))
.calledWith(MOCK_LABWARE_ID, MOCK_COMMANDS)
.mockReturnValue({ slotName: MOCK_SLOT })
.thenReturn({ slotName: MOCK_SLOT })

expect(
getLabwareOffsetLocation(MOCK_LABWARE_ID, MOCK_COMMANDS, MOCK_MODULES, [])
).toEqual({ slotName: MOCK_SLOT })
})
it('should return null if the location is off deck', () => {
when(mockGetLabwareLocation)
when(vi.mocked(getLabwareLocation))
.calledWith(MOCK_LABWARE_ID, MOCK_COMMANDS)
.mockReturnValue('offDeck')
.thenReturn('offDeck')

expect(
getLabwareOffsetLocation(MOCK_LABWARE_ID, MOCK_COMMANDS, MOCK_MODULES, [])
).toEqual(null)
})
it('should return the slot name and module model if the labware is on top of a module', () => {
when(mockGetLabwareLocation)
when(vi.mocked(getLabwareLocation))
.calledWith(MOCK_LABWARE_ID, MOCK_COMMANDS)
.mockReturnValue({ moduleId: TCIdInProtocol })
when(mockGetModuleInitialLoadInfo)
.thenReturn({ moduleId: TCIdInProtocol })
when(vi.mocked(getModuleInitialLoadInfo))
.calledWith(TCIdInProtocol, MOCK_COMMANDS)
.mockReturnValue({ location: { slotName: MOCK_SLOT } } as any)
.thenReturn({ location: { slotName: MOCK_SLOT } } as any)

expect(
getLabwareOffsetLocation(MOCK_LABWARE_ID, MOCK_COMMANDS, MOCK_MODULES, [])
).toEqual({ slotName: MOCK_SLOT, moduleModel: TCModelInProtocol })
})

it('should return the slot name, module model and definition uri for labware on adapter on mod', () => {
mockGetLabwareLocation.mockReturnValue({ labwareId: mockAdapterId })
mockGetModuleInitialLoadInfo.mockReturnValue({
vi.mocked(getLabwareLocation).mockReturnValue({ labwareId: mockAdapterId })
vi.mocked(getModuleInitialLoadInfo).mockReturnValue({
location: { slotName: MOCK_SLOT },
} as any)
expect(
Expand Down Expand Up @@ -122,7 +116,7 @@ describe('getLabwareOffsetLocation', () => {
},
]
MOCK_MODULES = []
mockGetLabwareLocation.mockReturnValue({ labwareId: mockAdapterId })
vi.mocked(getLabwareLocation).mockReturnValue({ labwareId: mockAdapterId })
expect(
getLabwareOffsetLocation(
MOCK_LABWARE_ID,
Expand Down

0 comments on commit e4afa9d

Please sign in to comment.