Skip to content

Commit c277129

Browse files
committed
update BundleContent and tests to work with branch being a string or null
1 parent 3deaf83 commit c277129

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,21 @@ vi.mock('./BundleSelection', () => ({
1818
default: () => <div>BundleSelection</div>,
1919
}))
2020

21-
const mockRepoOverview = {
21+
const mockRepoOverview = (hasDefaultBranch: boolean) => ({
2222
owner: {
2323
isCurrentUserActivated: true,
2424
repository: {
2525
__typename: 'Repository',
2626
private: false,
27-
defaultBranch: 'main',
27+
defaultBranch: hasDefaultBranch ? 'main' : null,
2828
oldestCommitAt: '2022-10-10T11:59:59',
2929
coverageEnabled: true,
3030
bundleAnalysisEnabled: true,
3131
languages: ['javascript'],
3232
testAnalyticsEnabled: true,
3333
},
3434
},
35-
}
35+
})
3636

3737
const mockBranchBundles = (isTimescaleEnabled: boolean) => ({
3838
config: { isTimescaleEnabled },
@@ -274,13 +274,15 @@ interface SetupArgs {
274274
isBundleError?: boolean
275275
isEmptyBundleSelection?: boolean
276276
isTimescaleEnabled?: boolean
277+
hasDefaultBranch?: boolean
277278
}
278279

279280
describe('BundleContent', () => {
280281
function setup({
281282
isBundleError = false,
282283
isEmptyBundleSelection = false,
283284
isTimescaleEnabled = true,
285+
hasDefaultBranch = true,
284286
}: SetupArgs) {
285287
server.use(
286288
graphql.query('BranchBundleSummaryData', () => {
@@ -294,7 +296,7 @@ describe('BundleContent', () => {
294296
})
295297
}),
296298
graphql.query('GetRepoOverview', () => {
297-
return HttpResponse.json({ data: mockRepoOverview })
299+
return HttpResponse.json({ data: mockRepoOverview(hasDefaultBranch) })
298300
}),
299301
graphql.query('BundleAssets', () => {
300302
if (isBundleError) {
@@ -446,7 +448,7 @@ describe('BundleContent', () => {
446448

447449
describe('when bundle and branch are not set', () => {
448450
it('renders no branch selected banner and empty table', async () => {
449-
setup({})
451+
setup({ hasDefaultBranch: false })
450452
render(<BundleContent />, {
451453
wrapper: wrapper('/gh/codecov/test-repo/bundles'),
452454
})
@@ -491,7 +493,7 @@ describe('BundleContent', () => {
491493
describe('when the bundle type is not BundleAnalysisReport', () => {
492494
describe('there is no branch data and no branch set', () => {
493495
it('renders the info banner', async () => {
494-
setup({ isEmptyBundleSelection: true })
496+
setup({ isEmptyBundleSelection: true, hasDefaultBranch: false })
495497
render(<BundleContent />, {
496498
wrapper: wrapper('/gh/codecov/test-repo/bundles'),
497499
})

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const BundleContent: React.FC = () => {
4848
owner,
4949
})
5050

51-
const branch = branchParam ?? repoOverview?.defaultBranch
51+
const branch = branchParam ?? repoOverview?.defaultBranch ?? null
5252

5353
const { data } = useSuspenseQueryV5(
5454
BranchBundleSummaryQueryOpts({
@@ -92,13 +92,13 @@ const BundleContent: React.FC = () => {
9292
'/:provider/:owner/:repo/bundles/',
9393
]}
9494
>
95-
<InfoBanner branch={branchParam} bundle={bundle} />
95+
<InfoBanner branch={branch} bundle={bundle} />
9696
<AssetEmptyTable />
9797
</SentryRoute>
9898
</Switch>
99-
) : bundleType === undefined && !branchParam ? (
99+
) : bundleType === undefined && !branch ? (
100100
<>
101-
<InfoBanner branch={branchParam} bundle={bundle} />
101+
<InfoBanner branch={branch} bundle={bundle} />
102102
<AssetEmptyTable />
103103
</>
104104
) : (

0 commit comments

Comments
 (0)