@@ -13,7 +13,25 @@ import { MemoryRouter, Route } from 'react-router-dom'
13
13
14
14
import { AssetsTable , ChangeOverTime } from './AssetsTable'
15
15
16
- const mockAssets = ( hasNextPage = true ) => {
16
+ const mocks = vi . hoisted ( ( ) => ( {
17
+ useFlags : vi . fn ( ) . mockReturnValue ( { renderBundleFilePathColumn : true } ) ,
18
+ } ) )
19
+
20
+ vi . mock ( 'shared/featureFlags' , async ( ) => {
21
+ const original = await vi . importActual ( 'shared/featureFlags' )
22
+ return {
23
+ ...original ,
24
+ useFlags : mocks . useFlags ,
25
+ }
26
+ } )
27
+
28
+ const mockAssets = ( {
29
+ hasNextPage = true ,
30
+ pluginName = '@codecov/vite-plugin' ,
31
+ } : {
32
+ hasNextPage ?: boolean
33
+ pluginName ?: string
34
+ } ) => {
17
35
const asset1 = {
18
36
name : 'asset-1' ,
19
37
routes : [ '/' ] ,
@@ -69,7 +87,7 @@ const mockAssets = (hasNextPage = true) => {
69
87
bundleAnalysisReport : {
70
88
__typename : 'BundleAnalysisReport' ,
71
89
bundle : {
72
- info : { pluginName : '@codecov/vite-plugin' } ,
90
+ info : { pluginName } ,
73
91
bundleData : { size : { uncompress : 6000 } } ,
74
92
assetsPaginated : {
75
93
edges : [
@@ -105,6 +123,7 @@ const mockBundleAssetModules = {
105
123
bundleAnalysisReport : {
106
124
__typename : 'BundleAnalysisReport' ,
107
125
bundle : {
126
+ info : { pluginName : '@codecov/vite-plugin' } ,
108
127
bundleData : { size : { uncompress : 12 } } ,
109
128
asset : { modules : [ ] } ,
110
129
} ,
@@ -116,7 +135,7 @@ const mockBundleAssetModules = {
116
135
} ,
117
136
}
118
137
119
- const mockEmptyAssets = {
138
+ const mockEmptyAssets = ( pluginName : string ) => ( {
120
139
owner : {
121
140
repository : {
122
141
__typename : 'Repository' ,
@@ -126,6 +145,7 @@ const mockEmptyAssets = {
126
145
bundleAnalysisReport : {
127
146
__typename : 'BundleAnalysisReport' ,
128
147
bundle : {
148
+ info : { pluginName } ,
129
149
bundleData : { size : { uncompress : 12 } } ,
130
150
assetsPaginated : {
131
151
edges : [ ] ,
@@ -138,7 +158,7 @@ const mockEmptyAssets = {
138
158
} ,
139
159
} ,
140
160
} ,
141
- }
161
+ } )
142
162
143
163
const mockMissingHeadReport = {
144
164
owner : {
@@ -216,13 +236,15 @@ interface SetupArgs {
216
236
isEmptyBundles ?: boolean
217
237
isMissingHeadReport ?: boolean
218
238
multipleAssets ?: boolean
239
+ pluginName ?: string
219
240
}
220
241
221
242
describe ( 'AssetsTable' , ( ) => {
222
243
function setup ( {
223
244
isEmptyBundles = false ,
224
245
isMissingHeadReport = false ,
225
246
multipleAssets = true ,
247
+ pluginName = '@codecov/vite-plugin' ,
226
248
} : SetupArgs ) {
227
249
const user = userEvent . setup ( )
228
250
const mockOrdering = vi . fn ( )
@@ -231,7 +253,7 @@ describe('AssetsTable', () => {
231
253
server . use (
232
254
graphql . query ( 'BundleAssets' , ( info ) => {
233
255
if ( isEmptyBundles ) {
234
- return HttpResponse . json ( { data : mockEmptyAssets } )
256
+ return HttpResponse . json ( { data : mockEmptyAssets ( pluginName ) } )
235
257
} else if ( isMissingHeadReport ) {
236
258
return HttpResponse . json ( { data : mockMissingHeadReport } )
237
259
}
@@ -248,7 +270,9 @@ describe('AssetsTable', () => {
248
270
multipleAssets = true
249
271
}
250
272
251
- return HttpResponse . json ( { data : mockAssets ( multipleAssets ) } )
273
+ return HttpResponse . json ( {
274
+ data : mockAssets ( { hasNextPage : multipleAssets , pluginName } ) ,
275
+ } )
252
276
} ) ,
253
277
graphql . query ( 'BundleAssetModules' , ( ) => {
254
278
return HttpResponse . json ( { data : mockBundleAssetModules } )
@@ -262,17 +286,35 @@ describe('AssetsTable', () => {
262
286
}
263
287
264
288
describe ( 'there is no data' , ( ) => {
265
- it ( 'renders the empty table' , async ( ) => {
266
- setup ( { isEmptyBundles : true } )
267
- render ( < AssetsTable /> , { wrapper } )
289
+ describe ( 'non-file path plugin' , ( ) => {
290
+ it ( 'renders the empty table with 5 dashes' , async ( ) => {
291
+ setup ( { isEmptyBundles : true } )
292
+ render ( < AssetsTable /> , { wrapper } )
268
293
269
- const tableRoles = await screen . findAllByRole ( 'row' )
270
- expect ( tableRoles ) . toHaveLength ( 2 )
294
+ const tableRoles = await screen . findAllByRole ( 'row' )
295
+ expect ( tableRoles ) . toHaveLength ( 2 )
271
296
272
- const tableCells = await within ( tableRoles [ 1 ] ! ) . findAllByRole ( 'cell' )
273
- expect ( tableCells ) . toHaveLength ( 4 )
274
- tableCells . forEach ( ( cell ) => {
275
- expect ( cell ) . toHaveTextContent ( '-' )
297
+ const tableCells = await within ( tableRoles [ 1 ] ! ) . findAllByRole ( 'cell' )
298
+ expect ( tableCells ) . toHaveLength ( 5 )
299
+ tableCells . forEach ( ( cell ) => {
300
+ expect ( cell ) . toHaveTextContent ( '-' )
301
+ } )
302
+ } )
303
+ } )
304
+
305
+ describe ( 'file path plugin' , ( ) => {
306
+ it ( 'renders the empty table with 6 dashes' , async ( ) => {
307
+ setup ( { isEmptyBundles : true , pluginName : '@codecov/sveltekit-plugin' } )
308
+ render ( < AssetsTable /> , { wrapper } )
309
+
310
+ const tableRoles = await screen . findAllByRole ( 'row' )
311
+ expect ( tableRoles ) . toHaveLength ( 2 )
312
+
313
+ const tableCells = await within ( tableRoles [ 1 ] ! ) . findAllByRole ( 'cell' )
314
+ expect ( tableCells ) . toHaveLength ( 6 )
315
+ tableCells . forEach ( ( cell ) => {
316
+ expect ( cell ) . toHaveTextContent ( '-' )
317
+ } )
276
318
} )
277
319
} )
278
320
} )
@@ -286,7 +328,7 @@ describe('AssetsTable', () => {
286
328
expect ( tableRoles ) . toHaveLength ( 2 )
287
329
288
330
const tableCells = await within ( tableRoles [ 1 ] ! ) . findAllByRole ( 'cell' )
289
- expect ( tableCells ) . toHaveLength ( 4 )
331
+ expect ( tableCells ) . toHaveLength ( 5 )
290
332
tableCells . forEach ( ( cell ) => {
291
333
expect ( cell ) . toHaveTextContent ( '-' )
292
334
} )
@@ -303,19 +345,21 @@ describe('AssetsTable', () => {
303
345
expect ( asset ) . toBeInTheDocument ( )
304
346
} )
305
347
306
- it ( 'renders type column' , async ( ) => {
307
- setup ( { } )
308
- render ( < AssetsTable /> , { wrapper } )
348
+ describe ( 'file path plugin' , ( ) => {
349
+ it ( 'renders file path column' , async ( ) => {
350
+ setup ( { pluginName : '@codecov/sveltekit-plugin' } )
351
+ render ( < AssetsTable /> , { wrapper } )
309
352
310
- const type = await screen . findByText ( 'Type' )
311
- expect ( type ) . toBeInTheDocument ( )
353
+ const filePath = await screen . findByText ( 'File path' )
354
+ expect ( filePath ) . toBeInTheDocument ( )
355
+ } )
312
356
} )
313
357
314
358
it ( 'renders load time column' , async ( ) => {
315
359
setup ( { } )
316
360
render ( < AssetsTable /> , { wrapper } )
317
361
318
- const loadTime = await screen . findByText ( 'Estimated load time (3G)' )
362
+ const loadTime = await screen . findByText ( 'Est. load time (3G)' )
319
363
expect ( loadTime ) . toBeInTheDocument ( )
320
364
} )
321
365
@@ -345,6 +389,16 @@ describe('AssetsTable', () => {
345
389
expect ( asset ) . toBeInTheDocument ( )
346
390
} )
347
391
392
+ describe ( 'file path plugin' , ( ) => {
393
+ it ( 'renders file path column' , async ( ) => {
394
+ setup ( { pluginName : '@codecov/sveltekit-plugin' } )
395
+ render ( < AssetsTable /> , { wrapper } )
396
+
397
+ const filePath = await screen . findByText ( '/login' )
398
+ expect ( filePath ) . toBeInTheDocument ( )
399
+ } )
400
+ } )
401
+
348
402
it ( 'renders type column' , async ( ) => {
349
403
setup ( { multipleAssets : false } )
350
404
render ( < AssetsTable /> , { wrapper } )
@@ -436,9 +490,7 @@ describe('AssetsTable', () => {
436
490
const { user, mockOrdering } = setup ( { multipleAssets : false } )
437
491
render ( < AssetsTable /> , { wrapper } )
438
492
439
- const loadTimeColumn = await screen . findByText (
440
- 'Estimated load time (3G)'
441
- )
493
+ const loadTimeColumn = await screen . findByText ( 'Est. load time (3G)' )
442
494
await user . click ( loadTimeColumn )
443
495
444
496
await waitFor ( ( ) => expect ( mockOrdering ) . toHaveBeenCalledWith ( 'SIZE' ) )
0 commit comments