Skip to content

Commit fded78d

Browse files
committed
#RI-2409 - cover disabled state for button by tests
1 parent 1a9d9e2 commit fded78d

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

redisinsight/ui/src/components/instance-header/InstanceHeader.spec.tsx

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ import { cloneDeep } from 'lodash'
22
import React from 'react'
33
import { instance, mock } from 'ts-mockito'
44
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'
611

712
import InstanceHeader, { Props } from './InstanceHeader'
813

@@ -27,6 +32,18 @@ jest.mock('uiSrc/slices/instances/instances', () => ({
2732
...jest.requireActual('uiSrc/slices/instances/instances'),
2833
connectedInstanceInfoSelector: jest.fn().mockReturnValue({
2934
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,
3047
})
3148
}))
3249

@@ -77,4 +94,24 @@ describe('InstanceHeader', () => {
7794
]
7895
expect(store.getActions()).toEqual([...expectedActions])
7996
})
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+
})
80117
})

0 commit comments

Comments
 (0)