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

616 add patch setction pr page team tier #2337

Merged
merged 5 commits into from
Oct 23, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 14 additions & 62 deletions src/pages/PullRequestPage/Header/Header.jsx
Original file line number Diff line number Diff line change
@@ -1,71 +1,23 @@
import cs from 'classnames'
import capitalize from 'lodash/capitalize'
import { useParams } from 'react-router-dom'

import { formatTimeToNow } from 'shared/utils/dates'
import { getProviderPullURL } from 'shared/utils/provider'
import A from 'ui/A'
import CIStatusLabel from 'ui/CIStatus'
import Icon from 'ui/Icon'
import { TierNames, useTier } from 'services/tier'
import { useFlags } from 'shared/featureFlags'

import { usePullHeadData } from './hooks'
import PendoLink from './PendoLink'

const pullStateToColor = {
OPEN: 'bg-ds-primary-green',
CLOSED: 'bg-ds-primary-red',
MERGED: 'bg-ds-primary-purple',
}
import HeaderDefault from './HeaderDefault'
import HeaderTeam from './HeaderTeam'

function Header() {
const { provider, owner, repo, pullId } = useParams()
const { data } = usePullHeadData({ provider, owner, repo, pullId })
const { provider, owner } = useParams()
const { data: tierData } = useTier({ provider, owner })
const { multipleTiers } = useFlags({

Check warning on line 12 in src/pages/PullRequestPage/Header/Header.jsx

View check run for this annotation

Codecov - Staging / codecov/patch

src/pages/PullRequestPage/Header/Header.jsx#L10-L12

Added lines #L10 - L12 were not covered by tests

Check warning on line 12 in src/pages/PullRequestPage/Header/Header.jsx

View check run for this annotation

Codecov - QA / codecov/patch

src/pages/PullRequestPage/Header/Header.jsx#L10-L12

Added lines #L10 - L12 were not covered by tests

Check warning on line 12 in src/pages/PullRequestPage/Header/Header.jsx

View check run for this annotation

Codecov Public QA / codecov/patch

src/pages/PullRequestPage/Header/Header.jsx#L10-L12

Added lines #L10 - L12 were not covered by tests

Check warning on line 12 in src/pages/PullRequestPage/Header/Header.jsx

View check run for this annotation

Codecov / codecov/patch

src/pages/PullRequestPage/Header/Header.jsx#L10-L12

Added lines #L10 - L12 were not covered by tests
multipleTiers: false,
})

if (multipleTiers && tierData === TierNames.TEAM) {
return <HeaderTeam />

Check warning on line 17 in src/pages/PullRequestPage/Header/Header.jsx

View check run for this annotation

Codecov - Staging / codecov/patch

src/pages/PullRequestPage/Header/Header.jsx#L17

Added line #L17 was not covered by tests

Check warning on line 17 in src/pages/PullRequestPage/Header/Header.jsx

View check run for this annotation

Codecov - QA / codecov/patch

src/pages/PullRequestPage/Header/Header.jsx#L17

Added line #L17 was not covered by tests

Check warning on line 17 in src/pages/PullRequestPage/Header/Header.jsx

View check run for this annotation

Codecov Public QA / codecov/patch

src/pages/PullRequestPage/Header/Header.jsx#L17

Added line #L17 was not covered by tests

Check warning on line 17 in src/pages/PullRequestPage/Header/Header.jsx

View check run for this annotation

Codecov / codecov/patch

src/pages/PullRequestPage/Header/Header.jsx#L17

Added line #L17 was not covered by tests
}

return (
<div className="flex flex-col justify-between gap-2 border-b border-ds-gray-secondary pb-2 text-xs md:flex-row">
<div>
<h1 className="flex items-center gap-2 text-lg font-semibold">
{data?.pull?.title}
<span
className={cs(
'text-white font-bold px-3 py-0.5 text-xs rounded',
pullStateToColor[data?.pull?.state]
)}
>
{capitalize(data?.pull?.state)}
</span>
</h1>
<p className="flex items-center gap-2">
<span>
{data?.pull?.updatestamp &&
formatTimeToNow(data?.pull?.updatestamp)}{' '}
<span className="bold">{data?.pull?.author?.username}</span>{' '}
authored{' '}
{data?.pull?.pullId && (
<A
href={getProviderPullURL({
provider,
owner,
repo,
pullId: data?.pull?.pullId,
})}
hook="provider-pr-link"
isExternal={true}
>
#{data?.pull?.pullId}
</A>
)}
</span>
<CIStatusLabel ciPassed={data?.pull?.head?.ciPassed} />
<span className="flex items-center">
<Icon name="branch" variant="developer" size="sm" />
{data?.pull?.head?.branchName}
</span>
</p>
</div>
<PendoLink />
</div>
)
return <HeaderDefault />

Check warning on line 20 in src/pages/PullRequestPage/Header/Header.jsx

View check run for this annotation

Codecov - Staging / codecov/patch

src/pages/PullRequestPage/Header/Header.jsx#L20

Added line #L20 was not covered by tests

Check warning on line 20 in src/pages/PullRequestPage/Header/Header.jsx

View check run for this annotation

Codecov - QA / codecov/patch

src/pages/PullRequestPage/Header/Header.jsx#L20

Added line #L20 was not covered by tests

Check warning on line 20 in src/pages/PullRequestPage/Header/Header.jsx

View check run for this annotation

Codecov Public QA / codecov/patch

src/pages/PullRequestPage/Header/Header.jsx#L20

Added line #L20 was not covered by tests

Check warning on line 20 in src/pages/PullRequestPage/Header/Header.jsx

View check run for this annotation

Codecov / codecov/patch

src/pages/PullRequestPage/Header/Header.jsx#L20

Added line #L20 was not covered by tests
}

