From c4079f429e549b45baa6228bb011f0217cced701 Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Wed, 18 Oct 2023 07:40:35 -0300 Subject: [PATCH 1/2] append flags to parent commit link --- .../CommitDetailSummary.jsx | 155 ++++++++++-------- 1 file changed, 89 insertions(+), 66 deletions(-) diff --git a/src/pages/CommitDetailPage/CommitDetailSummary/CommitDetailSummary.jsx b/src/pages/CommitDetailPage/CommitDetailSummary/CommitDetailSummary.jsx index 83a7b4d587..9808cc7a9c 100644 --- a/src/pages/CommitDetailPage/CommitDetailSummary/CommitDetailSummary.jsx +++ b/src/pages/CommitDetailPage/CommitDetailSummary/CommitDetailSummary.jsx @@ -1,3 +1,6 @@ +import qs from 'qs' +import { useLocation } from 'react-router-dom' + import { UploadStateEnum } from 'shared/utils/commit' import A from 'ui/A' import Summary from 'ui/Summary' @@ -5,63 +8,70 @@ import TotalsNumber from 'ui/TotalsNumber' import { useCommitForSummary } from './hooks' -const getSourceSummaryCards = ({ headCommitId, parentCommitId, state }) => - state?.toUpperCase() === UploadStateEnum.error - ? [ - { - name: 'error', - value: ( -

- There is an error processing the coverage reports. Common issues - are{' '} - - files paths - - , empty files or expired reports. See error{' '} - - reference - {' '} - page for additional troubleshooting to resolve error. -

- ), - }, - ] - : [ - { - name: 'source', - title: 'Source', - value: - headCommitId && parentCommitId ? ( -

- This commit{' '} - - {headCommitId?.slice(0, 7)} - {' '} - compared to{' '} - - {parentCommitId?.slice(0, 7)} - {' '} -

- ) : ( - // not really sure what to do here as value - // is a required field on the Summary type -
- ), - }, - ] +const getSourceSummaryCards = ({ + headCommitId, + parentCommitId, + state, + flags, +}) => { + if (state?.toUpperCase() === UploadStateEnum.error) { + return [ + { + name: 'error', + value: ( +

+ There is an error processing the coverage reports. Common issues are{' '} + + files paths + + , empty files or expired reports. See error{' '} + + reference + {' '} + page for additional troubleshooting to resolve error. +

+ ), + }, + ] + } + + return [ + { + name: 'source', + title: 'Source', + value: + headCommitId && parentCommitId ? ( +

+ This commit{' '} + + {headCommitId?.slice(0, 7)} + {' '} + compared to{' '} + + {parentCommitId?.slice(0, 7)} + {' '} +

+ ) : ( + // not really sure what to do here as value + // is a required field on the Summary type +
+ ), + }, + ] +} const getTotalsSummaryCards = ({ headCoverage, @@ -103,6 +113,13 @@ const getTotalsSummaryCards = ({ ] function CommitDetailSummary() { + const location = useLocation() + const queryParams = qs.parse(location.search, { + ignoreQueryPrefix: true, + depth: 1, + }) + const flags = queryParams?.flags ?? [] + const { headCoverage, headCommitId, @@ -112,15 +129,21 @@ function CommitDetailSummary() { state, } = useCommitForSummary() - const fields = [ - ...getTotalsSummaryCards({ - headCoverage, - headCommitId, - patchCoverage, - changeCoverage, - }), - ...getSourceSummaryCards({ headCommitId, parentCommitId, state }), - ] + const totalSummaryCards = getTotalsSummaryCards({ + headCoverage, + headCommitId, + patchCoverage, + changeCoverage, + }) + + const sourceSummaryCards = getSourceSummaryCards({ + headCommitId, + parentCommitId, + state, + flags, + }) + + const fields = [...totalSummaryCards, ...sourceSummaryCards] return (
From 75cf5d0af20c4ae8a730041076503176eac08254 Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Wed, 18 Oct 2023 07:40:46 -0300 Subject: [PATCH 2/2] update tests --- .../CommitDetailSummary.spec.jsx | 69 +++++++++++++++---- 1 file changed, 54 insertions(+), 15 deletions(-) diff --git a/src/pages/CommitDetailPage/CommitDetailSummary/CommitDetailSummary.spec.jsx b/src/pages/CommitDetailPage/CommitDetailSummary/CommitDetailSummary.spec.jsx index 043a1ce2d0..2e9d3be58e 100644 --- a/src/pages/CommitDetailPage/CommitDetailSummary/CommitDetailSummary.spec.jsx +++ b/src/pages/CommitDetailPage/CommitDetailSummary/CommitDetailSummary.spec.jsx @@ -2,6 +2,7 @@ import { QueryClient, QueryClientProvider } from '@tanstack/react-query' import { render, screen } from '@testing-library/react' import { graphql } from 'msw' import { setupServer } from 'msw/node' +import qs from 'qs' import { MemoryRouter, Route } from 'react-router-dom' import CommitDetailSummary from './CommitDetailSummary' @@ -80,20 +81,31 @@ const queryClient = new QueryClient({ }) const server = setupServer() -const wrapper = ({ children }) => ( - - - {children} - - -) +const wrapper = + (initialEntries = '/gh/codecov/cool-repo/commit/sha256') => + ({ children }) => + ( + + + + {children} + + + + ) + +beforeAll(() => { + server.listen() +}) -beforeAll(() => server.listen()) afterEach(() => { queryClient.clear() server.resetHandlers() }) -afterAll(() => server.close()) + +afterAll(() => { + server.close() +}) describe('CommitDetailSummary', () => { function setup(hasErrored = false) { @@ -132,7 +144,7 @@ describe('CommitDetailSummary', () => { describe('renders a card for every valid field', () => { it('has a head card', async () => { - render(, { wrapper }) + render(, { wrapper: wrapper() }) const headCardTitle = await screen.findByText('HEAD') expect(headCardTitle).toBeInTheDocument() @@ -142,7 +154,7 @@ describe('CommitDetailSummary', () => { }) it('has a patch card', async () => { - render(, { wrapper }) + render(, { wrapper: wrapper() }) const patchCardTitle = await screen.findByText('Patch') expect(patchCardTitle).toBeInTheDocument() @@ -152,7 +164,7 @@ describe('CommitDetailSummary', () => { }) it('has a change card', async () => { - render(, { wrapper }) + render(, { wrapper: wrapper() }) const changeCardTitle = await screen.findByText('Change') expect(changeCardTitle).toBeInTheDocument() @@ -162,7 +174,7 @@ describe('CommitDetailSummary', () => { }) it('has a source card', async () => { - render(, { wrapper }) + render(, { wrapper: wrapper() }) const sourceCardTitle = await screen.findByText('Source') expect(sourceCardTitle).toBeInTheDocument() @@ -189,7 +201,7 @@ describe('CommitDetailSummary', () => { }) it('renders error message', async () => { - render(, { wrapper }) + render(, { wrapper: wrapper() }) const errorMsg = await screen.findByText( /There is an error processing the coverage reports/ @@ -198,7 +210,7 @@ describe('CommitDetailSummary', () => { }) it('suggests support links', async () => { - render(, { wrapper }) + render(, { wrapper: wrapper() }) const pathFix = await screen.findByRole('link', { name: 'files paths external-link.svg', @@ -217,4 +229,31 @@ describe('CommitDetailSummary', () => { ) }) }) + + describe('when rendered with a flag query param', () => { + it('appends flag query param to commit id link', async () => { + setup() + + render(, { + wrapper: wrapper( + `/gh/codecov/cool-repo/commit/sha256${qs.stringify( + { flags: ['flag-1'] }, + { addQueryPrefix: true } + )}` + ), + }) + + const parentCommitId = await screen.findByText( + commit().parent.commitid.slice(0, 7) + ) + expect(parentCommitId).toBeInTheDocument() + expect(parentCommitId).toHaveAttribute( + 'href', + `/gh/codecov/cool-repo/commit/fc43199b07c52cf3d6c19b7cdb368f74387c38ab${qs.stringify( + { flags: ['flag-1'] }, + { addQueryPrefix: true } + )}` + ) + }) + }) })