Skip to content

Commit

Permalink
fix: display file explorer even when missing base commit (#3050)
Browse files Browse the repository at this point in the history
  • Loading branch information
calvin-codecov authored Aug 5, 2024
1 parent 276dee1 commit d99d8ee
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 15 deletions.
24 changes: 19 additions & 5 deletions src/pages/CommitDetailPage/CommitCoverage/CommitCoverage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,19 @@ function CommitRoutes() {
})

const compareTypeName = commitPageData?.commit?.compareWithParent?.__typename
const ErrorBannerComponent = <ErrorBanner errorType={compareTypeName} />
if (
compareTypeName !== 'Comparison' &&
compareTypeName !== 'FirstPullRequest'
compareTypeName !== 'FirstPullRequest' &&
compareTypeName !== 'MissingBaseCommit'
) {
return <ErrorBanner errorType={compareTypeName} />
return ErrorBannerComponent
}

// we still want to show file explorer when missing base commit since the file structure
// is still useful info to the user
const isMissingBaseCommit = compareTypeName === 'MissingBaseCommit'

const showIndirectChanges = !(overview.private && tierName === TierNames.TEAM)

return (
Expand All @@ -74,17 +80,25 @@ function CommitRoutes() {
<CommitDetailFileExplorer />
</SentryRoute>
<SentryRoute path="/:provider/:owner/:repo/commit/:commit/blob/:path+">
<CommitDetailFileViewer />
{isMissingBaseCommit ? (
ErrorBannerComponent
) : (
<CommitDetailFileViewer />
)}
</SentryRoute>
<SentryRoute path="/:provider/:owner/:repo/commit/:commit" exact>
<FilesChangedTab />
{isMissingBaseCommit ? ErrorBannerComponent : <FilesChangedTab />}
</SentryRoute>
{showIndirectChanges && (
<SentryRoute
path="/:provider/:owner/:repo/commit/:commit/indirect-changes"
exact
>
<IndirectChangesTab />
{isMissingBaseCommit ? (
ErrorBannerComponent
) : (
<IndirectChangesTab />
)}
</SentryRoute>
)}
<Redirect
Expand Down
40 changes: 30 additions & 10 deletions src/pages/CommitDetailPage/CommitCoverage/CommitCoverage.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,8 @@ const mockCommitComponentData = {
}

const mockCommitPageData = (
hasCommitPageDataError = false,
hasCommitPageMissingCommitDataError = false,
hasCommitPageOtherDataError = false,
hasFirstPR = false
) => ({
owner: {
Expand All @@ -284,11 +285,13 @@ const mockCommitPageData = (
commit: {
commitid: 'id-1',
compareWithParent: {
__typename: hasCommitPageDataError
__typename: hasCommitPageMissingCommitDataError
? 'MissingBaseCommit'
: hasFirstPR
? 'FirstPullRequest'
: 'Comparison',
: hasCommitPageOtherDataError
? 'MissingBaseReport'
: hasFirstPR
? 'FirstPullRequest'
: 'Comparison',
},
bundleAnalysisCompareWithParent: {
__typename: 'BundleAnalysisComparison',
Expand Down Expand Up @@ -363,7 +366,8 @@ describe('CommitCoverage', () => {
tierName = TierNames.PRO,
hasCommitErrors = false,
hasErroredUploads = false,
hasCommitPageDataError = false,
hasCommitPageMissingCommitDataError = false,
hasCommitPageOtherDataError = false,
hasFirstPR = false,
coverageEnabled = true,
bundleAnalysisEnabled = true,
Expand All @@ -373,7 +377,8 @@ describe('CommitCoverage', () => {
tierName: TierNames.PRO,
hasCommitErrors: false,
hasErroredUploads: false,
hasCommitPageDataError: false,
hasCommitPageMissingCommitDataError: false,
hasCommitPageOtherDataError: false,
hasFirstPR: false,
isGithubRateLimited: false,
}
Expand Down Expand Up @@ -434,7 +439,13 @@ describe('CommitCoverage', () => {
graphql.query('CommitPageData', (req, res, ctx) => {
return res(
ctx.status(200),
ctx.data(mockCommitPageData(hasCommitPageDataError, hasFirstPR))
ctx.data(
mockCommitPageData(
hasCommitPageMissingCommitDataError,
hasCommitPageOtherDataError,
hasFirstPR
)
)
)
}),
graphql.query('GetRepoRateLimitStatus', (req, res, ctx) => {
Expand Down Expand Up @@ -667,13 +678,22 @@ describe('CommitCoverage', () => {
})

describe('commit has errors', () => {
it('renders error banner', async () => {
const { queryClient } = setup({ hasCommitPageDataError: true })
it('renders error banner for missing base commit', async () => {
const { queryClient } = setup({
hasCommitPageMissingCommitDataError: true,
})
render(<CommitCoverage />, { wrapper: wrapper({ queryClient }) })

const missingBaseCommit = await screen.findByText(/Missing Base Commit/)
expect(missingBaseCommit).toBeInTheDocument()
})
it('renders error banner', async () => {
const { queryClient } = setup({ hasCommitPageOtherDataError: true })
render(<CommitCoverage />, { wrapper: wrapper({ queryClient }) })

const missingBaseCommit = await screen.findByText(/Missing Base Report/)
expect(missingBaseCommit).toBeInTheDocument()
})
})

describe('sending metrics', () => {
Expand Down

0 comments on commit d99d8ee

Please sign in to comment.