Skip to content

Commit e4afa9d

Browse files
committed
fix json import and import vitest
1 parent 32718c8 commit e4afa9d

File tree

1 file changed

+21
-27
lines changed

1 file changed

+21
-27
lines changed

app/src/organisms/Devices/ProtocolRun/utils/__tests__/getLabwareOffsetLocation.test.tsx

+21-27
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import { when, resetAllWhenMocks } from 'jest-when'
1+
import { when } from 'vitest-when'
2+
import { describe, it, beforeEach, vi, expect, afterEach } from 'vitest'
3+
24
import {
35
CompletedProtocolAnalysis,
46
getLabwareDefURI,
7+
multiple_tipacks_with_tc,
8+
opentrons96PcrAdapterV1,
59
} from '@opentrons/shared-data'
6-
import _uncastedProtocolWithTC from '@opentrons/shared-data/protocol/fixtures/6/multipleTipracksWithTC.json'
7-
import fixture_adapter from '@opentrons/shared-data/labware/definitions/2/opentrons_96_pcr_adapter/1.json'
810
import { getLabwareOffsetLocation } from '../getLabwareOffsetLocation'
911
import { getLabwareLocation } from '../getLabwareLocation'
1012
import { getModuleInitialLoadInfo } from '../getModuleInitialLoadInfo'
@@ -14,24 +16,17 @@ import type {
1416
LabwareDefinition2,
1517
} from '@opentrons/shared-data'
1618

17-
jest.mock('../getLabwareLocation')
18-
jest.mock('../getModuleInitialLoadInfo')
19+
vi.mock('../getLabwareLocation')
20+
vi.mock('../getModuleInitialLoadInfo')
1921

20-
const protocolWithTC = (_uncastedProtocolWithTC as unknown) as CompletedProtocolAnalysis
21-
const mockAdapterDef = fixture_adapter as LabwareDefinition2
22+
const protocolWithTC = (multiple_tipacks_with_tc as unknown) as CompletedProtocolAnalysis
23+
const mockAdapterDef = opentrons96PcrAdapterV1 as LabwareDefinition2
2224
const mockAdapterId = 'mockAdapterId'
2325
const TCModelInProtocol = 'thermocyclerModuleV1'
2426
const MOCK_SLOT = '2'
2527
const TCIdInProtocol =
2628
'18f0c1b0-0122-11ec-88a3-f1745cf9b36c:thermocyclerModuleType' // this is just taken from the protocol fixture
2729

28-
const mockGetLabwareLocation = getLabwareLocation as jest.MockedFunction<
29-
typeof getLabwareLocation
30-
>
31-
const mockGetModuleInitialLoadInfo = getModuleInitialLoadInfo as jest.MockedFunction<
32-
typeof getModuleInitialLoadInfo
33-
>
34-
3530
describe('getLabwareOffsetLocation', () => {
3631
let MOCK_LABWARE_ID: string
3732
let MOCK_COMMANDS: CompletedProtocolAnalysis['commands']
@@ -57,44 +52,43 @@ describe('getLabwareOffsetLocation', () => {
5752
]
5853
})
5954
afterEach(() => {
60-
resetAllWhenMocks()
61-
jest.restoreAllMocks()
55+
vi.restoreAllMocks()
6256
})
6357
it('should return just the slot name if the labware is not on top of a module or adapter', () => {
6458
const MOCK_SLOT = '2'
65-
when(mockGetLabwareLocation)
59+
when(vi.mocked(getLabwareLocation))
6660
.calledWith(MOCK_LABWARE_ID, MOCK_COMMANDS)
67-
.mockReturnValue({ slotName: MOCK_SLOT })
61+
.thenReturn({ slotName: MOCK_SLOT })
6862

6963
expect(
7064
getLabwareOffsetLocation(MOCK_LABWARE_ID, MOCK_COMMANDS, MOCK_MODULES, [])
7165
).toEqual({ slotName: MOCK_SLOT })
7266
})
7367
it('should return null if the location is off deck', () => {
74-
when(mockGetLabwareLocation)
68+
when(vi.mocked(getLabwareLocation))
7569
.calledWith(MOCK_LABWARE_ID, MOCK_COMMANDS)
76-
.mockReturnValue('offDeck')
70+
.thenReturn('offDeck')
7771

7872
expect(
7973
getLabwareOffsetLocation(MOCK_LABWARE_ID, MOCK_COMMANDS, MOCK_MODULES, [])
8074
).toEqual(null)
8175
})
8276
it('should return the slot name and module model if the labware is on top of a module', () => {
83-
when(mockGetLabwareLocation)
77+
when(vi.mocked(getLabwareLocation))
8478
.calledWith(MOCK_LABWARE_ID, MOCK_COMMANDS)
85-
.mockReturnValue({ moduleId: TCIdInProtocol })
86-
when(mockGetModuleInitialLoadInfo)
79+
.thenReturn({ moduleId: TCIdInProtocol })
80+
when(vi.mocked(getModuleInitialLoadInfo))
8781
.calledWith(TCIdInProtocol, MOCK_COMMANDS)
88-
.mockReturnValue({ location: { slotName: MOCK_SLOT } } as any)
82+
.thenReturn({ location: { slotName: MOCK_SLOT } } as any)
8983

9084
expect(
9185
getLabwareOffsetLocation(MOCK_LABWARE_ID, MOCK_COMMANDS, MOCK_MODULES, [])
9286
).toEqual({ slotName: MOCK_SLOT, moduleModel: TCModelInProtocol })
9387
})
9488

9589
it('should return the slot name, module model and definition uri for labware on adapter on mod', () => {
96-
mockGetLabwareLocation.mockReturnValue({ labwareId: mockAdapterId })
97-
mockGetModuleInitialLoadInfo.mockReturnValue({
90+
vi.mocked(getLabwareLocation).mockReturnValue({ labwareId: mockAdapterId })
91+
vi.mocked(getModuleInitialLoadInfo).mockReturnValue({
9892
location: { slotName: MOCK_SLOT },
9993
} as any)
10094
expect(
@@ -122,7 +116,7 @@ describe('getLabwareOffsetLocation', () => {
122116
},
123117
]
124118
MOCK_MODULES = []
125-
mockGetLabwareLocation.mockReturnValue({ labwareId: mockAdapterId })
119+
vi.mocked(getLabwareLocation).mockReturnValue({ labwareId: mockAdapterId })
126120
expect(
127121
getLabwareOffsetLocation(
128122
MOCK_LABWARE_ID,

0 commit comments

Comments
 (0)