@@ -4,15 +4,26 @@ import {
4
4
QueryClient as QueryClientV5 ,
5
5
} from '@tanstack/react-queryV5'
6
6
import { render , screen , waitFor } from '@testing-library/react'
7
+ import { userEvent } from '@testing-library/user-event'
7
8
import { graphql , HttpResponse } from 'msw'
8
9
import { setupServer } from 'msw/node'
10
+ import { Suspense } from 'react'
11
+ import { Toaster } from 'react-hot-toast'
9
12
import { MemoryRouter , Route } from 'react-router'
10
13
11
14
import { TierNames , TTierNames } from 'services/tier'
12
15
13
16
import ConfigurationManager from './ConfigurationManager'
14
17
import { RepositoryConfiguration } from './hooks/useRepoConfigurationStatus/RepoConfigurationStatusQueryOpts'
15
18
19
+ const mocks = vi . hoisted ( ( ) => ( {
20
+ useFlags : vi . fn ( ) . mockReturnValue ( { displayBundleCachingModal : true } ) ,
21
+ } ) )
22
+
23
+ vi . mock ( 'shared/featureFlags' , ( ) => ( {
24
+ useFlags : mocks . useFlags ,
25
+ } ) )
26
+
16
27
interface mockRepoConfigArgs {
17
28
tierName ?: TTierNames
18
29
flags ?: boolean
@@ -55,6 +66,27 @@ function mockRepoConfig({
55
66
}
56
67
}
57
68
69
+ const mockCachedBundles = {
70
+ owner : {
71
+ repository : {
72
+ __typename : 'Repository' ,
73
+ branch : {
74
+ head : {
75
+ bundleAnalysis : {
76
+ bundleAnalysisReport : {
77
+ __typename : 'BundleAnalysisReport' ,
78
+ bundles : [
79
+ { name : 'bundle1' , isCached : true } ,
80
+ { name : 'bundle2' , isCached : false } ,
81
+ ] ,
82
+ } ,
83
+ } ,
84
+ } ,
85
+ } ,
86
+ } ,
87
+ } ,
88
+ }
89
+
58
90
const queryClient = new QueryClient ( {
59
91
defaultOptions : { queries : { retry : false } } ,
60
92
} )
@@ -66,8 +98,11 @@ const wrapper: React.FC<React.PropsWithChildren> = ({ children }) => (
66
98
< QueryClientProviderV5 client = { queryClientV5 } >
67
99
< QueryClientProvider client = { queryClient } >
68
100
< MemoryRouter initialEntries = { [ '/gh/codecov/cool-repo/config' ] } >
69
- < Route path = "/:provider/:owner/:repo/config" > { children } </ Route >
101
+ < Route path = "/:provider/:owner/:repo/config" >
102
+ < Suspense fallback = { < div > Loading</ div > } > { children } </ Suspense >
103
+ </ Route >
70
104
</ MemoryRouter >
105
+ < Toaster />
71
106
</ QueryClientProvider >
72
107
</ QueryClientProviderV5 >
73
108
)
@@ -90,11 +125,18 @@ interface SetupArgs {
90
125
91
126
describe ( 'Configuration Manager' , ( ) => {
92
127
function setup ( { repoConfig = mockRepoConfig ( { } ) } : SetupArgs ) {
128
+ const user = userEvent . setup ( )
129
+
93
130
server . use (
94
131
graphql . query ( 'GetRepoConfigurationStatus' , ( ) => {
95
132
return HttpResponse . json ( { data : { owner : repoConfig } } )
133
+ } ) ,
134
+ graphql . query ( 'CachedBundleList' , ( ) => {
135
+ return HttpResponse . json ( { data : mockCachedBundles } )
96
136
} )
97
137
)
138
+
139
+ return { user }
98
140
}
99
141
100
142
describe ( 'CoverageConfiguration' , ( ) => {
@@ -374,6 +416,41 @@ describe('Configuration Manager', () => {
374
416
expect ( configuredStatus ) . toBeInTheDocument ( )
375
417
} )
376
418
} )
419
+
420
+ describe ( 'bundle caching' , ( ) => {
421
+ it ( 'renders bundle caching button' , async ( ) => {
422
+ setup ( {
423
+ repoConfig : mockRepoConfig ( {
424
+ bundleAnalysis : true ,
425
+ languages : [ 'typescript' ] ,
426
+ } ) ,
427
+ } )
428
+ render ( < ConfigurationManager /> , { wrapper } )
429
+
430
+ const button = await screen . findByText ( 'Configure data caching' )
431
+ expect ( button ) . toBeInTheDocument ( )
432
+ } )
433
+
434
+ it ( 'renders bundle caching modal' , async ( ) => {
435
+ const { user } = setup ( {
436
+ repoConfig : mockRepoConfig ( {
437
+ bundleAnalysis : true ,
438
+ languages : [ 'typescript' ] ,
439
+ } ) ,
440
+ } )
441
+ render ( < ConfigurationManager /> , { wrapper } )
442
+
443
+ const button = await screen . findByText ( 'Configure data caching' )
444
+ expect ( button ) . toBeInTheDocument ( )
445
+
446
+ await user . click ( button )
447
+
448
+ const modalHeader = await screen . findByText (
449
+ 'Configure bundle caching data'
450
+ )
451
+ expect ( modalHeader ) . toBeInTheDocument ( )
452
+ } )
453
+ } )
377
454
} )
378
455
379
456
describe ( 'TestAnalyticsConfiguration' , ( ) => {
0 commit comments