7
7
ConnectionSuccessOutputText ,
8
8
InitOutputText ,
9
9
} from 'uiSrc/constants/cliOutput'
10
+ import { INSTANCE_ID_MOCK } from 'uiSrc/mocks/handlers/instances/instancesHandlers'
10
11
import reducer , {
11
12
initialState ,
12
13
toggleCli ,
@@ -32,11 +33,8 @@ import reducer, {
32
33
resetCliHelperSettings , goBackFromCommand ,
33
34
} from '../../cli/cli-settings'
34
35
35
- jest . mock ( 'uiSrc/constants/cliOutput' , ( ) => ( {
36
- ...jest . requireActual ( 'uiSrc/constants/cliOutput' ) ,
37
- InitOutputText : jest . fn ( ) . mockReturnValue ( [ ] ) ,
38
- } ) )
39
-
36
+ let mathRandom : jest . SpyInstance < number >
37
+ const random = 0.91911
40
38
let store : typeof mockedStore
41
39
beforeEach ( ( ) => {
42
40
cleanup ( )
@@ -53,6 +51,14 @@ jest.mock('uiSrc/services', () => ({
53
51
} ) )
54
52
55
53
describe ( 'cliSettings slice' , ( ) => {
54
+ beforeAll ( ( ) => {
55
+ mathRandom = jest . spyOn ( Math , 'random' ) . mockImplementation ( ( ) => random )
56
+ } )
57
+
58
+ afterAll ( ( ) => {
59
+ mathRandom . mockRestore ( )
60
+ } )
61
+
56
62
describe ( 'toggleCliHelper' , ( ) => {
57
63
it ( 'default state.isShowHelper should be falsy' , ( ) => {
58
64
// Arrange
@@ -479,17 +485,17 @@ describe('cliSettings slice', () => {
479
485
apiService . post = jest . fn ( ) . mockResolvedValue ( responsePayload )
480
486
481
487
// Act
482
- await store . dispatch < any > ( createCliClientAction ( ) )
488
+ await store . dispatch < any > ( createCliClientAction ( INSTANCE_ID_MOCK , ( ) => { } ) )
483
489
484
490
// Assert
485
491
const expectedActions = [
486
492
processCliClient ( ) ,
487
- concatToOutput ( InitOutputText ( ) ) ,
493
+ concatToOutput ( InitOutputText ( '' , 0 , 0 , true , ( ) => { } ) ) ,
488
494
processCliClientSuccess ( responsePayload . data ?. uuid ) ,
489
495
concatToOutput ( ConnectionSuccessOutputText ) ,
490
496
setCliDbIndex ( 0 )
491
497
]
492
- expect ( store . getActions ( ) ) . toEqual ( expectedActions )
498
+ expect ( clearStoreActions ( store . getActions ( ) ) ) . toEqual ( clearStoreActions ( expectedActions ) )
493
499
} )
494
500
495
501
it ( 'call both createCliClientAction and processCliClientFailure when fetch is fail' , async ( ) => {
@@ -505,12 +511,12 @@ describe('cliSettings slice', () => {
505
511
apiService . post = jest . fn ( ) . mockRejectedValueOnce ( responsePayload )
506
512
507
513
// Act
508
- await store . dispatch < any > ( createCliClientAction ( ) )
514
+ await store . dispatch < any > ( createCliClientAction ( INSTANCE_ID_MOCK , ( ) => { } ) )
509
515
510
516
// Assert
511
517
const expectedActions = [
512
518
processCliClient ( ) ,
513
- concatToOutput ( InitOutputText ( ) ) ,
519
+ concatToOutput ( InitOutputText ( '' , 0 , 0 , true , ( ) => { } ) ) ,
514
520
processCliClientFailure ( responsePayload . response . data . message ) ,
515
521
concatToOutput ( cliTexts . CLI_ERROR_MESSAGE ( errorMessage ) )
516
522
]
0 commit comments