Skip to content

Commit

Permalink
Merge branch 'main' into gh-eng-780-fix-hidden-branch-selector-title-…
Browse files Browse the repository at this point in the history
…on-coverage-tab
  • Loading branch information
nicholas-codecov authored Nov 9, 2023
2 parents 284720b + 56c0992 commit 701fa82
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ describe('CommitsTableTeam', () => {
wrapper: wrapper(queryClient),
})

const patchColumn = await screen.findByText('Patch')
const patchColumn = await screen.findByText('Patch %')
expect(patchColumn).toBeInTheDocument()
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const columns = [
}),
columnHelper.accessor('patch', {
id: 'patch',
header: 'Patch',
header: 'Patch %',
cell: ({ renderValue }) => renderValue(),
}),
]
Expand Down
10 changes: 6 additions & 4 deletions src/pages/RepoPage/FlagsTab/FlagsTab.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Redirect, useParams } from 'react-router-dom'

import { SentryRoute } from 'sentry'

import { useRepoSettingsTeam } from 'services/repo'
import { useRepoFlagsSelect } from 'services/repo/useRepoFlagsSelect'
import { TierNames, useTier } from 'services/tier'
import FlagsNotConfigured from 'shared/FlagsNotConfigured'
Expand All @@ -13,9 +14,9 @@ import Header from './Header'
import FlagsTable from './subroute/FlagsTable/FlagsTable'
import TimescaleDisabled from './TimescaleDisabled'

const isDisabled = ({ flagsMeasurementsActive, isRepoBackfilling }) =>
!flagsMeasurementsActive || isRepoBackfilling

const isDisabled = ({ flagsMeasurementsActive, isRepoBackfilling }) => {
return !flagsMeasurementsActive || isRepoBackfilling
}
const showFlagsTable = ({
flagsMeasurementsActive,
flagsMeasurementsBackfilled,
Expand All @@ -31,6 +32,7 @@ function FlagsTab() {
const { data: flagsData } = useRepoFlagsSelect()
const { provider, owner, repo } = useParams()
const { data: tierData } = useTier({ owner, provider })
const { data: repoSettings } = useRepoSettingsTeam()

const {
flagsMeasurementsActive,
Expand All @@ -39,7 +41,7 @@ function FlagsTab() {
isTimescaleEnabled,
} = useRepoBackfillingStatus()

if (tierData === TierNames.TEAM) {
if (tierData === TierNames.TEAM && repoSettings?.repository?.private) {
return <Redirect to={`/${provider}/${owner}/${repo}`} />
}

Expand Down
64 changes: 55 additions & 9 deletions src/pages/RepoPage/FlagsTab/FlagsTab.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,21 @@ const flagsData = [
},
]

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

const server = setupServer()
const queryClient = new QueryClient()
let testLocation = {
Expand All @@ -61,14 +76,23 @@ beforeAll(() => {
console.error = () => {}
server.listen()
})

afterEach(() => {
queryClient.clear()
server.resetHandlers()
})
afterAll(() => server.close())

afterAll(() => {
server.close()
})

describe('Flags Tab', () => {
function setup({ data = {}, flags = flagsData, tierValue = TierNames.PRO }) {
function setup({
data = {},
flags = flagsData,
tierValue = TierNames.PRO,
isPrivate = false,
}) {
useRepoFlagsSelect.mockReturnValue({ data: flags })
useRepoBackfilled.mockReturnValue(data)

Expand All @@ -84,21 +108,43 @@ describe('Flags Tab', () => {
ctx.status(200),
ctx.data({ owner: { plan: { tierName: TierNames.PRO } } })
)
}),
graphql.query('GetRepoSettingsTeam', (req, res, ctx) => {
return res(ctx.status(200), ctx.data(mockRepoSettings(isPrivate)))
})
)
}

describe('when user has a team tier', () => {
beforeEach(() => {
setup({ tierValue: TierNames.TEAM })
describe('the repo is public', () => {
it('renders the flags tab', async () => {
setup({
tierValue: TierNames.TEAM,
isPrivate: false,
data: {
data: {
flagsMeasurementsActive: true,
flagsMeasurementsBackfilled: true,
isTimescaleEnabled: true,
},
},
})
render(<FlagsTab />, { wrapper })

const header = await screen.findByText(/Flags Header Component/)
expect(header).toBeInTheDocument()
})
})

it('redirects to the coverage tab', async () => {
render(<FlagsTab />, { wrapper })
describe('the repo is private', () => {
it('redirects to the coverage tab', async () => {
setup({ tierValue: TierNames.TEAM, isPrivate: true })
render(<FlagsTab />, { wrapper })

await waitFor(() =>
expect(testLocation.pathname).toBe('/gh/codecov/gazebo')
)
await waitFor(() =>
expect(testLocation.pathname).toBe('/gh/codecov/gazebo')
)
})
})
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ describe('PullsTableTeam', () => {
const { queryClient } = setup({})
render(<PullsTableTeam />, { wrapper: wrapper(queryClient) })

const patchColumn = await screen.findByText('Patch')
const patchColumn = await screen.findByText('Patch %')
expect(patchColumn).toBeInTheDocument()
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const columns = [
}),
columnHelper.accessor('patch', {
id: 'patch',
header: () => 'Patch',
header: () => 'Patch %',
cell: ({ renderValue }) => renderValue(),
}),
]
Expand Down

0 comments on commit 701fa82

Please sign in to comment.