Skip to content

Commit 097b9e7

Browse files
Merge branch 'main' into cy/ts_shared_p5
2 parents 34a1906 + d09206c commit 097b9e7

File tree

8 files changed

+348
-96
lines changed

8 files changed

+348
-96
lines changed

src/pages/RepoPage/BundlesTab/BundleContent/AssetsTable/AssetsTable.test.tsx

Lines changed: 77 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,25 @@ import { MemoryRouter, Route } from 'react-router-dom'
1313

1414
import { AssetsTable, ChangeOverTime } from './AssetsTable'
1515

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+
}) => {
1735
const asset1 = {
1836
name: 'asset-1',
1937
routes: ['/'],
@@ -69,7 +87,7 @@ const mockAssets = (hasNextPage = true) => {
6987
bundleAnalysisReport: {
7088
__typename: 'BundleAnalysisReport',
7189
bundle: {
72-
info: { pluginName: '@codecov/vite-plugin' },
90+
info: { pluginName },
7391
bundleData: { size: { uncompress: 6000 } },
7492
assetsPaginated: {
7593
edges: [
@@ -105,6 +123,7 @@ const mockBundleAssetModules = {
105123
bundleAnalysisReport: {
106124
__typename: 'BundleAnalysisReport',
107125
bundle: {
126+
info: { pluginName: '@codecov/vite-plugin' },
108127
bundleData: { size: { uncompress: 12 } },
109128
asset: { modules: [] },
110129
},
@@ -116,7 +135,7 @@ const mockBundleAssetModules = {
116135
},
117136
}
118137

119-
const mockEmptyAssets = {
138+
const mockEmptyAssets = (pluginName: string) => ({
120139
owner: {
121140
repository: {
122141
__typename: 'Repository',
@@ -126,6 +145,7 @@ const mockEmptyAssets = {
126145
bundleAnalysisReport: {
127146
__typename: 'BundleAnalysisReport',
128147
bundle: {
148+
info: { pluginName },
129149
bundleData: { size: { uncompress: 12 } },
130150
assetsPaginated: {
131151
edges: [],
@@ -138,7 +158,7 @@ const mockEmptyAssets = {
138158
},
139159
},
140160
},
141-
}
161+
})
142162

143163
const mockMissingHeadReport = {
144164
owner: {
@@ -216,13 +236,15 @@ interface SetupArgs {
216236
isEmptyBundles?: boolean
217237
isMissingHeadReport?: boolean
218238
multipleAssets?: boolean
239+
pluginName?: string
219240
}
220241

221242
describe('AssetsTable', () => {
222243
function setup({
223244
isEmptyBundles = false,
224245
isMissingHeadReport = false,
225246
multipleAssets = true,
247+
pluginName = '@codecov/vite-plugin',
226248
}: SetupArgs) {
227249
const user = userEvent.setup()
228250
const mockOrdering = vi.fn()
@@ -231,7 +253,7 @@ describe('AssetsTable', () => {
231253
server.use(
232254
graphql.query('BundleAssets', (info) => {
233255
if (isEmptyBundles) {
234-
return HttpResponse.json({ data: mockEmptyAssets })
256+
return HttpResponse.json({ data: mockEmptyAssets(pluginName) })
235257
} else if (isMissingHeadReport) {
236258
return HttpResponse.json({ data: mockMissingHeadReport })
237259
}
@@ -248,7 +270,9 @@ describe('AssetsTable', () => {
248270
multipleAssets = true
249271
}
250272

251-
return HttpResponse.json({ data: mockAssets(multipleAssets) })
273+
return HttpResponse.json({
274+
data: mockAssets({ hasNextPage: multipleAssets, pluginName }),
275+
})
252276
}),
253277
graphql.query('BundleAssetModules', () => {
254278
return HttpResponse.json({ data: mockBundleAssetModules })
@@ -262,17 +286,35 @@ describe('AssetsTable', () => {
262286
}
263287

264288
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 })
268293

269-
const tableRoles = await screen.findAllByRole('row')
270-
expect(tableRoles).toHaveLength(2)
294+
const tableRoles = await screen.findAllByRole('row')
295+
expect(tableRoles).toHaveLength(2)
271296

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+
})
276318
})
277319
})
278320
})
@@ -286,7 +328,7 @@ describe('AssetsTable', () => {
286328
expect(tableRoles).toHaveLength(2)
287329

288330
const tableCells = await within(tableRoles[1]!).findAllByRole('cell')
289-
expect(tableCells).toHaveLength(4)
331+
expect(tableCells).toHaveLength(5)
290332
tableCells.forEach((cell) => {
291333
expect(cell).toHaveTextContent('-')
292334
})
@@ -303,19 +345,21 @@ describe('AssetsTable', () => {
303345
expect(asset).toBeInTheDocument()
304346
})
305347

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 })
309352

310-
const type = await screen.findByText('Type')
311-
expect(type).toBeInTheDocument()
353+
const filePath = await screen.findByText('File path')
354+
expect(filePath).toBeInTheDocument()
355+
})
312356
})
313357

314358
it('renders load time column', async () => {
315359
setup({})
316360
render(<AssetsTable />, { wrapper })
317361

318-
const loadTime = await screen.findByText('Estimated load time (3G)')
362+
const loadTime = await screen.findByText('Est. load time (3G)')
319363
expect(loadTime).toBeInTheDocument()
320364
})
321365

@@ -345,6 +389,16 @@ describe('AssetsTable', () => {
345389
expect(asset).toBeInTheDocument()
346390
})
347391

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+
348402
it('renders type column', async () => {
349403
setup({ multipleAssets: false })
350404
render(<AssetsTable />, { wrapper })
@@ -436,9 +490,7 @@ describe('AssetsTable', () => {
436490
const { user, mockOrdering } = setup({ multipleAssets: false })
437491
render(<AssetsTable />, { wrapper })
438492

439-
const loadTimeColumn = await screen.findByText(
440-
'Estimated load time (3G)'
441-
)
493+
const loadTimeColumn = await screen.findByText('Est. load time (3G)')
442494
await user.click(loadTimeColumn)
443495

444496
await waitFor(() => expect(mockOrdering).toHaveBeenCalledWith('SIZE'))

0 commit comments

Comments
 (0)