Skip to content
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
22 changes: 14 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"react-dom": "^18.3.1",
"react-hook-form": "^7.43.9",
"react-hot-toast": "^2.4.1",
"react-intersection-observer": "^9.4.1",
"react-intersection-observer": "^9.10.3",
"react-modal": "^3.14.4",
"react-router-dom": "^5.2.1",
"react-router-dom-v5-compat": "^6.15.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import isArray from 'lodash/isArray'
import isEmpty from 'lodash/isEmpty'

import { Commit } from 'services/commits/useCommits'
import {
Commit,
COMMIT_STATUS_COMPLETED,
COMMIT_STATUS_ERROR,
COMMIT_STATUS_PENDING,
} from 'services/commits/useCommits'
import { formatSizeToString } from 'shared/utils/bundleAnalysis'
import TotalsNumber from 'ui/TotalsNumber'

Expand Down Expand Up @@ -35,12 +40,12 @@ export const createCommitsTableData = ({ pages }: CommitsTableData) => {

return commits.filter(Boolean).map((commit) => {
let patch = <p>-</p>
if (commit?.coverageStatus === 'ERROR') {
if (commit?.coverageStatus === COMMIT_STATUS_ERROR) {
patch = <ErroredUpload />
} else if (commit?.coverageStatus === 'PENDING') {
} else if (commit?.coverageStatus === COMMIT_STATUS_PENDING) {
patch = <PendingUpload />
} else if (
commit?.coverageStatus === 'COMPLETED' &&
commit?.coverageStatus === COMMIT_STATUS_COMPLETED &&
commit?.compareWithParent?.__typename === 'Comparison'
) {
const percent =
Expand All @@ -57,12 +62,12 @@ export const createCommitsTableData = ({ pages }: CommitsTableData) => {
}

let bundleAnalysis = <p>-</p>
if (commit?.bundleStatus === 'ERROR') {
if (commit?.bundleStatus === COMMIT_STATUS_ERROR) {
bundleAnalysis = <ErroredUpload />
} else if (commit?.bundleStatus === 'PENDING') {
} else if (commit?.bundleStatus === COMMIT_STATUS_PENDING) {
bundleAnalysis = <PendingUpload />
} else if (
commit?.bundleStatus === 'COMPLETED' &&
commit?.bundleStatus === COMMIT_STATUS_COMPLETED &&
commit?.bundleAnalysisCompareWithParent?.__typename ===
'BundleAnalysisComparison'
) {
Expand Down
7 changes: 2 additions & 5 deletions src/pages/RepoPage/CommitsTab/CommitsTable/CommitsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ import { useEffect, useMemo } from 'react'
import { useInView } from 'react-intersection-observer'
import { useParams } from 'react-router-dom'

import {
type CommitStatusesEnum,
useCommits,
} from 'services/commits/useCommits'
import { CommitStatuses, useCommits } from 'services/commits/useCommits'
import { useRepoOverview } from 'services/repo'
import Spinner from 'ui/Spinner'

Expand Down Expand Up @@ -69,7 +66,7 @@ interface URLParams {
interface CommitsTableProps {
branch: string
search: string
coverageStatus: Array<CommitStatusesEnum>
coverageStatus: Array<CommitStatuses>
}

const CommitsTable: React.FC<CommitsTableProps> = ({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import isArray from 'lodash/isArray'
import isEmpty from 'lodash/isEmpty'

import { Commit } from 'services/commits/useCommits'
import {
Commit,
COMMIT_STATUS_COMPLETED,
COMMIT_STATUS_ERROR,
COMMIT_STATUS_PENDING,
} from 'services/commits/useCommits'
import { formatSizeToString } from 'shared/utils/bundleAnalysis'
import TotalsNumber from 'ui/TotalsNumber'

Expand Down Expand Up @@ -35,12 +40,12 @@ export const createCommitsTableData = ({ pages }: CommitsTableData) => {

return commits.filter(Boolean).map((commit) => {
let patch = <p>-</p>
if (commit?.coverageStatus === 'ERROR') {
if (commit?.coverageStatus === COMMIT_STATUS_ERROR) {
patch = <ErroredUpload />
} else if (commit?.coverageStatus === 'PENDING') {
} else if (commit?.coverageStatus === COMMIT_STATUS_PENDING) {
patch = <PendingUpload />
} else if (
commit?.coverageStatus === 'COMPLETED' &&
commit?.coverageStatus === COMMIT_STATUS_COMPLETED &&
commit?.compareWithParent?.__typename === 'Comparison'
) {
const percent =
Expand All @@ -57,12 +62,12 @@ export const createCommitsTableData = ({ pages }: CommitsTableData) => {
}

let bundleAnalysis = <p>-</p>
if (commit?.bundleStatus === 'ERROR') {
if (commit?.bundleStatus === COMMIT_STATUS_ERROR) {
bundleAnalysis = <ErroredUpload />
} else if (commit?.bundleStatus === 'PENDING') {
} else if (commit?.bundleStatus === COMMIT_STATUS_PENDING) {
bundleAnalysis = <PendingUpload />
} else if (
commit?.bundleStatus === 'COMPLETED' &&
commit?.bundleStatus === COMMIT_STATUS_COMPLETED &&
commit?.bundleAnalysisCompareWithParent?.__typename ===
'BundleAnalysisComparison'
) {
Expand Down
127 changes: 16 additions & 111 deletions src/pages/RepoPage/PullsTab/PullsTab.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,89 +1,21 @@
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')
jest.mock('./PullsTableTeam', () => () => 'PullsTableTeam')

const mockRepoSettings = (isPrivate = false) => ({
owner: {
repository: {
__typename: 'Repository',
activated: true,
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({ tierValue = 'pro', isPrivate = false }: SetupArgs) {
function setup() {
const user = userEvent.setup()

server.use(
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('rendering table controls', () => {
beforeEach(() => setup({}))

it('renders select by updatestamp label', () => {
setup()
repoPageRender({
initialEntries: ['/gh/codecov/gazebo/pulls'],
renderPulls: () => <PullsTab />,
Expand All @@ -94,6 +26,7 @@ describe('Pulls Tab', () => {
})

it('renders view by state label', () => {
setup()
repoPageRender({
initialEntries: ['/gh/codecov/gazebo/pulls'],
renderPulls: () => <PullsTab />,
Expand All @@ -104,6 +37,7 @@ describe('Pulls Tab', () => {
})

it('renders default of select by updatestamp', () => {
setup()
repoPageRender({
initialEntries: ['/gh/codecov/gazebo/pulls'],
renderPulls: () => <PullsTab />,
Expand All @@ -114,6 +48,7 @@ describe('Pulls Tab', () => {
})

it('renders default of select by state', () => {
setup()
repoPageRender({
initialEntries: ['/gh/codecov/gazebo/pulls'],
renderPulls: () => <PullsTab />,
Expand All @@ -125,51 +60,21 @@ 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()
})
it('renders PullsTable component', async () => {
setup()
repoPageRender({
initialEntries: ['/gh/codecov/gazebo/pulls'],
renderPulls: () => <PullsTab />,
})

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()
})
})
const table = await screen.findByText('PullsTable')
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 @@ -191,7 +96,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 @@ -207,7 +112,7 @@ describe('Pulls Tab', () => {

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 @@ -229,7 +134,7 @@ describe('Pulls Tab', () => {

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 Down
Loading