1
1
import { renderHook } from 'uiSrc/utils/test-utils'
2
- import { connectedInstanceSelector } from 'uiSrc/slices/instances/instances'
2
+ import {
3
+ connectedInstanceInfoSelector ,
4
+ connectedInstanceSelector ,
5
+ } from 'uiSrc/slices/instances/instances'
3
6
import useRedisInstanceCompatibility , {
4
7
UseRedisInstanceCompatibilityReturn ,
5
8
} from './useRedisInstanceCompatibility'
6
9
7
10
jest . mock ( 'uiSrc/slices/instances/instances' , ( ) => ( {
8
11
...jest . requireActual ( 'uiSrc/slices/instances/instances' ) ,
9
12
connectedInstanceSelector : jest . fn ( ) ,
13
+ connectedInstanceInfoSelector : jest . fn ( ) ,
10
14
} ) )
11
15
12
16
jest . mock ( 'uiSrc/slices/interfaces' , ( ) => ( {
@@ -20,6 +24,15 @@ const renderUseRedisInstanceCompatibility = () => {
20
24
21
25
describe ( 'useRedisInstanceCompatibility' , ( ) => {
22
26
const mockConnectedInstanceSelector = connectedInstanceSelector as jest . Mock
27
+ const mockConnectedInstanceInfoSelector =
28
+ connectedInstanceInfoSelector as jest . Mock
29
+
30
+ beforeEach ( ( ) => {
31
+ jest . clearAllMocks ( )
32
+ mockConnectedInstanceInfoSelector . mockReturnValue ( {
33
+ version : '7.2.0' ,
34
+ } )
35
+ } )
23
36
24
37
afterEach ( ( ) => {
25
38
jest . clearAllMocks ( )
@@ -29,7 +42,6 @@ describe('useRedisInstanceCompatibility', () => {
29
42
mockConnectedInstanceSelector . mockReturnValue ( {
30
43
loading : undefined ,
31
44
modules : [ { name : 'search' } ] ,
32
- version : '7.2.0' ,
33
45
} )
34
46
35
47
const hookResult = renderUseRedisInstanceCompatibility ( )
@@ -42,7 +54,6 @@ describe('useRedisInstanceCompatibility', () => {
42
54
mockConnectedInstanceSelector . mockReturnValue ( {
43
55
loading : false ,
44
56
modules : null ,
45
- version : '7.2.0' ,
46
57
} )
47
58
48
59
const hookResult = renderUseRedisInstanceCompatibility ( )
@@ -58,6 +69,8 @@ describe('useRedisInstanceCompatibility', () => {
58
69
modules : null ,
59
70
} )
60
71
72
+ mockConnectedInstanceInfoSelector . mockReturnValue ( { } )
73
+
61
74
const hookResult = renderUseRedisInstanceCompatibility ( )
62
75
63
76
expect ( hookResult . loading ) . toBe ( true )
@@ -69,7 +82,6 @@ describe('useRedisInstanceCompatibility', () => {
69
82
mockConnectedInstanceSelector . mockReturnValue ( {
70
83
loading : false ,
71
84
modules : [ { name : 'search' } , { name : 'other' } ] ,
72
- version : '7.2.0' ,
73
85
} )
74
86
75
87
const hookResult = renderUseRedisInstanceCompatibility ( )
@@ -82,7 +94,6 @@ describe('useRedisInstanceCompatibility', () => {
82
94
it ( 'returns hasRedisearch=false when modules is an empty array (defaulted)' , ( ) => {
83
95
mockConnectedInstanceSelector . mockReturnValue ( {
84
96
loading : false ,
85
- version : '7.2.0' ,
86
97
// omit `modules` to hit the default `modules = []`
87
98
} )
88
99
@@ -96,7 +107,6 @@ describe('useRedisInstanceCompatibility', () => {
96
107
mockConnectedInstanceSelector . mockReturnValue ( {
97
108
loading : false ,
98
109
modules : null , // explicit null
99
- version : '7.2.0' ,
100
110
} )
101
111
102
112
const hookResult = renderUseRedisInstanceCompatibility ( )
@@ -108,6 +118,9 @@ describe('useRedisInstanceCompatibility', () => {
108
118
mockConnectedInstanceSelector . mockReturnValue ( {
109
119
loading : false ,
110
120
modules : [ { name : 'RediSearch' } ] ,
121
+ } )
122
+
123
+ mockConnectedInstanceInfoSelector . mockReturnValue ( {
111
124
version : '7.1.9' ,
112
125
} )
113
126
@@ -120,6 +133,9 @@ describe('useRedisInstanceCompatibility', () => {
120
133
mockConnectedInstanceSelector . mockReturnValue ( {
121
134
loading : false ,
122
135
modules : [ { name : 'something else' } ] ,
136
+ } )
137
+
138
+ mockConnectedInstanceInfoSelector . mockReturnValue ( {
123
139
version : 'not a version' ,
124
140
} )
125
141
@@ -131,6 +147,9 @@ describe('useRedisInstanceCompatibility', () => {
131
147
mockConnectedInstanceSelector . mockReturnValue ( {
132
148
loading : false ,
133
149
modules : [ { name : 'search' } ] ,
150
+ } )
151
+
152
+ mockConnectedInstanceInfoSelector . mockReturnValue ( {
134
153
version : undefined ,
135
154
} )
136
155
0 commit comments