export default Header
83 changes: 44 additions & 39 deletions src/pages/PullRequestPage/Header/Header.spec.jsx
Original file line number Diff line number Diff line change
@@ -1,34 +1,18 @@
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { render, screen, waitFor } from '@testing-library/react'
import { render, screen } from '@testing-library/react'
import { graphql } from 'msw'
import { setupServer } from 'msw/node'
import { MemoryRouter, Route } from 'react-router-dom'

import { TierNames } from 'services/tier'
import { useFlags } from 'shared/featureFlags'

import Header from './Header'

jest.mock('./HeaderDefault', () => () => 'Default Header')
jest.mock('./HeaderTeam', () => () => 'Team Header')
jest.mock('shared/featureFlags')

const mockPullData = {
owner: {
repository: {
__typename: 'Repository',
pull: {
pullId: 1,
title: 'Cool Pull Request',
state: 'OPEN',
author: {
username: 'cool-user',
},
head: {
branchName: 'cool-branch',
ciPassed: true,
},
updatestamp: '2020-01-01T12:00:00.000000',
},
},
},
}

const queryClient = new QueryClient({
defaultOptions: { queries: { retry: false } },
})
Expand All @@ -55,35 +39,56 @@ afterAll(() => {
})

describe('Header', () => {
function setup() {
function setup({ multipleTiers = false } = { multipleTiers: false }) {
useFlags.mockReturnValue({
multipleTiers,
})

server.use(
graphql.query('PullHeadData', (req, res, ctx) =>
res(ctx.status(200), ctx.data(mockPullData))
)
graphql.query('OwnerTier', (req, res, ctx) => {
if (multipleTiers) {
return res(
ctx.status(200),
ctx.data({ owner: { plan: { tierName: TierNames.TEAM } } })
)
}
return res(
ctx.status(200),
ctx.data({ owner: { plan: { tierName: TierNames.PRO } } })
)
})
)
}

describe('when rendered', () => {
describe('when rendered and customer is not team tier', () => {
beforeEach(() => {
setup()
setup({ multipleTiers: false })
})

it('renders the pr overview', async () => {
it('renders the default header component', async () => {
render(<Header />, { wrapper })

await waitFor(() => queryClient.isFetching)
await waitFor(() => !queryClient.isFetching)
const defaultHeader = await screen.findByText(/Default Header/)
expect(defaultHeader).toBeInTheDocument()

const heading = await screen.findByRole('heading', {
name: /Cool Pull Request/,
})
expect(heading).toBeInTheDocument()
const teamHeader = screen.queryByText(/Team Header/)
expect(teamHeader).not.toBeInTheDocument()
})
})

describe('when rendered and customer has team tier', () => {
beforeEach(() => {
setup({ multipleTiers: true })
})

it('renders the team header component', async () => {
render(<Header />, { wrapper })

const open = await screen.findByText(/open/i)
expect(open).toBeInTheDocument()
const teamHeader = await screen.findByText(/Team Header/)
expect(teamHeader).toBeInTheDocument()

const prNumber = await screen.findByText(/#1/i)
expect(prNumber).toBeInTheDocument()
const defaultHeader = screen.queryByText(/Default Header/)
expect(defaultHeader).not.toBeInTheDocument()
})
})
})
66 changes: 66 additions & 0 deletions src/pages/PullRequestPage/Header/HeaderDefault/HeaderDefault.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import cs from 'classnames'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No new logic here, straight up copy-paste from what previously was Header

import capitalize from 'lodash/capitalize'
import { useParams } from 'react-router-dom'

import { formatTimeToNow } from 'shared/utils/dates'
import { getProviderPullURL } from 'shared/utils/provider'
import A from 'ui/A'
import CIStatusLabel from 'ui/CIStatus'
import Icon from 'ui/Icon'

import { usePullHeadData } from './hooks'

import { pullStateToColor } from '../constants'
import PendoLink from '../PendoLink'

function HeaderDefault() {
const { provider, owner, repo, pullId } = useParams()
const { data } = usePullHeadData({ provider, owner, repo, pullId })

Check warning on line 18 in src/pages/PullRequestPage/Header/HeaderDefault/HeaderDefault.jsx

View check run for this annotation

Codecov - Staging / codecov/patch

src/pages/PullRequestPage/Header/HeaderDefault/HeaderDefault.jsx#L16-L18

Added lines #L16 - L18 were not covered by tests

Check warning on line 18 in src/pages/PullRequestPage/Header/HeaderDefault/HeaderDefault.jsx

View check run for this annotation

Codecov - QA / codecov/patch

src/pages/PullRequestPage/Header/HeaderDefault/HeaderDefault.jsx#L16-L18

Added lines #L16 - L18 were not covered by tests

Check warning on line 18 in src/pages/PullRequestPage/Header/HeaderDefault/HeaderDefault.jsx

View check run for this annotation

Codecov Public QA / codecov/patch

src/pages/PullRequestPage/Header/HeaderDefault/HeaderDefault.jsx#L16-L18

Added lines #L16 - L18 were not covered by tests

Check warning on line 18 in src/pages/PullRequestPage/Header/HeaderDefault/HeaderDefault.jsx

View check run for this annotation

Codecov / codecov/patch

src/pages/PullRequestPage/Header/HeaderDefault/HeaderDefault.jsx#L16-L18

Added lines #L16 - L18 were not covered by tests

const pull = data?.pull

Check warning on line 20 in src/pages/PullRequestPage/Header/HeaderDefault/HeaderDefault.jsx

View check run for this annotation

Codecov - Staging / codecov/patch

src/pages/PullRequestPage/Header/HeaderDefault/HeaderDefault.jsx#L20

Added line #L20 was not covered by tests

Check warning on line 20 in src/pages/PullRequestPage/Header/HeaderDefault/HeaderDefault.jsx

View check run for this annotation

Codecov - QA / codecov/patch

src/pages/PullRequestPage/Header/HeaderDefault/HeaderDefault.jsx#L20

Added line #L20 was not covered by tests

Check warning on line 20 in src/pages/PullRequestPage/Header/HeaderDefault/HeaderDefault.jsx

View check run for this annotation

Codecov Public QA / codecov/patch

src/pages/PullRequestPage/Header/HeaderDefault/HeaderDefault.jsx#L20

Added line #L20 was not covered by tests

Check warning on line 20 in src/pages/PullRequestPage/Header/HeaderDefault/HeaderDefault.jsx

View check run for this annotation

Codecov / codecov/patch

src/pages/PullRequestPage/Header/HeaderDefault/HeaderDefault.jsx#L20

Added line #L20 was not covered by tests

return (

Check warning on line 22 in src/pages/PullRequestPage/Header/HeaderDefault/HeaderDefault.jsx

View check run for this annotation

Codecov - Staging / codecov/patch

src/pages/PullRequestPage/Header/HeaderDefault/HeaderDefault.jsx#L22

Added line #L22 was not covered by tests

Check warning on line 22 in src/pages/PullRequestPage/Header/HeaderDefault/HeaderDefault.jsx

View check run for this annotation

Codecov - QA / codecov/patch

src/pages/PullRequestPage/Header/HeaderDefault/HeaderDefault.jsx#L22

Added line #L22 was not covered by tests

Check warning on line 22 in src/pages/PullRequestPage/Header/HeaderDefault/HeaderDefault.jsx

View check run for this annotation

Codecov Public QA / codecov/patch

src/pages/PullRequestPage/Header/HeaderDefault/HeaderDefault.jsx#L22

Added line #L22 was not covered by tests

Check warning on line 22 in src/pages/PullRequestPage/Header/HeaderDefault/HeaderDefault.jsx

View check run for this annotation

Codecov / codecov/patch

src/pages/PullRequestPage/Header/HeaderDefault/HeaderDefault.jsx#L22

Added line #L22 was not covered by tests
<div className="flex flex-col justify-between gap-2 border-b border-ds-gray-secondary pb-2 text-xs md:flex-row">
<div>
<h1 className="flex items-center gap-2 text-lg font-semibold">
{pull?.title}
<span
className={cs(
'text-white font-bold px-3 py-0.5 text-xs rounded',
pullStateToColor[pull?.state]
)}
>
{capitalize(pull?.state)}
</span>
</h1>
<p className="flex items-center gap-2">
<span>
{pull?.updatestamp && formatTimeToNow(pull?.updatestamp)}{' '}
<span className="bold">{pull?.author?.username}</span> authored{' '}
{pull?.pullId && (
<A

Check warning on line 41 in src/pages/PullRequestPage/Header/HeaderDefault/HeaderDefault.jsx

View check run for this annotation

Codecov - Staging / codecov/patch

src/pages/PullRequestPage/Header/HeaderDefault/HeaderDefault.jsx#L41

Added line #L41 was not covered by tests

Check warning on line 41 in src/pages/PullRequestPage/Header/HeaderDefault/HeaderDefault.jsx

View check run for this annotation

Codecov - QA / codecov/patch

src/pages/PullRequestPage/Header/HeaderDefault/HeaderDefault.jsx#L41

Added line #L41 was not covered by tests

Check warning on line 41 in src/pages/PullRequestPage/Header/HeaderDefault/HeaderDefault.jsx

View check run for this annotation

Codecov Public QA / codecov/patch

src/pages/PullRequestPage/Header/HeaderDefault/HeaderDefault.jsx#L41

Added line #L41 was not covered by tests

Check warning on line 41 in src/pages/PullRequestPage/Header/HeaderDefault/HeaderDefault.jsx

View check run for this annotation

Codecov / codecov/patch

src/pages/PullRequestPage/Header/HeaderDefault/HeaderDefault.jsx#L41

Added line #L41 was not covered by tests
href={getProviderPullURL({
provider,
owner,
repo,
pullId: pull?.pullId,
})}
hook="provider-pr-link"
isExternal={true}
>
#{pull?.pullId}
</A>
)}
</span>
<CIStatusLabel ciPassed={pull?.head?.ciPassed} />
<span className="flex items-center">
<Icon name="branch" variant="developer" size="sm" />
{pull?.head?.branchName}
</span>
</p>
</div>
<PendoLink />
</div>
)
}
export default HeaderDefault
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No new logic here, straight up copy-paste from what previously was Header.spec

import { render, screen, waitFor } from '@testing-library/react'
import { graphql } from 'msw'
import { setupServer } from 'msw/node'
import { MemoryRouter, Route } from 'react-router-dom'

import Header from './HeaderDefault'

const mockPullData = {
owner: {
repository: {
__typename: 'Repository',
pull: {
pullId: 1,
title: 'Cool Pull Request',
state: 'OPEN',
author: {
username: 'cool-user',
},
head: {
branchName: 'cool-branch',
ciPassed: true,
},
updatestamp: '2020-01-01T12:00:00.000000',
},
},
},
}

const queryClient = new QueryClient({
defaultOptions: { queries: { retry: false } },
})
const server = setupServer()
const wrapper = ({ children }) => (
<QueryClientProvider client={queryClient}>
<MemoryRouter initialEntries={['/gh/test-org/test-repo/pull/12']}>
<Route path="/:provider/:owner/:repo/pull/:pullId">{children}</Route>
</MemoryRouter>
</QueryClientProvider>
)

beforeAll(() => {
server.listen()
})

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

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

describe('Header', () => {
function setup() {
server.use(
graphql.query('PullHeadData', (req, res, ctx) =>
res(ctx.status(200), ctx.data(mockPullData))
)
)
}

describe('when rendered', () => {
beforeEach(() => {
setup()
})

it('renders the pr overview', async () => {
render(<Header />, { wrapper })

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

const heading = await screen.findByRole('heading', {
name: /Cool Pull Request/,
})
expect(heading).toBeInTheDocument()

const open = await screen.findByText(/open/i)
expect(open).toBeInTheDocument()

const prNumber = await screen.findByText(/#1/i)
expect(prNumber).toBeInTheDocument()
})
})
})
1 change: 1 addition & 0 deletions src/pages/PullRequestPage/Header/HeaderDefault/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './HeaderDefault'
Loading
Loading