Skip to content

Commit

Permalink
fix: Move the banner above summary, and fix the use of team hook in c…
Browse files Browse the repository at this point in the history
…overage tab
  • Loading branch information
RulaKhaled committed May 8, 2024
1 parent e0d67da commit 8cefc74
Show file tree
Hide file tree
Showing 27 changed files with 114 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,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 @@ -33,6 +33,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 @@ -44,6 +44,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
40 changes: 16 additions & 24 deletions src/pages/RepoPage/CoverageTab/CoverageTab.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,6 @@ const queryClient = new QueryClient({

const server = setupServer()

const mockRepoSettings = (isPrivate = false) => ({
owner: {
repository: {
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 @@ -51,13 +36,24 @@ const wrapper =
</QueryClientProvider>
)

const mockRepo = {
const mockRepo = (isPrivate = 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: false,
},
},
}
})

const repoConfigMock = {
owner: {
Expand Down Expand Up @@ -206,8 +202,7 @@ afterAll(() => {

describe('Coverage Tab', () => {
function setup(
{ repoData = mockRepo, isPrivate = false, tierValue = TierNames.PRO } = {
repoData: mockRepo,
{ isPrivate = false, tierValue = TierNames.PRO } = {
isPrivate: false,
tierValue: TierNames.PRO,
}
Expand All @@ -218,7 +213,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)))
),
graphql.query('GetBranches', (req, res, ctx) =>
res(ctx.status(200), ctx.data(branchesMock))
Expand Down Expand Up @@ -266,10 +261,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
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 @@ -358,27 +358,6 @@ describe('CodeTreeTable', () => {
})
})

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

expect(
await screen.findByText(
'Once merged to your default branch, Codecov will show your report results on this dashboard.'
)
).toBeTruthy()
const message = screen.getByText(
'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

0 comments on commit 8cefc74

Please sign in to comment.