@@ -7,10 +7,7 @@ import { when } from 'vitest-when'
7
7
import { renderWithProviders } from '../../../__testing-utils__'
8
8
import { i18n } from '../../../i18n'
9
9
import { useTrackCreateProtocolRunEvent } from '../../../organisms/Devices/hooks'
10
- import {
11
- useCloseCurrentRun ,
12
- useCurrentRunId ,
13
- } from '../../../organisms/ProtocolUpload/hooks'
10
+ import { useCloseCurrentRun } from '../../../organisms/ProtocolUpload/hooks'
14
11
import { useCurrentRunStatus } from '../../../organisms/RunTimeControl/hooks'
15
12
import {
16
13
getConnectableRobots ,
@@ -34,8 +31,11 @@ import { useCreateRunFromProtocol } from '../useCreateRunFromProtocol'
34
31
import { useOffsetCandidatesForAnalysis } from '../../ApplyHistoricOffsets/hooks/useOffsetCandidatesForAnalysis'
35
32
import { ChooseRobotToRunProtocolSlideout } from '../'
36
33
import { useNotifyDataReady } from '../../../resources/useNotifyDataReady'
34
+ import { useCurrentRunId } from '../../../resources/runs'
37
35
38
36
import type { State } from '../../../redux/types'
37
+ import type { Runs } from '@opentrons/api-client'
38
+ import { UseAllRunsQueryOptions } from '@opentrons/react-api-client/src/runs/useAllRunsQuery'
39
39
40
40
vi . mock ( '../../../organisms/Devices/hooks' )
41
41
vi . mock ( '../../../organisms/ProtocolUpload/hooks' )
@@ -46,6 +46,7 @@ vi.mock('../../../redux/networking')
46
46
vi . mock ( '../useCreateRunFromProtocol' )
47
47
vi . mock ( '../../ApplyHistoricOffsets/hooks/useOffsetCandidatesForAnalysis' )
48
48
vi . mock ( '../../../resources/useNotifyDataReady' )
49
+ vi . mock ( '../../../resources/runs' )
49
50
50
51
const render = (
51
52
props : React . ComponentProps < typeof ChooseRobotToRunProtocolSlideout >
@@ -88,7 +89,7 @@ describe('ChooseRobotToRunProtocolSlideout', () => {
88
89
isClosingCurrentRun : false ,
89
90
closeCurrentRun : mockCloseCurrentRun ,
90
91
} )
91
- vi . mocked ( useCurrentRunId ) . mockReturnValue ( null )
92
+ provideNullCurrentRunIdFor ( mockConnectableRobot . ip )
92
93
vi . mocked ( useCurrentRunStatus ) . mockReturnValue ( null )
93
94
when ( vi . mocked ( useCreateRunFromProtocol ) )
94
95
. calledWith (
@@ -191,6 +192,7 @@ describe('ChooseRobotToRunProtocolSlideout', () => {
191
192
{ ...mockConnectableRobot , name : 'otherRobot' , ip : 'otherIp' } ,
192
193
mockConnectableRobot ,
193
194
] )
195
+ provideNullCurrentRunIdFor ( 'otherIp' )
194
196
render ( {
195
197
storedProtocolData : storedProtocolDataFixture ,
196
198
onCloseClick : vi . fn ( ) ,
@@ -372,6 +374,7 @@ describe('ChooseRobotToRunProtocolSlideout', () => {
372
374
mockConnectableRobot ,
373
375
{ ...mockConnectableRobot , name : 'otherRobot' , ip : 'otherIp' } ,
374
376
] )
377
+ provideNullCurrentRunIdFor ( 'otherIp' )
375
378
render ( {
376
379
storedProtocolData : storedProtocolDataFixture ,
377
380
onCloseClick : vi . fn ( ) ,
@@ -387,7 +390,7 @@ describe('ChooseRobotToRunProtocolSlideout', () => {
387
390
fireEvent . click ( proceedButton )
388
391
fireEvent . click ( screen . getByRole ( 'button' , { name : 'Confirm values' } ) )
389
392
expect ( vi . mocked ( useCreateRunFromProtocol ) ) . nthCalledWith (
390
- 2 ,
393
+ 3 ,
391
394
expect . any ( Object ) ,
392
395
{ hostname : '127.0.0.1' } ,
393
396
[
@@ -450,3 +453,21 @@ describe('ChooseRobotToRunProtocolSlideout', () => {
450
453
)
451
454
} )
452
455
} )
456
+
457
+ const provideNullCurrentRunIdFor = ( hostname : string ) : void => {
458
+ let once = true
459
+ when ( vi . mocked ( useCurrentRunId ) )
460
+ . calledWith ( expect . any ( Object ) , {
461
+ hostname,
462
+ requestor : undefined ,
463
+ } )
464
+ . thenDo ( options => {
465
+ void ( options ?. onSuccess != null && once
466
+ ? options . onSuccess ( ( {
467
+ links : { current : null } ,
468
+ } as unknown ) as UseAllRunsQueryOptions )
469
+ : { } )
470
+ once = false
471
+ return null
472
+ } )
473
+ }
0 commit comments