Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Move the banner above summary, and fix the use of team hook #2859

Merged
merged 4 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const mockGetRepo = (hasUploadToken: boolean, isActive: boolean) => ({
activated: false,
oldestCommitAt: '',
active: isActive,
isFirstPullRequest: false,
},
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const mockGetRepo = {
activated: false,
oldestCommitAt: '',
active: true,
isFirstPullRequest: false,
},
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const mockGetRepo = {
activated: false,
oldestCommitAt: '',
active: true,
isFirstPullRequest: false,
},
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const mockGetRepo = {
activated: false,
oldestCommitAt: '',
active: true,
isFirstPullRequest: false,
},
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const mockGetRepo = {
activated: true,
oldestCommitAt: '2020-01-01T12:00:00',
active: true,
isFirstPullRequest: false,
},
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ const mockGetRepo = ({
activated: isRepoActivated,
oldestCommitAt: '2022-10-10T11:59:59',
active: isRepoActive,
isFirstPullRequest: false,
},
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const mockGetRepo = {
activated: false,
oldestCommitAt: '',
active: true,
isFirstPullRequest: false,
},
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const mockGetRepo = {
activated: false,
oldestCommitAt: '',
active: true,
isFirstPullRequest: false,
},
},
}
Expand Down
1 change: 1 addition & 0 deletions src/pages/RepoPage/CoverageOnboarding/NewRepoTab.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const mockGetRepo = (
activated: false,
oldestCommitAt: '',
active: hasCommits,
isFirstPullRequest: false,
},
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const mockGetRepo = {
activated: false,
oldestCommitAt: '',
active: true,
isFirstPullRequest: false,
},
},
}
Expand Down
15 changes: 12 additions & 3 deletions src/pages/RepoPage/CoverageTab/CoverageTab.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import { Switch, useParams } from 'react-router-dom'
import { SentryRoute } from 'sentry'

import SilentNetworkErrorWrapper from 'layouts/shared/SilentNetworkErrorWrapper'
import { useRepoSettingsTeam } from 'services/repo'
import { useRepo } from 'services/repo'
import { TierNames, useTier } from 'services/tier'
import { useFlags } from 'shared/featureFlags'
import Spinner from 'ui/Spinner'

import FirstPullRequestBanner from './FirstPullRequestBanner'
import Summary from './Summary'
import SummaryTeamPlan from './SummaryTeamPlan'
import ToggleElement from './ToggleElement'
Expand All @@ -25,11 +26,16 @@ const Loader = () => (
)

