1
1
import * as React from 'react'
2
2
import { fireEvent , screen } from '@testing-library/react'
3
- import { when , resetAllWhenMocks } from 'jest-when'
3
+ import { when } from 'vitest-when'
4
+ import { describe , it , beforeEach , vi , afterEach } from 'vitest'
4
5
5
- import {
6
- DeckConfigurator ,
7
- partialComponentPropsMatcher ,
8
- renderWithProviders ,
9
- } from '@opentrons/components'
6
+ import { DeckConfigurator } from '@opentrons/components'
10
7
import {
11
8
useDeckConfigurationQuery ,
12
9
useUpdateDeckConfigurationMutation ,
13
10
} from '@opentrons/react-api-client'
14
11
12
+ import {
13
+ partialComponentPropsMatcher ,
14
+ renderWithProviders ,
15
+ } from '../../../__testing-utils__'
15
16
import { i18n } from '../../../i18n'
16
17
import { useIsRobotViewable , useRunStatuses } from '../../Devices/hooks'
17
18
import { DeckFixtureSetupInstructionsModal } from '../DeckFixtureSetupInstructionsModal'
@@ -21,15 +22,15 @@ import { useNotifyCurrentMaintenanceRun } from '../../../resources/maintenance_r
21
22
22
23
import type { MaintenanceRun } from '@opentrons/api-client'
23
24
24
- jest . mock ( '@opentrons/components/src/hardware-sim/DeckConfigurator/index' )
25
- jest . mock ( '@opentrons/react-api-client' )
26
- jest . mock ( '../DeckFixtureSetupInstructionsModal' )
27
- jest . mock ( '../../Devices/hooks' )
28
- jest . mock ( '../../../resources/maintenance_runs/useNotifyCurrentMaintenanceRun' )
29
- jest . mock ( '../../../resources/devices/hooks/useIsEstopNotDisengaged' )
25
+ vi . mock ( '@opentrons/components/src/hardware-sim/DeckConfigurator/index' )
26
+ vi . mock ( '@opentrons/react-api-client' )
27
+ vi . mock ( '../DeckFixtureSetupInstructionsModal' )
28
+ vi . mock ( '../../Devices/hooks' )
29
+ vi . mock ( '../../../resources/maintenance_runs/useNotifyCurrentMaintenanceRun' )
30
+ vi . mock ( '../../../resources/devices/hooks/useIsEstopNotDisengaged' )
30
31
31
32
const ROBOT_NAME = 'otie'
32
- const mockUpdateDeckConfiguration = jest . fn ( )
33
+ const mockUpdateDeckConfiguration = vi . fn ( )
33
34
const RUN_STATUSES = {
34
35
isRunRunning : false ,
35
36
isRunStill : false ,
@@ -40,31 +41,6 @@ const mockCurrnetMaintenanceRun = {
40
41
data : { id : 'mockMaintenanceRunId' } ,
41
42
} as MaintenanceRun
42
43
43
- const mockUseDeckConfigurationQuery = useDeckConfigurationQuery as jest . MockedFunction <
44
- typeof useDeckConfigurationQuery
45
- >
46
- const mockUseUpdateDeckConfigurationMutation = useUpdateDeckConfigurationMutation as jest . MockedFunction <
47
- typeof useUpdateDeckConfigurationMutation
48
- >
49
- const mockDeckFixtureSetupInstructionsModal = DeckFixtureSetupInstructionsModal as jest . MockedFunction <
50
- typeof DeckFixtureSetupInstructionsModal
51
- >
52
- const mockDeckConfigurator = DeckConfigurator as jest . MockedFunction <
53
- typeof DeckConfigurator
54
- >
55
- const mockUseRunStatuses = useRunStatuses as jest . MockedFunction <
56
- typeof useRunStatuses
57
- >
58
- const mockUseNotifyCurrentMaintenanceRun = useNotifyCurrentMaintenanceRun as jest . MockedFunction <
59
- typeof useNotifyCurrentMaintenanceRun
60
- >
61
- const mockUseIsEstopNotDisengaged = useIsEstopNotDisengaged as jest . MockedFunction <
62
- typeof useIsEstopNotDisengaged
63
- >
64
- const mockUseIsRobotViewable = useIsRobotViewable as jest . MockedFunction <
65
- typeof useIsRobotViewable
66
- >
67
-
68
44
const render = (
69
45
props : React . ComponentProps < typeof DeviceDetailsDeckConfiguration >
70
46
) => {
@@ -80,26 +56,28 @@ describe('DeviceDetailsDeckConfiguration', () => {
80
56
props = {
81
57
robotName : ROBOT_NAME ,
82
58
}
83
- mockUseDeckConfigurationQuery . mockReturnValue ( { data : [ ] } as any )
84
- mockUseUpdateDeckConfigurationMutation . mockReturnValue ( {
59
+ vi . mocked ( useDeckConfigurationQuery ) . mockReturnValue ( { data : [ ] } as any )
60
+ vi . mocked ( useUpdateDeckConfigurationMutation ) . mockReturnValue ( {
85
61
updateDeckConfiguration : mockUpdateDeckConfiguration ,
86
62
} as any )
87
- mockDeckFixtureSetupInstructionsModal . mockReturnValue (
63
+ vi . mocked ( DeckFixtureSetupInstructionsModal ) . mockReturnValue (
88
64
< div > mock DeckFixtureSetupInstructionsModal</ div >
89
65
)
90
- when ( mockDeckConfigurator ) . mockReturnValue ( < div > mock DeckConfigurator</ div > )
91
- mockUseRunStatuses . mockReturnValue ( RUN_STATUSES )
92
- mockUseNotifyCurrentMaintenanceRun . mockReturnValue ( {
66
+ when ( vi . mocked ( DeckConfigurator ) ) . thenReturn (
67
+ < div > mock DeckConfigurator</ div >
68
+ )
69
+ vi . mocked ( useRunStatuses ) . mockReturnValue ( RUN_STATUSES )
70
+ vi . mocked ( useNotifyCurrentMaintenanceRun ) . mockReturnValue ( {
93
71
data : { } ,
94
72
} as any )
95
- when ( mockUseIsEstopNotDisengaged )
73
+ when ( vi . mocked ( useIsEstopNotDisengaged ) )
96
74
. calledWith ( ROBOT_NAME )
97
- . mockReturnValue ( false )
98
- when ( mockUseIsRobotViewable ) . calledWith ( ROBOT_NAME ) . mockReturnValue ( true )
75
+ . thenReturn ( false )
76
+ when ( vi . mocked ( useIsRobotViewable ) ) . calledWith ( ROBOT_NAME ) . thenReturn ( true )
99
77
} )
100
78
101
79
afterEach ( ( ) => {
102
- resetAllWhenMocks ( )
80
+ vi . resetAllMocks ( )
103
81
} )
104
82
105
83
it ( 'should render text and button' , ( ) => {
@@ -119,10 +97,10 @@ describe('DeviceDetailsDeckConfiguration', () => {
119
97
120
98
it ( 'should render banner and make deck configurator disabled when running' , ( ) => {
121
99
RUN_STATUSES . isRunRunning = true
122
- mockUseRunStatuses . mockReturnValue ( RUN_STATUSES )
123
- when ( mockDeckConfigurator )
100
+ vi . mocked ( useRunStatuses ) . mockReturnValue ( RUN_STATUSES )
101
+ when ( vi . mocked ( DeckConfigurator ) )
124
102
. calledWith ( partialComponentPropsMatcher ( { readOnly : true } ) )
125
- . mockReturnValue ( < div > disabled mock DeckConfigurator</ div > )
103
+ . thenReturn ( < div > disabled mock DeckConfigurator</ div > )
126
104
render ( props )
127
105
screen . getByText (
128
106
'Deck configuration is not available when run is in progress'
@@ -131,12 +109,12 @@ describe('DeviceDetailsDeckConfiguration', () => {
131
109
} )
132
110
133
111
it ( 'should render banner and make deck configurator disabled when a maintenance run exists' , ( ) => {
134
- mockUseNotifyCurrentMaintenanceRun . mockReturnValue ( {
112
+ vi . mocked ( useNotifyCurrentMaintenanceRun ) . mockReturnValue ( {
135
113
data : mockCurrnetMaintenanceRun ,
136
114
} as any )
137
- when ( mockDeckConfigurator )
115
+ when ( vi . mocked ( DeckConfigurator ) )
138
116
. calledWith ( partialComponentPropsMatcher ( { readOnly : true } ) )
139
- . mockReturnValue ( < div > disabled mock DeckConfigurator</ div > )
117
+ . thenReturn ( < div > disabled mock DeckConfigurator</ div > )
140
118
render ( props )
141
119
screen . getByText (
142
120
'Deck configuration is not available when the robot is busy'
@@ -145,26 +123,26 @@ describe('DeviceDetailsDeckConfiguration', () => {
145
123
} )
146
124
147
125
it ( 'should render no deck fixtures, if deck configs are not set' , ( ) => {
148
- when ( mockUseDeckConfigurationQuery )
126
+ when ( vi . mocked ( useDeckConfigurationQuery ) )
149
127
. calledWith ( )
150
- . mockReturnValue ( [ ] as any )
128
+ . thenReturn ( [ ] as any )
151
129
render ( props )
152
130
screen . getByText ( 'No deck fixtures' )
153
131
} )
154
132
155
133
it ( 'should render disabled deck configurator when e-stop is pressed' , ( ) => {
156
- when ( mockUseIsEstopNotDisengaged )
134
+ when ( vi . mocked ( useIsEstopNotDisengaged ) )
157
135
. calledWith ( ROBOT_NAME )
158
- . mockReturnValue ( true )
159
- when ( mockDeckConfigurator )
136
+ . thenReturn ( true )
137
+ when ( vi . mocked ( DeckConfigurator ) )
160
138
. calledWith ( partialComponentPropsMatcher ( { readOnly : true } ) )
161
- . mockReturnValue ( < div > disabled mock DeckConfigurator</ div > )
139
+ . thenReturn ( < div > disabled mock DeckConfigurator</ div > )
162
140
render ( props )
163
141
screen . getByText ( 'disabled mock DeckConfigurator' )
164
142
} )
165
143
166
144
it ( 'should render not viewable text when robot is not viewable' , ( ) => {
167
- when ( mockUseIsRobotViewable ) . calledWith ( ROBOT_NAME ) . mockReturnValue ( false )
145
+ when ( vi . mocked ( useIsRobotViewable ) ) . calledWith ( ROBOT_NAME ) . thenReturn ( false )
168
146
render ( props )
169
147
screen . getByText ( 'Robot must be on the network to see deck configuration' )
170
148
} )
0 commit comments