-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into user_onboard_back_cancel_btns
- Loading branch information
Showing
72 changed files
with
1,923 additions
and
625 deletions.
There are no files selected for viewing
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
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
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
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
86 changes: 86 additions & 0 deletions
86
src/layouts/Header/components/AdminLink/AdminLink.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,86 @@ | ||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query' | ||
import { render, screen } from '@testing-library/react' | ||
import { rest } from 'msw' | ||
import { setupServer } from 'msw/node' | ||
import { MemoryRouter, Route } from 'react-router-dom' | ||
|
||
import AdminLink from './AdminLink' | ||
|
||
const wrapper: ({ | ||
initialEntries, | ||
}: { | ||
initialEntries?: string | ||
}) => React.FC<React.PropsWithChildren> = | ||
({ initialEntries = '/gh' }) => | ||
({ children }) => | ||
( | ||
<QueryClientProvider client={queryClient}> | ||
<MemoryRouter initialEntries={[initialEntries]}> | ||
<Route path="/:provider" exact> | ||
{children} | ||
</Route> | ||
</MemoryRouter> | ||
</QueryClientProvider> | ||
) | ||
|
||
const queryClient = new QueryClient({ | ||
defaultOptions: { queries: { retry: false } }, | ||
}) | ||
|
||
const server = setupServer() | ||
beforeAll(() => server.listen()) | ||
beforeEach(() => { | ||
server.resetHandlers() | ||
queryClient.clear() | ||
}) | ||
afterAll(() => server.close()) | ||
|
||
describe('AdminLink', () => { | ||
function setup(data = {}) { | ||
server.use( | ||
rest.get('/internal/users/current', (req, res, ctx) => | ||
res(ctx.status(200), ctx.json(data)) | ||
) | ||
) | ||
} | ||
|
||
describe('user is an admin', () => { | ||
beforeEach(() => { | ||
setup({ | ||
activated: false, | ||
email: '[email protected]', | ||
isAdmin: true, | ||
name: 'Codecov', | ||
ownerid: 2, | ||
username: 'codecov', | ||
}) | ||
}) | ||
|
||
it('renders link to access page', async () => { | ||
render(<AdminLink />, { wrapper: wrapper({}) }) | ||
const link = await screen.findByText(/Admin/) | ||
|
||
expect(link).toBeInTheDocument() | ||
expect(link).toHaveAttribute('href', '/admin/gh/access') | ||
}) | ||
}) | ||
|
||
describe('user is not an admin', () => { | ||
beforeEach(() => { | ||
setup({ | ||
activated: false, | ||
email: '[email protected]', | ||
isAdmin: false, | ||
name: 'Codecov', | ||
ownerid: 2, | ||
username: 'codecov', | ||
}) | ||
}) | ||
|
||
const { container } = render(<AdminLink />, { wrapper: wrapper({}) }) | ||
|
||
it('renders nothing', () => { | ||
expect(container).toBeEmptyDOMElement() | ||
}) | ||
}) | ||
}) |
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,24 @@ | ||
import { useSelfHostedCurrentUser } from 'services/selfHosted' | ||
import A from 'ui/A' | ||
import Icon from 'ui/Icon' | ||
|
||
function AdminLink() { | ||
const { data: user } = useSelfHostedCurrentUser() | ||
|
||
if (!user?.isAdmin) { | ||
return null | ||
} | ||
|
||
return ( | ||
<A | ||
variant="header" | ||
to={{ pageName: 'access' }} | ||
isExternal={false} | ||
hook="header-admin-link" | ||
> | ||
<Icon size="md" name="cog" variant="solid" /> Admin | ||
</A> | ||
) | ||
} | ||
|
||
export default AdminLink |
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 @@ | ||
export { default } from './AdminLink' |
44 changes: 44 additions & 0 deletions
44
src/layouts/Header/components/Navigator/Navigator.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,44 @@ | ||
import { render, screen } from '@testing-library/react' | ||
import { MemoryRouter, Route } from 'react-router-dom' | ||
|
||
import { RepoBreadcrumbProvider } from 'pages/RepoPage/context' | ||
|
||
import Navigator from './Navigator' | ||
|
||
jest.mock('ui/Breadcrumb', () => () => 'Breadcrumb') | ||
|
||
const wrapper: (initialEntries?: string) => React.FC<React.PropsWithChildren> = | ||
(initialEntries = '/gh/codecov') => | ||
({ children }) => | ||
( | ||
<MemoryRouter initialEntries={[initialEntries]}> | ||
<RepoBreadcrumbProvider> | ||
<Route path="/:provider/:owner" exact> | ||
{children} | ||
</Route> | ||
<Route path="/:provider/:owner/:repo" exact> | ||
{children} | ||
</Route> | ||
</RepoBreadcrumbProvider> | ||
</MemoryRouter> | ||
) | ||
|
||
describe('Header Navigator', () => { | ||
describe('when on repo page', () => { | ||
it('should render repo breadcrumb', async () => { | ||
render(<Navigator />, { wrapper: wrapper('/gh/codecov/test-repo') }) | ||
|
||
const breadcrumb = await screen.findByText('Breadcrumb') | ||
expect(breadcrumb).toBeInTheDocument() | ||
}) | ||
}) | ||
|
||
describe('temp: when not on repo page', () => { | ||
it('should render MyContextSwitcher', async () => { | ||
render(<Navigator />, { wrapper: wrapper() }) | ||
|
||
const switcher = await screen.findByText('MyContextSwitcher') | ||
expect(switcher).toBeInTheDocument() | ||
}) | ||
}) | ||
}) |
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,17 @@ | ||
import { useRouteMatch } from 'react-router-dom' | ||
|
||
import { useCrumbs } from 'pages/RepoPage/context' | ||
import Breadcrumb from 'ui/Breadcrumb' | ||
|
||
function Navigator() { | ||
const { path } = useRouteMatch() | ||
const { breadcrumbs } = useCrumbs() | ||
|
||
if (path.startsWith('/:provider/:owner/:repo')) { | ||
return <Breadcrumb paths={breadcrumbs} /> | ||
} | ||
|
||
return <p>MyContextSwitcher</p> | ||
} | ||
|
||
export default Navigator |
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 @@ | ||
export { default } from './Navigator' |
Oops, something went wrong.