Skip to content

Commit

Permalink
fix: Only show activation banner for non activated users (#2831)
Browse files Browse the repository at this point in the history
  • Loading branch information
RulaKhaled authored May 2, 2024
1 parent cbfc013 commit c9acd50
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 13 deletions.
38 changes: 33 additions & 5 deletions src/pages/RepoPage/CoverageOnboarding/NewRepoTab.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ jest.mock('./GitHubActions', () => () => 'GitHubActions')
jest.mock('./OtherCI', () => () => 'OtherCI')
jest.mock('./ActivationBanner', () => () => 'ActivationBanner')


const mockCurrentUser = {
me: {
trackingMetadata: {
Expand All @@ -25,11 +24,15 @@ const mockCurrentUser = {
},
}

const mockGetRepo = (noUploadToken = false, hasCommits = false) => ({
const mockGetRepo = (
noUploadToken = false,
hasCommits = false,
isCurrentUserActivated = false
) => ({
owner: {
isCurrentUserPartOfOrg: true,
isAdmin: null,
isCurrentUserActivated: null,
isCurrentUserActivated,
repository: {
__typename: 'Repository',
private: false,
Expand Down Expand Up @@ -95,10 +98,15 @@ afterAll(() => server.close())
interface SetupArgs {
hasCommits?: boolean
noUploadToken?: boolean
isCurrentUserActivated?: boolean
}

describe('NewRepoTab', () => {
function setup({ hasCommits = false, noUploadToken = false }: SetupArgs) {
function setup({
hasCommits = false,
noUploadToken = false,
isCurrentUserActivated = false,
}: SetupArgs) {
const user = userEvent.setup()
const hardRedirect = jest.fn()
mockedUseRedirect.mockImplementation((data) => ({
Expand All @@ -107,7 +115,12 @@ describe('NewRepoTab', () => {

server.use(
graphql.query('GetRepo', (req, res, ctx) =>
res(ctx.status(200), ctx.data(mockGetRepo(noUploadToken, hasCommits)))
res(
ctx.status(200),
ctx.data(
mockGetRepo(noUploadToken, hasCommits, isCurrentUserActivated)
)
)
),
graphql.query('CurrentUser', (req, res, ctx) =>
res(ctx.status(200), ctx.data(mockCurrentUser))
Expand Down Expand Up @@ -267,4 +280,19 @@ describe('NewRepoTab', () => {
})
})
})

describe('user is activated', () => {
it('does not render ActivationBanner', async () => {
setup({
isCurrentUserActivated: true,
})
render(<NewRepoTab />, { wrapper: wrapper() })

await waitFor(() => queryClient.isFetching)
await waitFor(() => !queryClient.isFetching)

const banner = screen.queryByText('ActivationBanner')
expect(banner).not.toBeInTheDocument()
})
})
})
20 changes: 12 additions & 8 deletions src/pages/RepoPage/CoverageOnboarding/NewRepoTab.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import PropTypes from 'prop-types'
import { lazy, Suspense } from 'react'
import { Switch, useParams } from 'react-router-dom'

Expand All @@ -24,7 +23,13 @@ const Loader = () => (
</div>
)

function Content({ provider }: { provider: string }) {
function Content({
provider,
isCurrentUserActivated,
}: {
provider: string
isCurrentUserActivated: boolean
}) {
if (providerToName(provider) !== 'Github') {
return (
<div className="mt-6">
Expand All @@ -44,7 +49,7 @@ function Content({ provider }: { provider: string }) {
{ pageName: 'newOtherCI' },
]}
/>
<ActivationBanner />
{!isCurrentUserActivated ? <ActivationBanner /> : null}
<div className="mt-6">
<Switch>
<SentryRoute path="/:provider/:owner/:repo/new" exact>
Expand All @@ -64,10 +69,6 @@ function Content({ provider }: { provider: string }) {
)
}

Content.propTypes = {
provider: PropTypes.string,
}

interface URLParams {
provider: string
owner: string
Expand All @@ -90,7 +91,10 @@ function NewRepoTab() {
<div className="flex flex-col gap-6">
<div className="flex flex-col gap-4 pt-4 lg:w-3/5">
<IntroBlurb />
<Content provider={provider} />
<Content
provider={provider}
isCurrentUserActivated={data?.isCurrentUserActivated ?? false}
/>
</div>
</div>
)
Expand Down

0 comments on commit c9acd50

Please sign in to comment.