1
1
import * as React from 'react'
2
- import { resetAllWhenMocks } from 'jest-when'
3
2
import { MemoryRouter } from 'react-router-dom'
4
- import { fireEvent } from '@testing-library/react'
3
+ import { fireEvent , screen } from '@testing-library/react'
4
+ import { describe , it , beforeEach , vi , afterEach } from 'vitest'
5
5
6
- import { renderWithProviders } from '@opentrons/components'
7
6
import { useInstrumentsQuery } from '@opentrons/react-api-client'
8
7
8
+ import { renderWithProviders } from '../../../../__testing-utils__'
9
9
import { i18n } from '../../../../i18n'
10
10
import { useMostRecentCompletedAnalysis } from '../../../LabwarePositionCheck/useMostRecentCompletedAnalysis'
11
11
import { PipetteWizardFlows } from '../../../PipetteWizardFlows'
12
12
import { SetupFlexPipetteCalibrationItem } from '../SetupFlexPipetteCalibrationItem'
13
13
import _uncastedModifiedSimpleV6Protocol from '../../hooks/__fixtures__/modifiedSimpleV6.json'
14
14
import { CompletedProtocolAnalysis } from '@opentrons/shared-data'
15
15
16
- jest . mock ( '@opentrons/react-api-client' )
17
- jest . mock ( '../../../PipetteWizardFlows' )
18
- jest . mock ( '../../../LabwarePositionCheck/useMostRecentCompletedAnalysis' )
19
- jest . mock ( '../../hooks' )
20
-
21
- const mockUseInstrumentsQuery = useInstrumentsQuery as jest . MockedFunction <
22
- typeof useInstrumentsQuery
23
- >
24
- const mockUseMostRecentCompletedAnalysis = useMostRecentCompletedAnalysis as jest . MockedFunction <
25
- typeof useMostRecentCompletedAnalysis
26
- >
27
- const mockPipetteWizardFlows = PipetteWizardFlows as jest . MockedFunction <
28
- typeof PipetteWizardFlows
29
- >
16
+ vi . mock ( '@opentrons/react-api-client' )
17
+ vi . mock ( '../../../PipetteWizardFlows' )
18
+ vi . mock ( '../../../LabwarePositionCheck/useMostRecentCompletedAnalysis' )
19
+ vi . mock ( '../../hooks' )
30
20
31
21
const RUN_ID = '1'
32
22
const modifiedSimpleV6Protocol = ( {
@@ -60,34 +50,39 @@ describe('SetupFlexPipetteCalibrationItem', () => {
60
50
}
61
51
62
52
beforeEach ( ( ) => {
63
- mockPipetteWizardFlows . mockReturnValue ( < div > pipette wizard flows</ div > )
64
- mockUseMostRecentCompletedAnalysis . mockReturnValue ( modifiedSimpleV6Protocol )
65
- mockUseInstrumentsQuery . mockReturnValue ( {
53
+ vi . mocked ( PipetteWizardFlows ) . mockReturnValue (
54
+ < div > pipette wizard flows</ div >
55
+ )
56
+ vi . mocked ( useMostRecentCompletedAnalysis ) . mockReturnValue (
57
+ modifiedSimpleV6Protocol
58
+ )
59
+ vi . mocked ( useInstrumentsQuery ) . mockReturnValue ( {
66
60
data : {
67
61
data : [ ] ,
68
62
} ,
69
63
} as any )
70
64
} )
71
65
afterEach ( ( ) => {
72
- resetAllWhenMocks ( )
66
+ vi . clearAllMocks ( )
73
67
} )
74
68
75
69
it ( 'renders the mount and pipette name' , ( ) => {
76
- const { getByText } = render ( )
77
- getByText ( 'Left Mount' )
78
- getByText ( 'P10 Single-Channel GEN1' )
70
+ render ( )
71
+ screen . getByText ( 'Left Mount' )
72
+ screen . getByText ( 'P10 Single-Channel GEN1' )
79
73
} )
80
74
81
75
it ( 'renders an attach button if on a Flex and pipette is not attached' , ( ) => {
82
- const { getByText , getByRole } = render ( )
83
- getByText ( 'Left Mount' )
84
- getByText ( 'P10 Single-Channel GEN1' )
85
- const attach = getByRole ( 'button' , { name : 'Attach Pipette' } )
76
+ render ( )
77
+ screen . getByText ( 'Left Mount' )
78
+ screen . getByText ( 'P10 Single-Channel GEN1' )
79
+ const attach = screen . getByRole ( 'button' , { name : 'Attach Pipette' } )
86
80
fireEvent . click ( attach )
87
- getByText ( 'pipette wizard flows' )
81
+ screen . getByText ( 'pipette wizard flows' )
88
82
} )
83
+
89
84
it ( 'renders a calibrate button if on a Flex and pipette is not calibrated' , ( ) => {
90
- mockUseInstrumentsQuery . mockReturnValue ( {
85
+ vi . mocked ( useInstrumentsQuery ) . mockReturnValue ( {
91
86
data : {
92
87
data : [
93
88
{
@@ -101,15 +96,16 @@ describe('SetupFlexPipetteCalibrationItem', () => {
101
96
] ,
102
97
} ,
103
98
} as any )
104
- const { getByText , getByRole } = render ( )
105
- getByText ( 'Left Mount' )
106
- getByText ( 'P10 Single-Channel GEN1' )
107
- const attach = getByRole ( 'button' , { name : 'Calibrate now' } )
99
+ render ( )
100
+ screen . getByText ( 'Left Mount' )
101
+ screen . getByText ( 'P10 Single-Channel GEN1' )
102
+ const attach = screen . getByRole ( 'button' , { name : 'Calibrate now' } )
108
103
fireEvent . click ( attach )
109
- getByText ( 'pipette wizard flows' )
104
+ screen . getByText ( 'pipette wizard flows' )
110
105
} )
106
+
111
107
it ( 'renders calibrated text if on a Flex and pipette is calibrated' , ( ) => {
112
- mockUseInstrumentsQuery . mockReturnValue ( {
108
+ vi . mocked ( useInstrumentsQuery ) . mockReturnValue ( {
113
109
data : {
114
110
data : [
115
111
{
@@ -127,9 +123,9 @@ describe('SetupFlexPipetteCalibrationItem', () => {
127
123
] ,
128
124
} ,
129
125
} as any )
130
- const { getByText } = render ( )
131
- getByText ( 'Left Mount' )
132
- getByText ( 'P10 Single-Channel GEN1' )
133
- getByText ( 'Last calibrated: today' )
126
+ render ( )
127
+ screen . getByText ( 'Left Mount' )
128
+ screen . getByText ( 'P10 Single-Channel GEN1' )
129
+ screen . getByText ( 'Last calibrated: today' )
134
130
} )
135
131
} )
0 commit comments