Skip to content

Commit

Permalink
Merge branch 'main' into spalmurray/otherci-onboarding-refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
spalmurray-codecov authored Apr 29, 2024
2 parents fbae872 + b0bea5f commit ba367e2
Show file tree
Hide file tree
Showing 45 changed files with 493 additions and 295 deletions.
226 changes: 113 additions & 113 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"@hookform/resolvers": "^2.8.5",
"@radix-ui/react-accordion": "^1.1.2",
"@radix-ui/react-popover": "^1.0.6",
"@sentry/react": "^8.0.0-beta.3",
"@sentry/react": "^8.0.0-beta.4",
"@stripe/react-stripe-js": "^1.7.2",
"@stripe/stripe-js": "^1.52.1",
"@tanstack/react-query": "^4.29.5",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const columns = [
]

function getOrderingDirection(sorting: Array<{ id: string; desc: boolean }>) {
const state = sorting.at(0)
const state = sorting[0]
return state ? (state.desc ? `-${state.id}` : state.id) : undefined
}

Expand Down
25 changes: 16 additions & 9 deletions src/pages/AnalyticsPage/Chart/Chart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { format } from 'date-fns'
import PropTypes from 'prop-types'

import CoverageAreaChart from 'ui/CoverageAreaChart'
import Icon from 'ui/Icon'

import { useCoverage } from './useCoverage'

Expand Down Expand Up @@ -36,15 +37,21 @@ function Chart({ params }) {
})

return (
<CoverageAreaChart
axisLabelFunc={data?.coverageAxisLabel}
data={data?.coverage}
title={`${repos?.join(', ')} coverage chart`}
desc={desc}
renderAreaChart={isPreviousData || isSuccess}
aproxWidth={260.5}
aproxHeight={47.5}
/>
<>
<p className="flex items-center gap-1 self-end text-sm text-ds-gray-senary">
<Icon name="informationCircle" size="sm" />
Data is average of selected repos
</p>
<CoverageAreaChart
axisLabelFunc={data?.coverageAxisLabel}
data={data?.coverage}
title={`${repos?.join(', ')} coverage chart`}
desc={desc}
renderAreaChart={isPreviousData || isSuccess}
aproxWidth={260.5}
aproxHeight={47.5}
/>
</>
)
}

Expand Down
68 changes: 63 additions & 5 deletions src/pages/AnalyticsPage/Chart/Chart.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('Analytics coverage chart', () => {
measurements: [
{
timestamp: '2020-01-01T00:00:00Z',
max: 91.11,
avg: 91.11,
},
],
},
Expand All @@ -43,11 +43,11 @@ describe('Analytics coverage chart', () => {
measurements: [
{
timestamp: '2020-01-01T00:00:00Z',
max: 90.0,
avg: 90.0,
},
{
timestamp: '2021-01-01T00:00:00Z',
max: 91.11,
avg: 91.11,
},
],
},
Expand All @@ -65,7 +65,10 @@ describe('Analytics coverage chart', () => {
}

return res(ctx.status(200), ctx.data(mockDataPoints))
})
}),
graphql.query('OwnerTier', (req, res, ctx) =>
res(ctx.status(200), ctx.data({ owner: { tier: 'pro' } }))
)
)
}

Expand All @@ -88,12 +91,29 @@ describe('Analytics coverage chart', () => {
const message = await screen.findByTitle('coverage chart')
expect(message).toBeInTheDocument()
})

it('renders data label', async () => {
setup({ hasNoData: true })
render(
<Chart
params={{
startDate: '2020-01-15',
endDate: '2020-01-19',
}}
/>,
{
wrapper,
}
)

const label = await screen.findByText(/Data is average of selected repos/)
expect(label).toBeInTheDocument()
})
})

