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: Update Repo Page Pulls Tab for Team Plan #2358

Merged
merged 15 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
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,84 @@ import userEvent from '@testing-library/user-event'
import { graphql } from 'msw'
import { setupServer } from 'msw/node'

import { TierNames } from 'services/tier'

import PullsTab from './PullsTab'

import { repoPageRender, screen } from '../repo-jest-setup'

jest.mock('./PullsTable/PullsTable', () => () => 'PullsTable')
jest.mock('./PullsTable', () => () => 'PullsTable')
jest.mock('./PullsTableTeam', () => () => 'PullsTableTeam')

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

const server = setupServer()

beforeAll(() => {
server.listen({ onUnhandledRequest: 'warn' })
})

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

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

interface SetupArgs {
tierValue?: 'pro' | 'team'
isPrivate?: boolean
}

describe('Pulls Tab', () => {
function setup() {
function setup({ tierValue = 'pro', isPrivate = false }: SetupArgs) {
const user = userEvent.setup()

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

return res(
ctx.status(200),
ctx.data({
owner: { plan: { tierName: 'pro' } },
})
)
}),
graphql.query('GetRepoSettingsTeam', (req, res, ctx) => {
return res(ctx.status(200), ctx.data(mockRepoSettings(isPrivate)))
})
)

return { user }
}

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

