@@ -8,10 +8,19 @@ import { userEvent } from '@testing-library/user-event'
8
8
import { graphql , HttpResponse } from 'msw'
9
9
import { setupServer } from 'msw/node'
10
10
import { Suspense } from 'react'
11
+ import { Toaster } from 'react-hot-toast'
11
12
import { MemoryRouter , Route } from 'react-router-dom'
12
13
13
14
import BundleSelection from './BundleSelection'
14
15
16
+ const mocks = vi . hoisted ( ( ) => ( {
17
+ useFlags : vi . fn ( ) . mockReturnValue ( { displayBundleCachingModal : true } ) ,
18
+ } ) )
19
+
20
+ vi . mock ( 'shared/featureFlags' , ( ) => ( {
21
+ useFlags : mocks . useFlags ,
22
+ } ) )
23
+
15
24
const mockRepoOverview = {
16
25
__typename : 'Repository' ,
17
26
private : false ,
@@ -61,6 +70,27 @@ const mockBranchBundles = {
61
70
} ,
62
71
}
63
72
73
+ const mockCachedBundles = {
74
+ owner : {
75
+ repository : {
76
+ __typename : 'Repository' ,
77
+ branch : {
78
+ head : {
79
+ bundleAnalysis : {
80
+ bundleAnalysisReport : {
81
+ __typename : 'BundleAnalysisReport' ,
82
+ bundles : [
83
+ { name : 'bundle1' , isCached : true } ,
84
+ { name : 'bundle2' , isCached : false } ,
85
+ ] ,
86
+ } ,
87
+ } ,
88
+ } ,
89
+ } ,
90
+ } ,
91
+ } ,
92
+ }
93
+
64
94
const server = setupServer ( )
65
95
const queryClient = new QueryClient ( {
66
96
defaultOptions : { queries : { retry : false , suspense : true } } ,
@@ -85,6 +115,7 @@ const wrapper =
85
115
] }
86
116
>
87
117
< Suspense fallback = { < p > Loading</ p > } > { children } </ Suspense >
118
+ < Toaster />
88
119
</ Route >
89
120
</ MemoryRouter >
90
121
</ QueryClientProvider >
@@ -136,6 +167,9 @@ describe('BundleSelection', () => {
136
167
} ) ,
137
168
graphql . query ( 'BranchBundlesNames' , ( ) => {
138
169
return HttpResponse . json ( { data : mockBranchBundles } )
170
+ } ) ,
171
+ graphql . query ( 'CachedBundleList' , ( ) => {
172
+ return HttpResponse . json ( { data : mockCachedBundles } )
139
173
} )
140
174
)
141
175
@@ -182,6 +216,16 @@ describe('BundleSelection', () => {
182
216
expect ( loadSelector ) . toBeInTheDocument ( )
183
217
} )
184
218
219
+ it ( 'renders bundle caching button' , async ( ) => {
220
+ setup ( )
221
+ render ( < BundleSelection /> , { wrapper : wrapper ( ) } )
222
+
223
+ const bundleCachingButton = await screen . findByRole ( 'button' , {
224
+ name : 'Configure data caching' ,
225
+ } )
226
+ expect ( bundleCachingButton ) . toBeInTheDocument ( )
227
+ } )
228
+
185
229
describe ( 'user interacts with branch and bundle selectors' , ( ) => {
186
230
describe ( 'user selects a branch' , ( ) => {
187
231
it ( 'resets the bundle selector to the first available bundle' , async ( ) => {
@@ -277,4 +321,21 @@ describe('BundleSelection', () => {
277
321
} )
278
322
} )
279
323
} )
324
+
325
+ describe ( 'user clicks bundle caching button' , ( ) => {
326
+ it ( 'renders bundle caching modal' , async ( ) => {
327
+ const { user } = setup ( )
328
+ render ( < BundleSelection /> , { wrapper : wrapper ( ) } )
329
+
330
+ const bundleCachingButton = await screen . findByRole ( 'button' , {
331
+ name : 'Configure data caching' ,
332
+ } )
333
+ await user . click ( bundleCachingButton )
334
+
335
+ const modalHeader = await screen . findByText (
336
+ 'Configure bundle caching data'
337
+ )
338
+ expect ( modalHeader ) . toBeInTheDocument ( )
339
+ } )
340
+ } )
280
341
} )
0 commit comments