Skip to content

Commit

Permalink
update BundleContent and tests to work with branch being a string or …
Browse files Browse the repository at this point in the history
…null
  • Loading branch information
nicholas-codecov committed Feb 5, 2025
1 parent 3deaf83 commit c277129
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@ vi.mock('./BundleSelection', () => ({
default: () => <div>BundleSelection</div>,
}))

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,
languages: ['javascript'],
testAnalyticsEnabled: true,
},
},
}
})

const mockBranchBundles = (isTimescaleEnabled: boolean) => ({
config: { isTimescaleEnabled },
Expand Down Expand Up @@ -274,13 +274,15 @@ interface SetupArgs {
isBundleError?: boolean
isEmptyBundleSelection?: boolean
isTimescaleEnabled?: boolean
hasDefaultBranch?: boolean
}

describe('BundleContent', () => {
function setup({
isBundleError = false,
isEmptyBundleSelection = false,
isTimescaleEnabled = true,
hasDefaultBranch = true,
}: SetupArgs) {
server.use(
graphql.query('BranchBundleSummaryData', () => {
Expand All @@ -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) {
Expand Down Expand Up @@ -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(<BundleContent />, {
wrapper: wrapper('/gh/codecov/test-repo/bundles'),
})
Expand Down Expand Up @@ -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(<BundleContent />, {
wrapper: wrapper('/gh/codecov/test-repo/bundles'),
})
Expand Down
8 changes: 4 additions & 4 deletions src/pages/RepoPage/BundlesTab/BundleContent/BundleContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const BundleContent: React.FC = () => {
owner,
})

const branch = branchParam ?? repoOverview?.defaultBranch
const branch = branchParam ?? repoOverview?.defaultBranch ?? null

const { data } = useSuspenseQueryV5(
BranchBundleSummaryQueryOpts({
Expand Down Expand Up @@ -92,13 +92,13 @@ const BundleContent: React.FC = () => {
'/:provider/:owner/:repo/bundles/',
]}
>
<InfoBanner branch={branchParam} bundle={bundle} />
<InfoBanner branch={branch} bundle={bundle} />
<AssetEmptyTable />
</SentryRoute>
</Switch>
) : bundleType === undefined && !branchParam ? (
) : bundleType === undefined && !branch ? (
<>
<InfoBanner branch={branchParam} bundle={bundle} />
<InfoBanner branch={branch} bundle={bundle} />
<AssetEmptyTable />
</>
) : (
Expand Down

0 comments on commit c277129

Please sign in to comment.