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

feat: Hide Commits Page Team Files Changed Table for Public Repos #2364

Merged
merged 3 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/pages/CommitDetailPage/CommitDetailPage.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { setupServer } from 'msw/node'
import { Suspense } from 'react'
import { MemoryRouter, Route } from 'react-router-dom'

import { TierNames } from 'services/tier'
import { useTruncation } from 'ui/TruncatedMessage/hooks'

import CommitPage from './CommitDetailPage'
Expand All @@ -13,6 +14,29 @@ jest.mock('./CommitDetailPageContent', () => () => 'CommitDetailPageContent')
jest.mock('./UploadsCard', () => () => 'UploadsCard')
jest.mock('ui/TruncatedMessage/hooks')

const mockProTier = {
owner: {
plan: {
tierName: TierNames.PRO,
},
},
}

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

const mockCommit = {
owner: {
isCurrentUserPartOfOrg: true,
Expand Down Expand Up @@ -182,6 +206,12 @@ describe('CommitPage', () => {
}),
rest.get('/internal/gh/codecov/account-details/', (req, res, ctx) => {
return res(ctx.status(200), ctx.json({}))
}),
graphql.query('GetRepoSettingsTeam', (req, res, ctx) => {
return res(ctx.status(200), ctx.data(mockRepoSettings(false)))
}),
graphql.query('OwnerTier', (req, res, ctx) => {
return res(ctx.status(200), ctx.data(mockProTier))
})
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,21 @@ const mockProTier = {
},
}

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

const server = setupServer()
const queryClient = new QueryClient()

Expand Down Expand Up @@ -58,10 +73,11 @@ afterAll(() => {
interface SetupArgs {
planValue: 'team' | 'pro'
flagValue: boolean
isPrivate?: boolean
}

describe('FilesChangedTab', () => {
function setup({ planValue, flagValue }: SetupArgs) {
function setup({ planValue, flagValue, isPrivate = false }: SetupArgs) {
mockedUseFlags.mockReturnValue({
multipleTiers: flagValue,
})
Expand All @@ -73,13 +89,16 @@ describe('FilesChangedTab', () => {
}

return res(ctx.status(200), ctx.data(mockProTier))
}),
graphql.query('GetRepoSettingsTeam', (req, res, ctx) => {
return res(ctx.status(200), ctx.data(mockRepoSettings(isPrivate)))
})
)
}

describe('user has pro tier', () => {
it('renders files changed table', async () => {
setup({ planValue: 'pro', flagValue: false })
setup({ planValue: TierNames.PRO, flagValue: false })
render(<FilesChangedTab />, { wrapper })

const table = await screen.findByText('FilesChangedTable')
Expand All @@ -88,13 +107,25 @@ describe('FilesChangedTab', () => {
})

describe('user has team tier', () => {
it('renders team files changed table', async () => {
setup({ planValue: 'team', flagValue: true })
describe('repo is private', () => {
it('renders team files changed table', async () => {
setup({ planValue: TierNames.TEAM, flagValue: true, isPrivate: true })

render(<FilesChangedTab />, { wrapper })
render(<FilesChangedTab />, { wrapper })

const table = await screen.findByText('FilesChangedTableTeam')
expect(table).toBeInTheDocument()
const table = await screen.findByText('FilesChangedTableTeam')
expect(table).toBeInTheDocument()
})
})

describe('repo is public', () => {
it('renders files changed table', async () => {
setup({ planValue: TierNames.TEAM, flagValue: false, isPrivate: false })
render(<FilesChangedTab />, { wrapper })

const table = await screen.findByText('FilesChangedTable')
expect(table).toBeInTheDocument()
})
})
})
})
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { lazy, Suspense } from 'react'
import { useParams } from 'react-router-dom'

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

Expand All @@ -21,14 +22,19 @@

function FilesChanged() {
const { provider, owner } = useParams<URLParams>()
const { data: repoSettings } = useRepoSettingsTeam()

Check warning on line 25 in src/pages/CommitDetailPage/subRoute/FilesChangedTab/FilesChangedTab.tsx

View check run for this annotation

Codecov - Staging / codecov/patch

src/pages/CommitDetailPage/subRoute/FilesChangedTab/FilesChangedTab.tsx#L25

Added line #L25 was not covered by tests

Check warning on line 25 in src/pages/CommitDetailPage/subRoute/FilesChangedTab/FilesChangedTab.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/CommitDetailPage/subRoute/FilesChangedTab/FilesChangedTab.tsx#L25

Added line #L25 was not covered by tests

const { multipleTiers } = useFlags({
multipleTiers: false,
})

const { data: tierData } = useTier({ provider, owner })

if (tierData === 'team' && multipleTiers) {
if (
tierData === TierNames.TEAM &&
!!repoSettings?.repository.private &&
multipleTiers

Check warning on line 36 in src/pages/CommitDetailPage/subRoute/FilesChangedTab/FilesChangedTab.tsx

View check run for this annotation

Codecov - Staging / codecov/patch

src/pages/CommitDetailPage/subRoute/FilesChangedTab/FilesChangedTab.tsx#L35-L36

Added lines #L35 - L36 were not covered by tests

Check warning on line 36 in src/pages/CommitDetailPage/subRoute/FilesChangedTab/FilesChangedTab.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/CommitDetailPage/subRoute/FilesChangedTab/FilesChangedTab.tsx#L35-L36

Added lines #L35 - L36 were not covered by tests
) {
return (
<Suspense fallback={<Loader />}>
<FilesChangedTableTeam />
Expand Down
Loading