From c277129c7ba5aec73537685744b0c988a7233cf8 Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Wed, 5 Feb 2025 08:25:47 -0400 Subject: [PATCH] update BundleContent and tests to work with branch being a string or null --- .../BundleContent/BundleContent.test.tsx | 14 ++++++++------ .../BundlesTab/BundleContent/BundleContent.tsx | 8 ++++---- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/pages/RepoPage/BundlesTab/BundleContent/BundleContent.test.tsx b/src/pages/RepoPage/BundlesTab/BundleContent/BundleContent.test.tsx index b4a4acf6d6..304b73753c 100644 --- a/src/pages/RepoPage/BundlesTab/BundleContent/BundleContent.test.tsx +++ b/src/pages/RepoPage/BundlesTab/BundleContent/BundleContent.test.tsx @@ -18,13 +18,13 @@ vi.mock('./BundleSelection', () => ({ default: () =>
BundleSelection
, })) -const mockRepoOverview = { +const mockRepoOverview = (hasDefaultBranch: boolean) => ({ owner: { isCurrentUserActivated: true, repository: { __typename: 'Repository', private: false, - defaultBranch: 'main', + defaultBranch: hasDefaultBranch ? 'main' : null, oldestCommitAt: '2022-10-10T11:59:59', coverageEnabled: true, bundleAnalysisEnabled: true, @@ -32,7 +32,7 @@ const mockRepoOverview = { testAnalyticsEnabled: true, }, }, -} +}) const mockBranchBundles = (isTimescaleEnabled: boolean) => ({ config: { isTimescaleEnabled }, @@ -274,6 +274,7 @@ interface SetupArgs { isBundleError?: boolean isEmptyBundleSelection?: boolean isTimescaleEnabled?: boolean + hasDefaultBranch?: boolean } describe('BundleContent', () => { @@ -281,6 +282,7 @@ describe('BundleContent', () => { isBundleError = false, isEmptyBundleSelection = false, isTimescaleEnabled = true, + hasDefaultBranch = true, }: SetupArgs) { server.use( graphql.query('BranchBundleSummaryData', () => { @@ -294,7 +296,7 @@ describe('BundleContent', () => { }) }), graphql.query('GetRepoOverview', () => { - return HttpResponse.json({ data: mockRepoOverview }) + return HttpResponse.json({ data: mockRepoOverview(hasDefaultBranch) }) }), graphql.query('BundleAssets', () => { if (isBundleError) { @@ -446,7 +448,7 @@ describe('BundleContent', () => { describe('when bundle and branch are not set', () => { it('renders no branch selected banner and empty table', async () => { - setup({}) + setup({ hasDefaultBranch: false }) render(, { wrapper: wrapper('/gh/codecov/test-repo/bundles'), }) @@ -491,7 +493,7 @@ describe('BundleContent', () => { describe('when the bundle type is not BundleAnalysisReport', () => { describe('there is no branch data and no branch set', () => { it('renders the info banner', async () => { - setup({ isEmptyBundleSelection: true }) + setup({ isEmptyBundleSelection: true, hasDefaultBranch: false }) render(, { wrapper: wrapper('/gh/codecov/test-repo/bundles'), }) diff --git a/src/pages/RepoPage/BundlesTab/BundleContent/BundleContent.tsx b/src/pages/RepoPage/BundlesTab/BundleContent/BundleContent.tsx index d042b84aa6..6683139acb 100644 --- a/src/pages/RepoPage/BundlesTab/BundleContent/BundleContent.tsx +++ b/src/pages/RepoPage/BundlesTab/BundleContent/BundleContent.tsx @@ -48,7 +48,7 @@ const BundleContent: React.FC = () => { owner, }) - const branch = branchParam ?? repoOverview?.defaultBranch + const branch = branchParam ?? repoOverview?.defaultBranch ?? null const { data } = useSuspenseQueryV5( BranchBundleSummaryQueryOpts({ @@ -92,13 +92,13 @@ const BundleContent: React.FC = () => { '/:provider/:owner/:repo/bundles/', ]} > - + - ) : bundleType === undefined && !branchParam ? ( + ) : bundleType === undefined && !branch ? ( <> - + ) : (