-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Create Team Plan Table for the Files Changed Table on the Commi…
…t Detail Page (#2309) Create new commit fetching hooks for the team plan, as well as creating a new table for files changed tab on the commit detail page for the new team plan. GH codecov/engineering-team#633
- Loading branch information
1 parent
89c1b19
commit e2e90c0
Showing
22 changed files
with
2,435 additions
and
120 deletions.
There are no files selected for viewing
21 changes: 0 additions & 21 deletions
21
src/pages/CommitDetailPage/subRoute/FilesChangedTab/FilesChangedTab.jsx
This file was deleted.
Oops, something went wrong.
17 changes: 0 additions & 17 deletions
17
src/pages/CommitDetailPage/subRoute/FilesChangedTab/FilesChangedTab.spec.jsx
This file was deleted.
Oops, something went wrong.
100 changes: 100 additions & 0 deletions
100
src/pages/CommitDetailPage/subRoute/FilesChangedTab/FilesChangedTab.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query' | ||
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 FilesChangedTab from './FilesChangedTab' | ||
|
||
jest.mock('./FilesChangedTable', () => () => 'FilesChangedTable') | ||
jest.mock('./FilesChangedTableTeam', () => () => 'FilesChangedTableTeam') | ||
|
||
jest.mock('shared/featureFlags') | ||
const mockedUseFlags = useFlags as jest.Mock<{ multipleTiers: boolean }> | ||
|
||
const mockTeamTier = { | ||
owner: { | ||
plan: { | ||
tierName: TierNames.TEAM, | ||
}, | ||
}, | ||
} | ||
|
||
const mockProTier = { | ||
owner: { | ||
plan: { | ||
tierName: TierNames.PRO, | ||
}, | ||
}, | ||
} | ||
|
||
const server = setupServer() | ||
const queryClient = new QueryClient() | ||
|
||
const wrapper: React.FC<React.PropsWithChildren> = ({ children }) => ( | ||
<QueryClientProvider client={queryClient}> | ||
<MemoryRouter initialEntries={['/gh/codecov/test-repo/commit/sha256']}> | ||
<Route path="/:provider/:owner/:repo/commit/:commit">{children}</Route> | ||
</MemoryRouter> | ||
</QueryClientProvider> | ||
) | ||
|
||
beforeAll(() => { | ||
server.listen() | ||
}) | ||
|
||
afterEach(() => { | ||
queryClient.clear() | ||
server.resetHandlers() | ||
}) | ||
|
||
afterAll(() => { | ||
server.close() | ||
}) | ||
|
||
interface SetupArgs { | ||
planValue: 'team' | 'pro' | ||
flagValue: boolean | ||
} | ||
|
||
describe('FilesChangedTab', () => { | ||
function setup({ planValue, flagValue }: SetupArgs) { | ||
mockedUseFlags.mockReturnValue({ | ||
multipleTiers: flagValue, | ||
}) | ||
|
||
server.use( | ||
graphql.query('OwnerTier', (req, res, ctx) => { | ||
if (planValue === 'team') { | ||
return res(ctx.status(200), ctx.data(mockTeamTier)) | ||
} | ||
|
||
return res(ctx.status(200), ctx.data(mockProTier)) | ||
}) | ||
) | ||
} | ||
|
||
describe('user has pro tier', () => { | ||
it('renders files changed table', async () => { | ||
setup({ planValue: 'pro', flagValue: false }) | ||
render(<FilesChangedTab />, { wrapper }) | ||
|
||
const table = await screen.findByText('FilesChangedTable') | ||
expect(table).toBeInTheDocument() | ||
}) | ||
}) | ||
|
||
describe('user has team tier', () => { | ||
it('renders team files changed table', async () => { | ||
setup({ planValue: 'team', flagValue: true }) | ||
|
||
render(<FilesChangedTab />, { wrapper }) | ||
|
||
const table = await screen.findByText('FilesChangedTableTeam') | ||
expect(table).toBeInTheDocument() | ||
}) | ||
}) | ||
}) |
46 changes: 46 additions & 0 deletions
46
src/pages/CommitDetailPage/subRoute/FilesChangedTab/FilesChangedTab.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { lazy, Suspense } from 'react' | ||
import { useParams } from 'react-router-dom' | ||
|
||
import { useTier } from 'services/tier' | ||
import { useFlags } from 'shared/featureFlags' | ||
import Spinner from 'ui/Spinner' | ||
|
||
const FilesChangedTable = lazy(() => import('./FilesChangedTable')) | ||
const FilesChangedTableTeam = lazy(() => import('./FilesChangedTableTeam')) | ||
|
||
const Loader = () => ( | ||
<div className="flex flex-1 justify-center p-4"> | ||
<Spinner /> | ||
</div> | ||
) | ||
|
||
interface URLParams { | ||
provider: string | ||
owner: string | ||
} | ||
|
||
function FilesChanged() { | ||
const { provider, owner } = useParams<URLParams>() | ||
|
||
const { multipleTiers } = useFlags({ | ||
multipleTiers: false, | ||
}) | ||
|
||
const { data: tierData } = useTier({ provider, owner }) | ||
|
||
if (tierData === 'team' && multipleTiers) { | ||
return ( | ||
<Suspense fallback={<Loader />}> | ||
<FilesChangedTableTeam /> | ||
</Suspense> | ||
) | ||
} | ||
|
||
return ( | ||
<Suspense fallback={<Loader />}> | ||
<FilesChangedTable /> | ||
</Suspense> | ||
) | ||
} | ||
|
||
export default FilesChanged |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.