1
1
import * as React from 'react'
2
- import { fireEvent } from '@testing-library/react'
3
- import { useCreateLiveCommandMutation } from '@opentrons/react-api-client '
2
+ import { fireEvent , screen } from '@testing-library/react'
3
+ import { describe , it , beforeEach , vi , expect } from 'vitest '
4
4
import { StaticRouter } from 'react-router-dom'
5
- import { renderWithProviders } from '@opentrons/components'
6
- import fixture_adapter from '@opentrons/shared-data/labware/definitions/2/opentrons_96_pcr_adapter/1.json'
5
+
6
+ import { opentrons96PcrAdapterV1 } from '@opentrons/shared-data'
7
+ import { useCreateLiveCommandMutation } from '@opentrons/react-api-client'
8
+
9
+ import { renderWithProviders } from '../../../../../__testing-utils__'
7
10
import { i18n } from '../../../../../i18n'
8
11
import {
9
12
mockHeaterShaker ,
@@ -24,17 +27,10 @@ import type {
24
27
import type { AttachedModule } from '../../../../../redux/modules/types'
25
28
import type { ModuleRenderInfoForProtocol } from '../../../hooks'
26
29
27
- jest . mock ( '../SecureLabwareModal' )
28
- jest . mock ( '@opentrons/react-api-client' )
29
-
30
- const mockSecureLabwareModal = SecureLabwareModal as jest . MockedFunction <
31
- typeof SecureLabwareModal
32
- >
33
- const mockUseLiveCommandMutation = useCreateLiveCommandMutation as jest . MockedFunction <
34
- typeof useCreateLiveCommandMutation
35
- >
30
+ vi . mock ( '../SecureLabwareModal' )
31
+ vi . mock ( '@opentrons/react-api-client' )
36
32
37
- const mockAdapterDef = fixture_adapter as LabwareDefinition2
33
+ const mockAdapterDef = opentrons96PcrAdapterV1 as LabwareDefinition2
38
34
const mockAdapterId = 'mockAdapterId'
39
35
const mockNestedLabwareDisplayName = 'nested labware display name'
40
36
const mockLocationInfo = {
@@ -82,17 +78,19 @@ const render = (props: React.ComponentProps<typeof LabwareListItem>) => {
82
78
}
83
79
84
80
describe ( 'LabwareListItem' , ( ) => {
85
- const mockCreateLiveCommand = jest . fn ( )
81
+ const mockCreateLiveCommand = vi . fn ( )
86
82
beforeEach ( ( ) => {
87
83
mockCreateLiveCommand . mockResolvedValue ( null )
88
- mockSecureLabwareModal . mockReturnValue ( < div > mock secure labware modal</ div > )
89
- mockUseLiveCommandMutation . mockReturnValue ( {
84
+ vi . mocked ( SecureLabwareModal ) . mockReturnValue (
85
+ < div > mock secure labware modal</ div >
86
+ )
87
+ vi . mocked ( useCreateLiveCommandMutation ) . mockReturnValue ( {
90
88
createLiveCommand : mockCreateLiveCommand ,
91
89
} as any )
92
90
} )
93
91
94
92
it ( 'renders the correct info for a thermocycler (OT2), clicking on secure labware instructions opens the modal' , ( ) => {
95
- const { getByText } = render ( {
93
+ render ( {
96
94
commands : [ ] ,
97
95
nickName : mockNickName ,
98
96
definition : mockLabwareDef ,
@@ -111,18 +109,18 @@ describe('LabwareListItem', () => {
111
109
isFlex : false ,
112
110
nestedLabwareInfo : null ,
113
111
} )
114
- getByText ( 'Mock Labware Definition' )
115
- getByText ( 'nickName' )
116
- getByText ( 'Thermocycler Module GEN1' )
117
- getByText ( '7,8,10,11' )
118
- const button = getByText ( 'Secure labware instructions' )
112
+ screen . getByText ( 'Mock Labware Definition' )
113
+ screen . getByText ( 'nickName' )
114
+ screen . getByText ( 'Thermocycler Module GEN1' )
115
+ screen . getByText ( '7,8,10,11' )
116
+ const button = screen . getByText ( 'Secure labware instructions' )
119
117
fireEvent . click ( button )
120
- getByText ( 'mock secure labware modal' )
121
- getByText ( 'nickName' )
118
+ screen . getByText ( 'mock secure labware modal' )
119
+ screen . getByText ( 'nickName' )
122
120
} )
123
121
124
122
it ( 'renders the correct info for a thermocycler (OT3)' , ( ) => {
125
- const { getByText } = render ( {
123
+ render ( {
126
124
commands : [ ] ,
127
125
nickName : mockNickName ,
128
126
definition : mockLabwareDef ,
@@ -141,13 +139,13 @@ describe('LabwareListItem', () => {
141
139
isFlex : true ,
142
140
nestedLabwareInfo : null ,
143
141
} )
144
- getByText ( 'Mock Labware Definition' )
145
- getByText ( 'A1+B1' )
146
- getByText ( 'Thermocycler Module GEN1' )
142
+ screen . getByText ( 'Mock Labware Definition' )
143
+ screen . getByText ( 'A1+B1' )
144
+ screen . getByText ( 'Thermocycler Module GEN1' )
147
145
} )
148
146
149
147
it ( 'renders the correct info for a labware on top of a magnetic module' , ( ) => {
150
- const { getByText , getByTestId } = render ( {
148
+ render ( {
151
149
commands : [ ] ,
152
150
nickName : mockNickName ,
153
151
definition : mockLabwareDef ,
@@ -172,17 +170,17 @@ describe('LabwareListItem', () => {
172
170
isFlex : false ,
173
171
nestedLabwareInfo : null ,
174
172
} )
175
- getByText ( 'Mock Labware Definition' )
176
- getByTestId ( 'slot_info_7' )
177
- getByText ( 'Magnetic Module GEN1' )
178
- const button = getByText ( 'Secure labware instructions' )
173
+ screen . getByText ( 'Mock Labware Definition' )
174
+ screen . getByTestId ( 'slot_info_7' )
175
+ screen . getByText ( 'Magnetic Module GEN1' )
176
+ const button = screen . getByText ( 'Secure labware instructions' )
179
177
fireEvent . click ( button )
180
- getByText ( 'mock secure labware modal' )
181
- getByText ( 'nickName' )
178
+ screen . getByText ( 'mock secure labware modal' )
179
+ screen . getByText ( 'nickName' )
182
180
} )
183
181
184
182
it ( 'renders the correct info for a labware on top of a temperature module' , ( ) => {
185
- const { getByText , getByTestId } = render ( {
183
+ render ( {
186
184
commands : [ ] ,
187
185
nickName : mockNickName ,
188
186
definition : mockLabwareDef ,
@@ -206,10 +204,10 @@ describe('LabwareListItem', () => {
206
204
isFlex : false ,
207
205
nestedLabwareInfo : null ,
208
206
} )
209
- getByText ( 'Mock Labware Definition' )
210
- getByTestId ( 'slot_info_7' )
211
- getByText ( 'Temperature Module GEN1' )
212
- getByText ( 'nickName' )
207
+ screen . getByText ( 'Mock Labware Definition' )
208
+ screen . getByTestId ( 'slot_info_7' )
209
+ screen . getByText ( 'Temperature Module GEN1' )
210
+ screen . getByText ( 'nickName' )
213
211
} )
214
212
215
213
it ( 'renders the correct info for a labware on an adapter on top of a temperature module' , ( ) => {
@@ -240,7 +238,7 @@ describe('LabwareListItem', () => {
240
238
} ,
241
239
} as any
242
240
243
- const { getByText , getAllByText } = render ( {
241
+ render ( {
244
242
commands : [ mockAdapterLoadCommand , mockModuleLoadCommand ] ,
245
243
nickName : mockNickName ,
246
244
definition : mockLabwareDef ,
@@ -269,12 +267,12 @@ describe('LabwareListItem', () => {
269
267
nestedLabwareDefinition : mockLabwareDef ,
270
268
} ,
271
269
} )
272
- getByText ( 'Mock Labware Definition' )
273
- getAllByText ( '7' )
274
- getByText ( 'Temperature Module GEN2' )
275
- getByText ( 'mock nested display name' )
276
- getByText ( 'nestedLabwareNickName' )
277
- getByText ( 'nickName' )
270
+ screen . getByText ( 'Mock Labware Definition' )
271
+ screen . getAllByText ( '7' )
272
+ screen . getByText ( 'Temperature Module GEN2' )
273
+ screen . getByText ( 'mock nested display name' )
274
+ screen . getByText ( 'nestedLabwareNickName' )
275
+ screen . getByText ( 'nickName' )
278
276
} )
279
277
280
278
it ( 'renders the correct info for a labware on an adapter on the deck' , ( ) => {
@@ -294,7 +292,7 @@ describe('LabwareListItem', () => {
294
292
} ,
295
293
} as any
296
294
297
- const { getByText } = render ( {
295
+ render ( {
298
296
commands : [ mockAdapterLoadCommand ] ,
299
297
nickName : mockNickName ,
300
298
definition : mockLabwareDef ,
@@ -311,16 +309,16 @@ describe('LabwareListItem', () => {
311
309
nestedLabwareDefinition : mockLabwareDef ,
312
310
} ,
313
311
} )
314
- getByText ( 'Mock Labware Definition' )
315
- getByText ( 'A2' )
316
- getByText ( 'mock nested display name' )
317
- getByText ( 'nestedLabwareNickName' )
318
- getByText ( 'nickName' )
319
- getByText ( 'On deck' )
312
+ screen . getByText ( 'Mock Labware Definition' )
313
+ screen . getByText ( 'A2' )
314
+ screen . getByText ( 'mock nested display name' )
315
+ screen . getByText ( 'nestedLabwareNickName' )
316
+ screen . getByText ( 'nickName' )
317
+ screen . getByText ( 'On deck' )
320
318
} )
321
319
322
320
it ( 'renders the correct info for a labware on top of a heater shaker' , ( ) => {
323
- const { getByText , getByLabelText , getByTestId } = render ( {
321
+ render ( {
324
322
nickName : mockNickName ,
325
323
commands : [ ] ,
326
324
definition : mockLabwareDef ,
@@ -344,14 +342,14 @@ describe('LabwareListItem', () => {
344
342
isFlex : false ,
345
343
nestedLabwareInfo : null ,
346
344
} )
347
- getByText ( 'Mock Labware Definition' )
348
- getByTestId ( 'slot_info_7' )
349
- getByText ( 'Heater-Shaker Module GEN1' )
350
- getByText ( 'nickName' )
351
- getByText ( 'To add labware, use the toggle to control the latch' )
352
- getByText ( 'Labware Latch' )
353
- getByText ( 'Secure' )
354
- const button = getByLabelText ( 'heater_shaker_7_latch_toggle' )
345
+ screen . getByText ( 'Mock Labware Definition' )
346
+ screen . getByTestId ( 'slot_info_7' )
347
+ screen . getByText ( 'Heater-Shaker Module GEN1' )
348
+ screen . getByText ( 'nickName' )
349
+ screen . getByText ( 'To add labware, use the toggle to control the latch' )
350
+ screen . getByText ( 'Labware Latch' )
351
+ screen . getByText ( 'Secure' )
352
+ const button = screen . getByLabelText ( 'heater_shaker_7_latch_toggle' )
355
353
fireEvent . click ( button )
356
354
expect ( mockCreateLiveCommand ) . toHaveBeenCalledWith ( {
357
355
command : {
@@ -364,7 +362,7 @@ describe('LabwareListItem', () => {
364
362
} )
365
363
366
364
it ( 'renders the correct info for an off deck labware' , ( ) => {
367
- const { getByText } = render ( {
365
+ render ( {
368
366
nickName : null ,
369
367
definition : mockLabwareDef ,
370
368
initialLocation : 'offDeck' ,
@@ -376,7 +374,7 @@ describe('LabwareListItem', () => {
376
374
isFlex : false ,
377
375
nestedLabwareInfo : null ,
378
376
} )
379
- getByText ( 'Mock Labware Definition' )
380
- getByText ( 'Off deck' )
377
+ screen . getByText ( 'Mock Labware Definition' )
378
+ screen . getByText ( 'Off deck' )
381
379
} )
382
380
} )
0 commit comments