it('renders select by updatestamp label', () => {
repoPageRender({
Expand Down Expand Up @@ -77,9 +122,52 @@ describe('Pulls Tab', () => {
})
})

describe('rendering table', () => {
describe('on non-team tier', () => {
it('renders PullsTable component', async () => {
setup({})
repoPageRender({
initialEntries: ['/gh/codecov/gazebo/pulls'],
renderPulls: () => <PullsTab />,
})

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

describe('on team tier', () => {
describe('repo is public', () => {
it('renders PullsTable component', async () => {
setup({ tierValue: TierNames.TEAM, isPrivate: false })
repoPageRender({
initialEntries: ['/gh/codecov/gazebo/pulls'],
renderPulls: () => <PullsTab />,
})

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

describe('repo is private', () => {
it('renders PullsTableTeam component', async () => {
setup({ tierValue: TierNames.TEAM, isPrivate: true })
repoPageRender({
initialEntries: ['/gh/codecov/gazebo/pulls'],
renderPulls: () => <PullsTab />,
})

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

describe('view by state', () => {
it('renders all options', async () => {
const { user } = setup()
const { user } = setup({})
repoPageRender({
initialEntries: ['/gh/codecov/gazebo/pulls'],
renderPulls: () => <PullsTab />,
Expand All @@ -101,7 +189,7 @@ describe('Pulls Tab', () => {

describe('order by updatestamp', () => {
it('renders all options', async () => {
const { user } = setup()
const { user } = setup({})
repoPageRender({
initialEntries: ['/gh/codecov/gazebo/pulls'],
renderPulls: () => <PullsTab />,
Expand All @@ -115,9 +203,9 @@ describe('Pulls Tab', () => {
})
})

describe('order by Oldest', () => {
describe('order by oldest', () => {
it('renders the selected option', async () => {
const { user } = setup()
const { user } = setup({})
repoPageRender({
initialEntries: ['/gh/codecov/gazebo/pulls'],
renderPulls: () => <PullsTab />,
Expand All @@ -137,9 +225,9 @@ describe('Pulls Tab', () => {
})
})

describe('view by Merged', () => {
describe('view by merged', () => {
it('renders the number of selected options', async () => {
const { user } = setup()
const { user } = setup({})
repoPageRender({
initialEntries: ['/gh/codecov/gazebo/pulls'],
renderPulls: () => <PullsTab />,
Expand All @@ -149,7 +237,10 @@ describe('Pulls Tab', () => {
await user.click(select)

const state = screen.getAllByRole('option')[2]
await user.click(state)

if (state) {
await user.click(state)
}

const itemSelected = await screen.findByText(/1 selected/)
expect(itemSelected).toBeInTheDocument()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { lazy, Suspense, useLayoutEffect, useState } from 'react'
import { useParams } from 'react-router-dom'

import { useLocationParams } from 'services/navigation'
import { useRepoSettingsTeam } from 'services/repo'
import { TierNames, useTier } from 'services/tier'
import MultiSelect from 'ui/MultiSelect'
import Select from 'ui/Select'
import Spinner from 'ui/Spinner'
Expand All @@ -17,21 +20,29 @@
import { useSetCrumbs } from '../context'

const PullsTable = lazy(() => import('./PullsTable'))
const PullsTableTeam = lazy(() => import('./PullsTableTeam'))

Check warning on line 23 in src/pages/RepoPage/PullsTab/PullsTab.tsx

View check run for this annotation

Codecov - Staging / codecov/patch

src/pages/RepoPage/PullsTab/PullsTab.tsx#L23

Added line #L23 was not covered by tests

Check warning on line 23 in src/pages/RepoPage/PullsTab/PullsTab.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/RepoPage/PullsTab/PullsTab.tsx#L23

Added line #L23 was not covered by tests

const Loader = (
const Loader = () => (

Check warning on line 25 in src/pages/RepoPage/PullsTab/PullsTab.tsx

View check run for this annotation

Codecov - Staging / codecov/patch

src/pages/RepoPage/PullsTab/PullsTab.tsx#L25

Added line #L25 was not covered by tests

Check warning on line 25 in src/pages/RepoPage/PullsTab/PullsTab.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/RepoPage/PullsTab/PullsTab.tsx#L25

Added line #L25 was not covered by tests
<div className="flex flex-1 justify-center">
<Spinner size={60} />
<Spinner />
</div>
)

type Order = keyof typeof orderNames
type SelectedStatesNames = Array<keyof typeof stateNames>
type SelectedStatesEnum = Array<keyof typeof stateEnum>

const defaultParams = {
order: orderingEnum.Newest.order,
prStates: [],
}

function useControlParams() {
const { params, updateParams } = useLocationParams(defaultParams)
const { order, prStates } = params
const { order, prStates } = params as {

Check warning on line 42 in src/pages/RepoPage/PullsTab/PullsTab.tsx

View check run for this annotation

Codecov - Staging / codecov/patch

src/pages/RepoPage/PullsTab/PullsTab.tsx#L42

Added line #L42 was not covered by tests

Check warning on line 42 in src/pages/RepoPage/PullsTab/PullsTab.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/RepoPage/PullsTab/PullsTab.tsx#L42

Added line #L42 was not covered by tests
order: Order
prStates: SelectedStatesNames
}
const paramOrderName = orderNames[order]

const paramStatesNames = prStates.map((filter) => {
Expand All @@ -51,9 +62,18 @@
}
}

interface URLParams {
provider: string
owner: string
}

function PullsTab() {
const { provider, owner } = useParams<URLParams>()

Check warning on line 71 in src/pages/RepoPage/PullsTab/PullsTab.tsx

View check run for this annotation

Codecov - Staging / codecov/patch

src/pages/RepoPage/PullsTab/PullsTab.tsx#L71

Added line #L71 was not covered by tests

Check warning on line 71 in src/pages/RepoPage/PullsTab/PullsTab.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/RepoPage/PullsTab/PullsTab.tsx#L71

Added line #L71 was not covered by tests
const setCrumbs = useSetCrumbs()

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

Check warning on line 75 in src/pages/RepoPage/PullsTab/PullsTab.tsx

View check run for this annotation

Codecov - Staging / codecov/patch

src/pages/RepoPage/PullsTab/PullsTab.tsx#L74-L75

Added lines #L74 - L75 were not covered by tests

Check warning on line 75 in src/pages/RepoPage/PullsTab/PullsTab.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/RepoPage/PullsTab/PullsTab.tsx#L74-L75

Added lines #L74 - L75 were not covered by tests

const {
updateParams,
selectedOrder,
Expand All @@ -66,13 +86,13 @@
setCrumbs()
}, [setCrumbs])

const handleOrderChange = (selectedOrder) => {
const handleOrderChange = (selectedOrder: keyof typeof orderingEnum) => {

Check warning on line 89 in src/pages/RepoPage/PullsTab/PullsTab.tsx

View check run for this annotation

Codecov - Staging / codecov/patch

src/pages/RepoPage/PullsTab/PullsTab.tsx#L89

Added line #L89 was not covered by tests

Check warning on line 89 in src/pages/RepoPage/PullsTab/PullsTab.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/RepoPage/PullsTab/PullsTab.tsx#L89

Added line #L89 was not covered by tests
const { order } = orderingEnum[selectedOrder]
setSelectedOrder(selectedOrder)
updateParams({ order })
}

const handleStatesChange = (selectedStates) => {
const handleStatesChange = (selectedStates: SelectedStatesEnum) => {

Check warning on line 95 in src/pages/RepoPage/PullsTab/PullsTab.tsx

View check run for this annotation

Codecov - Staging / codecov/patch

src/pages/RepoPage/PullsTab/PullsTab.tsx#L95

Added line #L95 was not covered by tests

Check warning on line 95 in src/pages/RepoPage/PullsTab/PullsTab.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/RepoPage/PullsTab/PullsTab.tsx#L95

Added line #L95 was not covered by tests
const prStates = selectedStates.map((filter) => {
const { state } = stateEnum[filter]
return state
Expand All @@ -81,13 +101,17 @@
updateParams({ prStates })
}

const showTeamTable =
repoSettingsTeam?.repository?.private && tierData === TierNames.TEAM

return (
<div className="flex flex-1 flex-col gap-4">
<div className="flex flex-row gap-3">
<div className="flex items-center justify-center gap-3">
<label className="text-sm font-semibold">View:</label>
<div>
<MultiSelect
// @ts-expect-error - need to play around with forward refs and types
dataMarketing="pulls-filter-by-state"
ariaName="Filter by state"
value={selectedStates}
Expand All @@ -101,6 +125,7 @@
<label className="text-sm font-semibold ">Sort by:</label>
<div>
<Select
// @ts-expect-error - need to play around with forward refs and types
dataMarketing="pulls-sort-by-selector"
ariaName="Sort order"
value={selectedOrder}
Expand All @@ -110,8 +135,8 @@
</div>
</div>
</div>
<Suspense fallback={Loader}>
<PullsTable />
<Suspense fallback={<Loader />}>
{showTeamTable ? <PullsTableTeam /> : <PullsTable />}
</Suspense>
</div>
)
Expand Down
55 changes: 0 additions & 55 deletions src/pages/RepoPage/PullsTab/PullsTable/Coverage/Coverage.jsx

This file was deleted.

Loading
Loading