@@ -18,23 +18,24 @@ vi.mock('./BundleSelection', () => ({
18
18
default : ( ) => < div > BundleSelection</ div > ,
19
19
} ) )
20
20
21
- const mockRepoOverview = {
21
+ const mockRepoOverview = ( hasDefaultBranch : boolean ) => ( {
22
22
owner : {
23
23
isCurrentUserActivated : true ,
24
24
repository : {
25
25
__typename : 'Repository' ,
26
26
private : false ,
27
- defaultBranch : 'main' ,
27
+ defaultBranch : hasDefaultBranch ? 'main' : null ,
28
28
oldestCommitAt : '2022-10-10T11:59:59' ,
29
29
coverageEnabled : true ,
30
30
bundleAnalysisEnabled : true ,
31
31
languages : [ 'javascript' ] ,
32
32
testAnalyticsEnabled : true ,
33
33
} ,
34
34
} ,
35
- }
35
+ } )
36
36
37
- const mockBranchBundles = {
37
+ const mockBranchBundles = ( isTimescaleEnabled : boolean ) => ( {
38
+ config : { isTimescaleEnabled } ,
38
39
owner : {
39
40
repository : {
40
41
__typename : 'Repository' ,
@@ -63,9 +64,10 @@ const mockBranchBundles = {
63
64
} ,
64
65
} ,
65
66
} ,
66
- }
67
+ } )
67
68
68
69
const mockBranchBundlesError = {
70
+ config : { isTimescaleEnabled : false } ,
69
71
owner : {
70
72
repository : {
71
73
__typename : 'Repository' ,
@@ -85,6 +87,7 @@ const mockBranchBundlesError = {
85
87
}
86
88
87
89
const mockEmptyBundleSelection = {
90
+ config : { isTimescaleEnabled : false } ,
88
91
owner : {
89
92
repository : {
90
93
__typename : 'Repository' ,
@@ -113,14 +116,8 @@ const mockAssets = {
113
116
routes : [ '/' ] ,
114
117
extension : 'js' ,
115
118
bundleData : {
116
- loadTime : {
117
- threeG : 2000 ,
118
- highSpeed : 2000 ,
119
- } ,
120
- size : {
121
- uncompress : 3000 ,
122
- gzip : 4000 ,
123
- } ,
119
+ loadTime : { threeG : 2000 , highSpeed : 2000 } ,
120
+ size : { uncompress : 3000 , gzip : 4000 } ,
124
121
} ,
125
122
measurements : {
126
123
change : { size : { uncompress : 5 } } ,
@@ -217,14 +214,8 @@ const mockBundleSummary = {
217
214
name : 'bundle1' ,
218
215
moduleCount : 10 ,
219
216
bundleData : {
220
- loadTime : {
221
- threeG : 1000 ,
222
- highSpeed : 500 ,
223
- } ,
224
- size : {
225
- gzip : 1000 ,
226
- uncompress : 2000 ,
227
- } ,
217
+ loadTime : { threeG : 1000 , highSpeed : 500 } ,
218
+ size : { gzip : 1000 , uncompress : 2000 } ,
228
219
} ,
229
220
} ,
230
221
} ,
@@ -282,12 +273,16 @@ afterAll(() => {
282
273
interface SetupArgs {
283
274
isBundleError ?: boolean
284
275
isEmptyBundleSelection ?: boolean
276
+ isTimescaleEnabled ?: boolean
277
+ hasDefaultBranch ?: boolean
285
278
}
286
279
287
280
describe ( 'BundleContent' , ( ) => {
288
281
function setup ( {
289
282
isBundleError = false ,
290
283
isEmptyBundleSelection = false ,
284
+ isTimescaleEnabled = true ,
285
+ hasDefaultBranch = true ,
291
286
} : SetupArgs ) {
292
287
server . use (
293
288
graphql . query ( 'BranchBundleSummaryData' , ( ) => {
@@ -296,10 +291,12 @@ describe('BundleContent', () => {
296
291
} else if ( isEmptyBundleSelection ) {
297
292
return HttpResponse . json ( { data : mockEmptyBundleSelection } )
298
293
}
299
- return HttpResponse . json ( { data : mockBranchBundles } )
294
+ return HttpResponse . json ( {
295
+ data : mockBranchBundles ( isTimescaleEnabled ) ,
296
+ } )
300
297
} ) ,
301
298
graphql . query ( 'GetRepoOverview' , ( ) => {
302
- return HttpResponse . json ( { data : mockRepoOverview } )
299
+ return HttpResponse . json ( { data : mockRepoOverview ( hasDefaultBranch ) } )
303
300
} ) ,
304
301
graphql . query ( 'BundleAssets' , ( ) => {
305
302
if ( isBundleError ) {
@@ -398,6 +395,39 @@ describe('BundleContent', () => {
398
395
expect ( moduleCount ) . toBeInTheDocument ( )
399
396
} )
400
397
} )
398
+
399
+ describe ( 'rendering the trend chart' , ( ) => {
400
+ describe ( 'when timescale is enabled' , ( ) => {
401
+ it ( 'renders the trend chart' , async ( ) => {
402
+ setup ( { isTimescaleEnabled : true } )
403
+ render ( < BundleContent /> , {
404
+ wrapper : wrapper (
405
+ '/gh/codecov/test-repo/bundles/main/test-bundle'
406
+ ) ,
407
+ } )
408
+
409
+ const chart = await screen . findByText ( 'Hide chart' )
410
+ expect ( chart ) . toBeInTheDocument ( )
411
+ } )
412
+ } )
413
+
414
+ describe ( 'when timescale is disabled' , ( ) => {
415
+ it ( 'renders the trend chart' , async ( ) => {
416
+ setup ( { isTimescaleEnabled : false } )
417
+ render ( < BundleContent /> , {
418
+ wrapper : wrapper (
419
+ '/gh/codecov/test-repo/bundles/main/test-bundle'
420
+ ) ,
421
+ } )
422
+
423
+ const bundleName = await screen . findByText ( 'asset-1' )
424
+ expect ( bundleName ) . toBeInTheDocument ( )
425
+
426
+ const chart = screen . queryByText ( 'Hide chart' )
427
+ expect ( chart ) . not . toBeInTheDocument ( )
428
+ } )
429
+ } )
430
+ } )
401
431
} )
402
432
403
433
describe ( 'when only the branch is set' , ( ) => {
@@ -418,7 +448,7 @@ describe('BundleContent', () => {
418
448
419
449
describe ( 'when bundle and branch are not set' , ( ) => {
420
450
it ( 'renders no branch selected banner and empty table' , async ( ) => {
421
- setup ( { } )
451
+ setup ( { hasDefaultBranch : false } )
422
452
render ( < BundleContent /> , {
423
453
wrapper : wrapper ( '/gh/codecov/test-repo/bundles' ) ,
424
454
} )
@@ -463,7 +493,7 @@ describe('BundleContent', () => {
463
493
describe ( 'when the bundle type is not BundleAnalysisReport' , ( ) => {
464
494
describe ( 'there is no branch data and no branch set' , ( ) => {
465
495
it ( 'renders the info banner' , async ( ) => {
466
- setup ( { isEmptyBundleSelection : true } )
496
+ setup ( { isEmptyBundleSelection : true , hasDefaultBranch : false } )
467
497
render ( < BundleContent /> , {
468
498
wrapper : wrapper ( '/gh/codecov/test-repo/bundles' ) ,
469
499
} )
0 commit comments