describe('One data point', () => {
it('Not enough data to render', async () => {
setup({ hasSingleData: true })

render(
<Chart
params={{
Expand All @@ -110,6 +130,25 @@ describe('Analytics coverage chart', () => {
const message = await screen.findByText(/Not enough data to render/)
expect(message).toBeInTheDocument()
})

it('renders data label', async () => {
setup({ hasSingleData: true })
render(
<Chart
params={{
startDate: '2020-01-15',
endDate: '2020-01-19',
repositories: [],
}}
/>,
{
wrapper,
}
)

const label = await screen.findByText(/Data is average of selected repos/)
expect(label).toBeInTheDocument()
})
})

describe('Chart with data', () => {
Expand Down Expand Up @@ -154,5 +193,24 @@ describe('Analytics coverage chart', () => {
)
expect(message).toBeInTheDocument()
})

it('renders data label', async () => {
setup({ hasNoData: false, hasSingleData: false })
render(
<Chart
params={{
startDate: '2020-01-15',
endDate: '2020-01-19',
repositories: ['api', 'frontend'],
}}
/>,
{
wrapper,
}
)

const label = await screen.findByText(/Data is average of selected repos/)
expect(label).toBeInTheDocument()
})
})
})
6 changes: 3 additions & 3 deletions src/pages/AnalyticsPage/Chart/useCoverage.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ export const useCoverage = ({ params, options = {} }) => {
isPublic: shouldDisplayPublicReposOnly,
opts: {
select: (data) => {
if (data?.measurements?.[0]?.max === null) {
data.measurements[0].max = 0
if (data?.measurements?.[0]?.avg === null) {
data.measurements[0].avg = 0
}

// set prevPercent so we can reuse value if next value is null
let prevPercent = data?.measurements?.[0]
const coverage = data?.measurements?.map((measurement) => {
let coverage = measurement?.max ?? prevPercent
let coverage = measurement?.avg ?? prevPercent

// can save on a few reassignments
if (prevPercent !== coverage) {
Expand Down
16 changes: 8 additions & 8 deletions src/pages/AnalyticsPage/Chart/useCoverage.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@ const mockRepoMeasurements = {
measurements: [
{
timestamp: '2023-01-01T00:00:00+00:00',
max: 85,
avg: 85,
},
{
timestamp: '2023-01-02T00:00:00+00:00',
max: 80,
avg: 80,
},
{
timestamp: '2023-01-02T00:00:00+00:00',
max: null,
avg: null,
},
{
timestamp: '2023-01-03T00:00:00+00:00',
max: 80,
avg: 80,
},
{
timestamp: '2023-01-04T00:00:00+00:00',
max: 95,
avg: 95,
},
],
},
Expand All @@ -42,11 +42,11 @@ const mockNullFirstValRepoMeasurements = {
measurements: [
{
timestamp: '2023-01-01T00:00:00+00:00',
max: null,
avg: null,
},
{
timestamp: '2023-01-02T00:00:00+00:00',
max: 80,
avg: 80,
},
],
},
Expand All @@ -57,7 +57,7 @@ const mockPublicRepoMeasurements = {
measurements: [
{
timestamp: '2023-01-02T00:00:00+00:00',
max: 80,
avg: 80,
},
],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const isNumericValue = (value: string) =>
value === 'patchPercentage' || value === 'head' || value === 'change'

function getFilter(sorting: Array<{ id: string; desc: boolean }>) {
const state = sorting.at(0)
const state = sorting[0]

if (state) {
const direction = state?.desc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const isNumericColumn = (cellId: string) =>
cellId === 'missedLines' || cellId === 'patchPercentage'

export function getFilter(sorting: Array<{ id: string; desc: boolean }>) {
const state = sorting.at(0)
const state = sorting[0]

if (state) {
const direction = state?.desc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ function LoadMoreTrigger({
}

function getOrderingDirection(sorting: Array<{ id: string; desc: boolean }>) {
const state = sorting.at(0)
const state = sorting[0]
return state ? (state.desc ? `-${state.id}` : state.id) : undefined
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@ const GithubConfigBanner = () => {
Configure{' '}
<A
data-testid="codecovGithubApp-link"
to={{ pageName: 'codecovGithubApp' }}
to={{ pageName: 'codecovGithubAppSelectTarget' }}
>
Codecov&apos;s GitHub app
</A>
</h2>
</BannerHeading>
<BannerContent>
<p>Codecov will use the integration to post statuses and comments.</p>
<p>
Enable status posts, comments, improved rate limit handling, and
private repo management.
</p>
</BannerContent>
</Banner>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('GithubConfigBanner', () => {
})

const body = screen.queryByText(
/Codecov will use the integration to post statuses and comments./
/Enable status posts, comments, improved rate limit handling, and private repo management./
)
expect(body).toBeInTheDocument()
})
Expand All @@ -50,7 +50,7 @@ describe('GithubConfigBanner', () => {
})

const body = screen.queryByText(
/Codecov will use the integration to post statuses and comments./
/Enable status posts, comments, improved rate limit handling, and private repo management./
)
expect(body).not.toBeInTheDocument()
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ const mockPull = {
},
],
},
head: {
branchName: 'abc',
},
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import qs, { type ParsedQs } from 'qs'
import { useMemo } from 'react'
import { useLocation } from 'react-router-dom'

import A from 'ui/A'
import Spinner from 'ui/Spinner'
import TotalsNumber from 'ui/TotalsNumber'

Expand Down Expand Up @@ -132,7 +133,17 @@ export default function ComponentsTable() {

return (
<>
<div className="my-2 flex flex-row-reverse">
<div className="flex w-full items-center justify-between px-5 py-2">
<A
hook="components"
to={{
pageName: 'componentsTab',
options: { branch: data?.pull?.head?.branchName },
}}
isExternal
>
View components over time
</A>
<ComponentsSelector />
</div>
<div className="tableui">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ export const query = `
message
}
}
head {
branchName
}
}
}
... on NotFoundError {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ const mockResponse = {
},
],
},
head: {
branchName: 'abc',
},
},
},
},
Expand Down Expand Up @@ -139,6 +142,9 @@ describe('useComponentComparison', () => {
},
],
},
head: {
branchName: 'abc',
},
},
})
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ const RepositorySchema = z.object({
MissingHeadCommitSchema,
MissingHeadReportSchema,
]),
head: z
.object({
branchName: z.string().nullable(),
})
.nullable(),
})
.nullable(),
})
Expand Down
Loading

0 comments on commit ba367e2

Please sign in to comment.