1
+ /* eslint-disable testing-library/no-node-access */
1
2
import { act , render , RenderResult , screen } from '@testing-library/react' ;
2
3
import { formatURL } from '@weaveworks/weave-gitops' ;
3
4
import PipelineDetails from '..' ;
@@ -81,6 +82,7 @@ const res: GetPipelineResponse = {
81
82
kind : 'HelmRelease' ,
82
83
name : 'podinfo' ,
83
84
version : '6.2.0' ,
85
+ lastAppliedRevision : '6.2.0' ,
84
86
} ,
85
87
] ,
86
88
} ,
@@ -141,6 +143,16 @@ const res: GetPipelineResponse = {
141
143
} ,
142
144
} ;
143
145
146
+ interface MappedWorkload {
147
+ kind ?: string | undefined ;
148
+ name ?: string | undefined ;
149
+ namespace ?: string | undefined ;
150
+ version ?: string | undefined ;
151
+ lastAppliedVersion ?: string | undefined ;
152
+ mappedClusterName ?: string | undefined ;
153
+ clusterName ?: string | undefined ;
154
+ }
155
+
144
156
describe ( 'PipelineDetails' , ( ) => {
145
157
let wrap : ( el : JSX . Element ) => JSX . Element ;
146
158
let api : PipelinesClientMock ;
@@ -178,23 +190,14 @@ describe('PipelineDetails', () => {
178
190
) ;
179
191
expect ( targets . length ) . toEqual ( env . targets ?. length ) ;
180
192
181
- let workloads : {
182
- target : string | undefined ;
183
- kind ?: string | undefined ;
184
- name ?: string | undefined ;
185
- namespace ?: string | undefined ;
186
- version ?: string | undefined ;
187
- clusterName ?: string | undefined ;
188
- } [ ] = [ ] ;
193
+ let workloads : MappedWorkload [ ] = [ ] ;
189
194
190
195
targetsStatuses [ env . name ! ] . targetsStatuses ?. forEach ( ts => {
191
196
if ( ts . workloads ) {
192
197
const wrks = ts . workloads . map ( wrk => ( {
193
198
...wrk ,
194
- target : ts . clusterRef ?. name
195
- ? `${ ts . clusterRef ?. name } /${ ts . namespace } `
196
- : ts . namespace ,
197
- clusterName : ts . clusterRef ?. namespace
199
+ clusterName : ts . clusterRef ?. name ,
200
+ mappedClusterName : ts . clusterRef ?. namespace
198
201
? `${ ts . clusterRef ?. namespace } /${ ts . clusterRef . name } `
199
202
: '' ,
200
203
namespace : ts . namespace ,
@@ -205,28 +208,55 @@ describe('PipelineDetails', () => {
205
208
206
209
// Targets
207
210
targets . forEach ( ( target , index ) => {
208
- // Target
209
- const workloadTarget =
210
- target . querySelector ( '.workloadTarget' ) ?. textContent ;
211
- expect ( workloadTarget ) . toEqual ( workloads ! [ index ] . target ) ;
211
+ const workloadTarget = target . querySelector ( '.workloadTarget' ) ;
212
+
213
+ // Cluster Name
214
+ const clusterNameEle = workloadTarget ?. querySelector ( '.cluster-name' ) ;
215
+ if ( workloads ! [ index ] . clusterName ) {
216
+ checkTextContentToEqual (
217
+ clusterNameEle ,
218
+ workloads ! [ index ] . clusterName || '' ,
219
+ ) ;
220
+ } else {
221
+ elementToBeNull ( clusterNameEle ) ;
222
+ }
223
+
224
+ // Workload Namespace
225
+ const workloadNamespace = workloadTarget ?. querySelector (
226
+ '.workload-namespace' ,
227
+ ) ;
228
+ expect ( workloadNamespace ?. textContent ) . toEqual (
229
+ workloads ! [ index ] . namespace ,
230
+ ) ;
212
231
213
232
//Target as a link
214
233
const linkToAutomation = target . querySelector ( '.workloadName > a' ) ;
215
-
216
- if ( workloads ! [ index ] . clusterName ) {
234
+ if ( workloads ! [ index ] . mappedClusterName ) {
217
235
const href = formatURL ( '/helm_release/details' , {
218
236
name : workloads ! [ index ] . name ,
219
237
namespace : workloads ! [ index ] . namespace ,
220
- clusterName : workloads ! [ index ] . clusterName ,
238
+ clusterName : workloads ! [ index ] . mappedClusterName ,
221
239
} ) ;
222
240
linkToExists ( linkToAutomation , href ) ;
223
241
} else {
224
- linkToBeNull ( linkToAutomation ) ;
242
+ elementToBeNull ( linkToAutomation ) ;
243
+ checkTextContentToEqual (
244
+ target . querySelector ( '.workload-name' ) ,
245
+ workloads ! [ index ] . name || '' ,
246
+ ) ;
247
+ }
248
+ // Workload Last Applied Version
249
+ const lastAppliedRevision = target . querySelector (
250
+ 'workloadName > .last-applied-version' ,
251
+ ) ;
252
+ if ( workloads ! [ index ] . lastAppliedVersion ) {
253
+ checkTextContentToEqual (
254
+ lastAppliedRevision ,
255
+ workloads ! [ index ] . lastAppliedVersion || '' ,
256
+ ) ;
257
+ } else {
258
+ elementToBeNull ( lastAppliedRevision ) ;
225
259
}
226
-
227
- // Workload Name
228
- const workloadName = target . querySelector ( '.workloadName' ) ?. textContent ;
229
- expect ( workloadName ) . toEqual ( workloads ! [ index ] . name ) ;
230
260
231
261
// Workload Version
232
262
const workloadVersion = target . querySelector ( '.version' ) ?. textContent ;
@@ -254,9 +284,16 @@ describe('PipelineDetails', () => {
254
284
} ) ;
255
285
} ) ;
256
286
257
- const linkToExists = ( element : Element | null , href : String ) => {
258
- return expect ( element ) . toHaveAttribute ( 'href' , href ) ;
287
+ const linkToExists = ( element : Element | null , href : string ) => {
288
+ expect ( element ) . toHaveAttribute ( 'href' , href ) ;
259
289
} ;
260
- const linkToBeNull = ( element : Element | null ) => {
261
- return expect ( element ) . toBeNull ( ) ;
290
+ const elementToBeNull = ( element : Element | null | undefined ) => {
291
+ expect ( element ) . toBeNull ( ) ;
292
+ } ;
293
+
294
+ const checkTextContentToEqual = (
295
+ element : Element | null | undefined ,
296
+ clusterName : string ,
297
+ ) => {
298
+ expect ( element ?. textContent ) . toEqual ( clusterName ) ;
262
299
} ;
0 commit comments