Skip to content

Commit c2c980b

Browse files
update bundle content tests
1 parent dab9bcc commit c2c980b

File tree

1 file changed

+47
-19
lines changed

1 file changed

+47
-19
lines changed

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

+47-19
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ const mockRepoOverview = {
3434
},
3535
}
3636

37-
const mockBranchBundles = {
37+
const mockBranchBundles = (isTimescaleEnabled: boolean) => ({
38+
config: { isTimescaleEnabled },
3839
owner: {
3940
repository: {
4041
__typename: 'Repository',
@@ -63,9 +64,10 @@ const mockBranchBundles = {
6364
},
6465
},
6566
},
66-
}
67+
})
6768

6869
const mockBranchBundlesError = {
70+
config: { isTimescaleEnabled: false },
6971
owner: {
7072
repository: {
7173
__typename: 'Repository',
@@ -85,6 +87,7 @@ const mockBranchBundlesError = {
8587
}
8688

8789
const mockEmptyBundleSelection = {
90+
config: { isTimescaleEnabled: false },
8891
owner: {
8992
repository: {
9093
__typename: 'Repository',
@@ -113,14 +116,8 @@ const mockAssets = {
113116
routes: ['/'],
114117
extension: 'js',
115118
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 },
124121
},
125122
measurements: {
126123
change: { size: { uncompress: 5 } },
@@ -217,14 +214,8 @@ const mockBundleSummary = {
217214
name: 'bundle1',
218215
moduleCount: 10,
219216
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 },
228219
},
229220
},
230221
},
@@ -282,12 +273,14 @@ afterAll(() => {
282273
interface SetupArgs {
283274
isBundleError?: boolean
284275
isEmptyBundleSelection?: boolean
276+
isTimescaleEnabled?: boolean
285277
}
286278

287279
describe('BundleContent', () => {
288280
function setup({
289281
isBundleError = false,
290282
isEmptyBundleSelection = false,
283+
isTimescaleEnabled = true,
291284
}: SetupArgs) {
292285
server.use(
293286
graphql.query('BranchBundleSummaryData', () => {
@@ -296,7 +289,9 @@ describe('BundleContent', () => {
296289
} else if (isEmptyBundleSelection) {
297290
return HttpResponse.json({ data: mockEmptyBundleSelection })
298291
}
299-
return HttpResponse.json({ data: mockBranchBundles })
292+
return HttpResponse.json({
293+
data: mockBranchBundles(isTimescaleEnabled),
294+
})
300295
}),
301296
graphql.query('GetRepoOverview', () => {
302297
return HttpResponse.json({ data: mockRepoOverview })
@@ -398,6 +393,39 @@ describe('BundleContent', () => {
398393
expect(moduleCount).toBeInTheDocument()
399394
})
400395
})
396+
397+
describe('rendering the trend chart', () => {
398+
describe('when timescale is enabled', () => {
399+
it('renders the trend chart', async () => {
400+
setup({ isTimescaleEnabled: true })
401+
render(<BundleContent />, {
402+
wrapper: wrapper(
403+
'/gh/codecov/test-repo/bundles/main/test-bundle'
404+
),
405+
})
406+
407+
const chart = await screen.findByText('Hide chart')
408+
expect(chart).toBeInTheDocument()
409+
})
410+
})
411+
412+
describe('when timescale is disabled', () => {
413+
it('renders the trend chart', async () => {
414+
setup({ isTimescaleEnabled: false })
415+
render(<BundleContent />, {
416+
wrapper: wrapper(
417+
'/gh/codecov/test-repo/bundles/main/test-bundle'
418+
),
419+
})
420+
421+
const bundleName = await screen.findByText('asset-1')
422+
expect(bundleName).toBeInTheDocument()
423+
424+
const chart = screen.queryByText('Hide chart')
425+
expect(chart).not.toBeInTheDocument()
426+
})
427+
})
428+
})
401429
})
402430

403431
describe('when only the branch is set', () => {

0 commit comments

Comments
 (0)