@@ -8,17 +8,10 @@ import OperatorHeader from "components/OperatorView/OperatorHeader";
8
8
import * as ReactRedux from "react-redux" ;
9
9
import { defaultStore , getStore , initialState , mountWrapper } from "shared/specs/mountWrapper" ;
10
10
import { FetchError , IStoreState } from "shared/types" ;
11
- import OperatorInstanceUpdateForm , {
12
- IOperatorInstanceUpgradeFormProps ,
13
- } from "./OperatorInstanceUpdateForm" ;
14
-
15
- const defaultProps : IOperatorInstanceUpgradeFormProps = {
16
- csvName : "foo" ,
17
- crdName : "foo-cluster" ,
18
- cluster : initialState . config . kubeappsCluster ,
19
- namespace : "kubeapps" ,
20
- resourceName : "my-foo" ,
21
- } ;
11
+ import OperatorInstanceUpdateForm from "./OperatorInstanceUpdateForm" ;
12
+ import { MemoryRouter , Route } from "react-router-dom" ;
13
+ import { IOperatorsState } from "reducers/operators" ;
14
+ import { IClusterState } from "reducers/cluster" ;
22
15
23
16
const defaultResource = {
24
17
kind : "Foo" ,
@@ -29,7 +22,7 @@ const defaultResource = {
29
22
} as any ;
30
23
31
24
const defaultCRD = {
32
- name : defaultProps . crdName ,
25
+ name : "foo-cluster" ,
33
26
kind : "Foo" ,
34
27
description : "useful description" ,
35
28
} as any ;
@@ -102,21 +95,44 @@ afterEach(() => {
102
95
103
96
it ( "gets resource and CSV" , ( ) => {
104
97
const getResource = jest . fn ( ) ;
98
+ const store = getStore ( {
99
+ operators : {
100
+ resource : defaultResource ,
101
+ csv : defaultCSV ,
102
+ } as Partial < IOperatorsState > ,
103
+ clusters : {
104
+ currentCluster : "default-cluster" ,
105
+ clusters : {
106
+ "default-cluster" : {
107
+ currentNamespace : "kubeapps" ,
108
+ } as Partial < IClusterState > ,
109
+ } ,
110
+ } ,
111
+ } as Partial < IStoreState > ) ;
105
112
const getCSV = jest . fn ( ) ;
106
113
actions . operators . getResource = getResource ;
107
114
actions . operators . getCSV = getCSV ;
108
- mountWrapper ( defaultStore , < OperatorInstanceUpdateForm { ...defaultProps } /> ) ;
109
- expect ( getCSV ) . toHaveBeenCalledWith (
110
- defaultProps . cluster ,
111
- defaultProps . namespace ,
112
- defaultProps . csvName ,
115
+ mountWrapper (
116
+ store ,
117
+ < MemoryRouter
118
+ initialEntries = { [
119
+ "/c/default/ns/default/operators-instances/new/foo/foo-cluster/my-foo/update" ,
120
+ ] }
121
+ >
122
+ < Route
123
+ path = { "/c/:cluster/ns/:namespace/operators-instances/new/:csv/:crd/:instanceName/update" }
124
+ >
125
+ < OperatorInstanceUpdateForm />
126
+ </ Route >
127
+ </ MemoryRouter > ,
113
128
) ;
129
+ expect ( getCSV ) . toHaveBeenCalledWith ( "default-cluster" , "kubeapps" , "foo" ) ;
114
130
expect ( getResource ) . toHaveBeenCalledWith (
115
- defaultProps . cluster ,
116
- defaultProps . namespace ,
117
- defaultProps . csvName ,
118
- defaultProps . crdName ,
119
- defaultProps . resourceName ,
131
+ "default- cluster" ,
132
+ "kubeapps" ,
133
+ "foo" ,
134
+ "foo-cluster" ,
135
+ "my-foo" ,
120
136
) ;
121
137
} ) ;
122
138
@@ -128,7 +144,17 @@ it("set default and deployed values", () => {
128
144
csv : defaultCSV ,
129
145
} ,
130
146
} as Partial < IStoreState > ) ,
131
- < OperatorInstanceUpdateForm { ...defaultProps } /> ,
147
+ < MemoryRouter
148
+ initialEntries = { [
149
+ "/c/default/ns/default/operators-instances/new/foo/foo-cluster/my-foo/update" ,
150
+ ] }
151
+ >
152
+ < Route
153
+ path = { "/c/:cluster/ns/:namespace/operators-instances/new/:csv/:crd/:instanceName/update" }
154
+ >
155
+ < OperatorInstanceUpdateForm />
156
+ </ Route >
157
+ </ MemoryRouter > ,
132
158
) ;
133
159
expect ( wrapper . find ( OperatorInstanceFormBody ) . props ( ) ) . toMatchObject ( {
134
160
defaultValues : 'kind: "Foo"\napiVersion: "v1"\n' ,
@@ -137,7 +163,20 @@ it("set default and deployed values", () => {
137
163
} ) ;
138
164
139
165
it ( "renders an error if the resource is not populated" , ( ) => {
140
- const wrapper = mountWrapper ( defaultStore , < OperatorInstanceUpdateForm { ...defaultProps } /> ) ;
166
+ const wrapper = mountWrapper (
167
+ defaultStore ,
168
+ < MemoryRouter
169
+ initialEntries = { [
170
+ "/c/default/ns/default/operators-instances/new/foo/foo-cluster/my-foo/update" ,
171
+ ] }
172
+ >
173
+ < Route
174
+ path = { "/c/:cluster/ns/:namespace/operators-instances/new/:csv/:crd/:instanceName/update" }
175
+ >
176
+ < OperatorInstanceUpdateForm />
177
+ </ Route >
178
+ </ MemoryRouter > ,
179
+ ) ;
141
180
expect ( wrapper . find ( Alert ) ) . toIncludeText ( "Resource my-foo not found" ) ;
142
181
} ) ;
143
182
@@ -153,7 +192,7 @@ it("renders only an error if the resource is not found", () => {
153
192
} ,
154
193
} ,
155
194
} as Partial < IStoreState > ) ,
156
- < OperatorInstanceUpdateForm { ... defaultProps } /> ,
195
+ < OperatorInstanceUpdateForm /> ,
157
196
) ;
158
197
expect ( wrapper . find ( Alert ) ) . toIncludeText ( "not found" ) ;
159
198
expect ( wrapper . find ( OperatorHeader ) ) . not . toExist ( ) ;
@@ -167,20 +206,38 @@ it("should submit the form", () => {
167
206
operators : {
168
207
resource : defaultResource ,
169
208
csv : defaultCSV ,
209
+ } as Partial < IOperatorsState > ,
210
+ clusters : {
211
+ currentCluster : "default-cluster" ,
212
+ clusters : {
213
+ "default-cluster" : {
214
+ currentNamespace : "kubeapps" ,
215
+ } as Partial < IClusterState > ,
216
+ } ,
170
217
} ,
171
218
} as Partial < IStoreState > ) ,
172
- < OperatorInstanceUpdateForm { ...defaultProps } /> ,
219
+ < MemoryRouter
220
+ initialEntries = { [
221
+ "/c/default/ns/default/operators-instances/new/foo/foo-cluster/my-foo/update" ,
222
+ ] }
223
+ >
224
+ < Route
225
+ path = { "/c/:cluster/ns/:namespace/operators-instances/new/:csv/:crd/:instanceName/update" }
226
+ >
227
+ < OperatorInstanceUpdateForm />
228
+ </ Route >
229
+ </ MemoryRouter > ,
173
230
) ;
174
231
175
232
const form = wrapper . find ( "form" ) ;
176
233
form . simulate ( "submit" , { preventDefault : jest . fn ( ) } ) ;
177
234
178
235
expect ( updateResource ) . toHaveBeenCalledWith (
179
- defaultProps . cluster ,
180
- defaultProps . namespace ,
181
- defaultResource . apiVersion ,
182
- defaultProps . crdName ,
183
- defaultProps . resourceName ,
184
- defaultResource ,
236
+ "default- cluster" ,
237
+ "kubeapps" ,
238
+ "v1" ,
239
+ "foo-cluster" ,
240
+ "my-foo" ,
241
+ { apiVersion : "v1" , kind : "Foo" , metadata : { name : "my-foo" } } ,
185
242
) ;
186
243
} ) ;
0 commit comments