function CoverageTab() {
const { data: repoData } = useRepoSettingsTeam()
const { provider, owner, repo } = useParams()
const { data: repoData } = useRepo({
provider,
owner,
repo,
})

const { multipleTiers } = useFlags({
multipleTiers: false,
})
const { provider, owner } = useParams()
const { data: tierName } = useTier({ provider, owner })

const showTeamSummary =
Expand All @@ -39,6 +45,9 @@ function CoverageTab() {

return (
<div className="mx-4 flex flex-col gap-2 divide-y border-solid border-ds-gray-secondary sm:mx-0">
{repoData?.repository?.isFirstPullRequest ? (
<FirstPullRequestBanner />
) : null}
{showTeamSummary ? <SummaryTeamPlan /> : <Summary />}
{!showTeamSummary && (
<SentryRoute
Expand Down
58 changes: 32 additions & 26 deletions src/pages/RepoPage/CoverageTab/CoverageTab.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,6 @@ const queryClient = new QueryClient({

const server = setupServer()

const mockRepoSettings = (isPrivate = false) => ({
owner: {
repository: {
__typename: 'Repository',
activated: true,
defaultBranch: 'master',
private: isPrivate,
uploadToken: 'token',
graphToken: 'token',
yaml: 'yaml',
bot: {
username: 'test',
},
},
},
})

const wrapper =
(initialEntries = ['/gh/codecov/cool-repo/tree/main']) =>
({ children }) =>
Expand All @@ -53,13 +36,24 @@ const wrapper =
</QueryClientProvider>
)

const mockRepo = {
const mockRepo = (isPrivate = false, isFirstPullRequest = false) => ({
owner: {
isCurrentUserPartOfOrg: true,
isAdmin: null,
isCurrentUserActivated: null,
repository: {
__typename: 'Repository',
private: isPrivate,
uploadToken: '9e6a6189-20f1-482d-ab62-ecfaa2629295',
defaultBranch: 'main',
yaml: '',
activated: false,
oldestCommitAt: '',
active: true,
isFirstPullRequest,
},
},
}
})

const repoConfigMock = {
owner: {
Expand Down Expand Up @@ -208,10 +202,14 @@ afterAll(() => {

describe('Coverage Tab', () => {
function setup(
{ repoData = mockRepo, isPrivate = false, tierValue = TierNames.PRO } = {
repoData: mockRepo,
{
isPrivate = false,
tierValue = TierNames.PRO,
isFirstPullRequest = false,
} = {
isPrivate: false,
tierValue: TierNames.PRO,
isFirstPullRequest: false,
}
) {
useFlags.mockReturnValue({
Expand All @@ -220,7 +218,7 @@ describe('Coverage Tab', () => {

server.use(
graphql.query('GetRepo', (req, res, ctx) =>
res(ctx.status(200), ctx.data(repoData))
res(ctx.status(200), ctx.data(mockRepo(isPrivate, isFirstPullRequest)))
),
graphql.query('GetBranches', (req, res, ctx) =>
res(ctx.status(200), ctx.data(branchesMock))
Expand Down Expand Up @@ -268,10 +266,7 @@ describe('Coverage Tab', () => {
(req, res, ctx) => {
return res(ctx.status(200), ctx.json({ data: {} }))
}
),
graphql.query('GetRepoSettingsTeam', (req, res, ctx) => {
return res(ctx.status(200), ctx.data(mockRepoSettings(isPrivate)))
})
)
)
}

Expand Down Expand Up @@ -328,4 +323,15 @@ describe('Coverage Tab', () => {
expect(coverageChart).not.toBeInTheDocument()
})
})

it('renders first pull request banner', async () => {
setup({ isFirstPullRequest: true })

render(<CoverageTab />, { wrapper: wrapper(['/gh/test-org/repoName']) })

const firstPullRequestBanner = await screen.findByText(
/Once merged to your default branch, Codecov will show your report results on this dashboard./
)
expect(firstPullRequestBanner).toBeInTheDocument()
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { render, screen } from '@testing-library/react'
import { MemoryRouter, Route } from 'react-router-dom'

import FirstPullRequestBanner from './FirstPullRequestBanner'

const wrapper: React.FC<React.PropsWithChildren> = ({ children }) => (
<MemoryRouter initialEntries={['/gh/codecov/gazebo']}>
<Route path="/:provider/:owner/:repo">{children}</Route>
</MemoryRouter>
)

describe('FirstPullRequestBanner', () => {
it('renders content', () => {
render(<FirstPullRequestBanner />, { wrapper })
const content = screen.getByText(
'Once merged to your default branch, Codecov will show your report results on this dashboard.'
)
expect(content).toBeInTheDocument()
})

it('renders the correct link', () => {
render(<FirstPullRequestBanner />, { wrapper })
const link = screen.getByRole('link', { name: 'edit default branch' })
expect(link).toHaveAttribute('href', '/gh/codecov/gazebo/settings')
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import A from 'ui/A'
import Banner from 'ui/Banner'
import BannerContent from 'ui/Banner/BannerContent'

const FirstPullRequestBanner = () => {
return (
<Banner>
<BannerContent>
<p>
Once merged to your default branch, Codecov will show your report
results on this dashboard.{' '}
<A
to={{ pageName: 'settings' }}
hook={'repo-to-edit-branch'}
variant="semibold"
isExternal={false}
data-testid="settings-page"
>
edit default branch
</A>
</p>
</BannerContent>
</Banner>
)
}

export default FirstPullRequestBanner
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './FirstPullRequestBanner'
Original file line number Diff line number Diff line change
Expand Up @@ -356,22 +356,6 @@ describe('CodeTreeTable', () => {
})
})

describe('there is no results found', () => {
it('displays error fetching data message', async () => {
setup({ noFiles: true })
render(<CodeTreeTable />, { wrapper: wrapper() })

const message = await screen.findByText(
'Once merged to your default branch, Codecov will show your report results on this dashboard.'
)
expect(message).toBeInTheDocument()

const link = await screen.findByTestId('settings-page')
expect(link).toBeInTheDocument()
expect(link).toHaveAttribute('href', '/gh/codecov/cool-repo/settings')
})
})

describe('when head commit has no reports', () => {
it('renders no report uploaded message', async () => {
setup({ noHeadReport: true })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,24 +290,6 @@ describe('FileListTable', () => {
})
})

describe('there is no results found', () => {
it('displays error fetching data message', async () => {
setup({ noFiles: true })
render(<FileListTable />, {
wrapper: wrapper('/gh/codecov/cool-repo/tree/main/'),
})

const message = await screen.findByText(
'Once merged to your default branch, Codecov will show your report results on this dashboard.'
)
expect(message).toBeInTheDocument()

const link = await screen.findByTestId('settings-page')
expect(link).toBeInTheDocument()
expect(link).toHaveAttribute('href', '/gh/codecov/cool-repo/settings')
})
})

describe('when head commit has no reports', () => {
it('renders no report uploaded message', async () => {
setup({ noHeadReport: true })
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { render, screen } from '@testing-library/react'
import { MemoryRouter, Route, useParams } from 'react-router-dom'

import RepoContentsResult from './RepoContentsResult'

Expand Down Expand Up @@ -58,51 +56,6 @@ describe('RepoContentsResult', () => {
expect(noCoverageForFlags).toBeInTheDocument()
})

it('renders no coverage for default if there is no coverage on the branch', async () => {
const props = {
isSearching: false,
isMissingHeadReport: false,
hasFlagsSelected: false,
hasComponentsSelected: false,
}

const queryClient = new QueryClient({
defaultOptions: {
queries: {
retry: false,
},
},
})

const mockedUseParams = useParams as jest.Mock
mockedUseParams.mockReturnValue({
owner: 'codecov',
provider: 'gh',
repo: 'cool-repo',
})

render(
<QueryClientProvider client={queryClient}>
<MemoryRouter
initialEntries={['/gh/codecov/cool-repo/tree/main/a/b/c']}
>
<Route path="/:provider/:owner/:repo/tree/:branch/:path+">
<RepoContentsResult {...props} />
</Route>
</MemoryRouter>
</QueryClientProvider>
)

const noCoverageForFlags = await screen.findByText(
/Once merged to your default branch, Codecov will show your report results on this dashboard./
)
expect(noCoverageForFlags).toBeInTheDocument()

const link = await screen.findByTestId('settings-page')
expect(link).toBeInTheDocument()
expect(link).toHaveAttribute('href', '/gh/codecov/cool-repo/settings')
})

it('renders no coverage for components if user has components selected', async () => {
const props = {
isSearching: false,
Expand Down