@@ -2,7 +2,12 @@ import { cloneDeep } from 'lodash'
2
2
import React from 'react'
3
3
import { instance , mock } from 'ts-mockito'
4
4
import { cleanup , mockedStore , render , screen , fireEvent } from 'uiSrc/utils/test-utils'
5
- import { checkDatabaseIndex , connectedInstanceInfoSelector } from 'uiSrc/slices/instances/instances'
5
+ import {
6
+ checkDatabaseIndex ,
7
+ connectedInstanceInfoSelector ,
8
+ connectedInstanceSelector
9
+ } from 'uiSrc/slices/instances/instances'
10
+ import { appContextDbIndex } from 'uiSrc/slices/app/context'
6
11
7
12
import InstanceHeader , { Props } from './InstanceHeader'
8
13
@@ -27,6 +32,18 @@ jest.mock('uiSrc/slices/instances/instances', () => ({
27
32
...jest . requireActual ( 'uiSrc/slices/instances/instances' ) ,
28
33
connectedInstanceInfoSelector : jest . fn ( ) . mockReturnValue ( {
29
34
databases : 16 ,
35
+ } ) ,
36
+ connectedInstanceSelector : jest . fn ( ) . mockReturnValue ( {
37
+ username : 'username' ,
38
+ id : 'instanceId' ,
39
+ loading : false ,
40
+ } )
41
+ } ) )
42
+
43
+ jest . mock ( 'uiSrc/slices/app/context' , ( ) => ( {
44
+ ...jest . requireActual ( 'uiSrc/slices/app/context' ) ,
45
+ appContextDbIndex : jest . fn ( ) . mockReturnValue ( {
46
+ disabled : false ,
30
47
} )
31
48
} ) )
32
49
@@ -77,4 +94,24 @@ describe('InstanceHeader', () => {
77
94
]
78
95
expect ( store . getActions ( ) ) . toEqual ( [ ...expectedActions ] )
79
96
} )
97
+
98
+ it ( 'should be disabled db index button with loading state' , ( ) => {
99
+ ( connectedInstanceSelector as jest . Mock ) . mockReturnValueOnce ( {
100
+ loading : true ,
101
+ } )
102
+
103
+ render ( < InstanceHeader { ...instance ( mockedProps ) } /> )
104
+
105
+ expect ( screen . getByTestId ( 'change-index-btn' ) ) . toBeDisabled ( )
106
+ } )
107
+
108
+ it ( 'should be disabled db index button with disabled state' , ( ) => {
109
+ ( appContextDbIndex as jest . Mock ) . mockReturnValueOnce ( {
110
+ disabled : true ,
111
+ } )
112
+
113
+ render ( < InstanceHeader { ...instance ( mockedProps ) } /> )
114
+
115
+ expect ( screen . getByTestId ( 'change-index-btn' ) ) . toBeDisabled ( )
116
+ } )
80
117
} )
0 commit comments