1
- import { when , resetAllWhenMocks } from 'jest-when'
1
+ import { when } from 'vitest-when'
2
+ import { describe , it , beforeEach , vi , expect , afterEach } from 'vitest'
3
+
2
4
import {
3
5
CompletedProtocolAnalysis ,
4
6
getLabwareDefURI ,
7
+ multiple_tipacks_with_tc ,
8
+ opentrons96PcrAdapterV1 ,
5
9
} 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'
8
10
import { getLabwareOffsetLocation } from '../getLabwareOffsetLocation'
9
11
import { getLabwareLocation } from '../getLabwareLocation'
10
12
import { getModuleInitialLoadInfo } from '../getModuleInitialLoadInfo'
@@ -14,24 +16,17 @@ import type {
14
16
LabwareDefinition2 ,
15
17
} from '@opentrons/shared-data'
16
18
17
- jest . mock ( '../getLabwareLocation' )
18
- jest . mock ( '../getModuleInitialLoadInfo' )
19
+ vi . mock ( '../getLabwareLocation' )
20
+ vi . mock ( '../getModuleInitialLoadInfo' )
19
21
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
22
24
const mockAdapterId = 'mockAdapterId'
23
25
const TCModelInProtocol = 'thermocyclerModuleV1'
24
26
const MOCK_SLOT = '2'
25
27
const TCIdInProtocol =
26
28
'18f0c1b0-0122-11ec-88a3-f1745cf9b36c:thermocyclerModuleType' // this is just taken from the protocol fixture
27
29
28
- const mockGetLabwareLocation = getLabwareLocation as jest . MockedFunction <
29
- typeof getLabwareLocation
30
- >
31
- const mockGetModuleInitialLoadInfo = getModuleInitialLoadInfo as jest . MockedFunction <
32
- typeof getModuleInitialLoadInfo
33
- >
34
-
35
30
describe ( 'getLabwareOffsetLocation' , ( ) => {
36
31
let MOCK_LABWARE_ID : string
37
32
let MOCK_COMMANDS : CompletedProtocolAnalysis [ 'commands' ]
@@ -57,44 +52,43 @@ describe('getLabwareOffsetLocation', () => {
57
52
]
58
53
} )
59
54
afterEach ( ( ) => {
60
- resetAllWhenMocks ( )
61
- jest . restoreAllMocks ( )
55
+ vi . restoreAllMocks ( )
62
56
} )
63
57
it ( 'should return just the slot name if the labware is not on top of a module or adapter' , ( ) => {
64
58
const MOCK_SLOT = '2'
65
- when ( mockGetLabwareLocation )
59
+ when ( vi . mocked ( getLabwareLocation ) )
66
60
. calledWith ( MOCK_LABWARE_ID , MOCK_COMMANDS )
67
- . mockReturnValue ( { slotName : MOCK_SLOT } )
61
+ . thenReturn ( { slotName : MOCK_SLOT } )
68
62
69
63
expect (
70
64
getLabwareOffsetLocation ( MOCK_LABWARE_ID , MOCK_COMMANDS , MOCK_MODULES , [ ] )
71
65
) . toEqual ( { slotName : MOCK_SLOT } )
72
66
} )
73
67
it ( 'should return null if the location is off deck' , ( ) => {
74
- when ( mockGetLabwareLocation )
68
+ when ( vi . mocked ( getLabwareLocation ) )
75
69
. calledWith ( MOCK_LABWARE_ID , MOCK_COMMANDS )
76
- . mockReturnValue ( 'offDeck' )
70
+ . thenReturn ( 'offDeck' )
77
71
78
72
expect (
79
73
getLabwareOffsetLocation ( MOCK_LABWARE_ID , MOCK_COMMANDS , MOCK_MODULES , [ ] )
80
74
) . toEqual ( null )
81
75
} )
82
76
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 ) )
84
78
. calledWith ( MOCK_LABWARE_ID , MOCK_COMMANDS )
85
- . mockReturnValue ( { moduleId : TCIdInProtocol } )
86
- when ( mockGetModuleInitialLoadInfo )
79
+ . thenReturn ( { moduleId : TCIdInProtocol } )
80
+ when ( vi . mocked ( getModuleInitialLoadInfo ) )
87
81
. calledWith ( TCIdInProtocol , MOCK_COMMANDS )
88
- . mockReturnValue ( { location : { slotName : MOCK_SLOT } } as any )
82
+ . thenReturn ( { location : { slotName : MOCK_SLOT } } as any )
89
83
90
84
expect (
91
85
getLabwareOffsetLocation ( MOCK_LABWARE_ID , MOCK_COMMANDS , MOCK_MODULES , [ ] )
92
86
) . toEqual ( { slotName : MOCK_SLOT , moduleModel : TCModelInProtocol } )
93
87
} )
94
88
95
89
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 ( {
98
92
location : { slotName : MOCK_SLOT } ,
99
93
} as any )
100
94
expect (
@@ -122,7 +116,7 @@ describe('getLabwareOffsetLocation', () => {
122
116
} ,
123
117
]
124
118
MOCK_MODULES = [ ]
125
- mockGetLabwareLocation . mockReturnValue ( { labwareId : mockAdapterId } )
119
+ vi . mocked ( getLabwareLocation ) . mockReturnValue ( { labwareId : mockAdapterId } )
126
120
expect (
127
121
getLabwareOffsetLocation (
128
122
MOCK_LABWARE_ID ,
0 commit comments