Skip to content

Commit

Permalink
Merge branch 'main' into 332-update-usepull-to-accept-flags-argument
Browse files Browse the repository at this point in the history
  • Loading branch information
terry-codecov authored Oct 26, 2023
2 parents b5173c4 + 70fcb81 commit bddf7fa
Show file tree
Hide file tree
Showing 43 changed files with 1,440 additions and 497 deletions.
14 changes: 7 additions & 7 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 @@ -127,7 +127,7 @@
"jest-junit": "^13.0.0",
"lint-staged": "^13.2.2",
"msw": "^1.2.1",
"postcss": "^8.4.12",
"postcss": "^8.4.31",
"prettier": "^2.8.8",
"react-scripts": "^5.0.1",
"react-test-renderer": "^18.2.0",
Expand Down
1 change: 1 addition & 0 deletions src/layouts/BaseLayout/BaseLayout.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ const internalUserHasSyncedProviders = {
service: 'github',
},
],
termsAgreement: false,
}

const queryClient = new QueryClient({
Expand Down
9 changes: 2 additions & 7 deletions src/layouts/BaseLayout/hooks/useUserAccessGate.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,8 @@ const useUserAccessGate = () => {

// the undefined provider check can be removed when the ToS has
// been refactored to no longer use a provider
if (
termsOfServicePage &&
!isUndefined(provider) &&
!isGuest &&
!config.IS_SELF_HOSTED
) {
showAgreeToTerms = userData?.termsAgreement === false
if (termsOfServicePage && !isGuest && !config.IS_SELF_HOSTED) {
showAgreeToTerms = internalUser?.termsAgreement === false

Check warning on line 77 in src/layouts/BaseLayout/hooks/useUserAccessGate.js

View check run for this annotation

Codecov - Staging / codecov/patch

src/layouts/BaseLayout/hooks/useUserAccessGate.js#L77

Added line #L77 was not covered by tests

Check warning on line 77 in src/layouts/BaseLayout/hooks/useUserAccessGate.js

View check run for this annotation

Codecov Public QA / codecov/patch

src/layouts/BaseLayout/hooks/useUserAccessGate.js#L77

Added line #L77 was not covered by tests

Check warning on line 77 in src/layouts/BaseLayout/hooks/useUserAccessGate.js

View check run for this annotation

Codecov - QA / codecov/patch

src/layouts/BaseLayout/hooks/useUserAccessGate.js#L77

Added line #L77 was not covered by tests
}

const onSyncPage = currentRoute.path === '/sync'
Expand Down
28 changes: 26 additions & 2 deletions src/layouts/BaseLayout/hooks/useUserAccessGate.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,30 @@ const internalUserHasSyncedProviders = {
],
}

const internalUserWithSignedTOS = {
email: userSignedInIdentity.email,
name: userSignedInIdentity.name,
externalId: '123',
owners: [
{
service: 'github',
},
],
termsAgreement: true,
}

const internalUserWithUnsignedTOS = {
email: userSignedInIdentity.email,
name: userSignedInIdentity.name,
externalId: '123',
owners: [
{
service: 'github',
},
],
termsAgreement: false,
}

type InternalUser =
| typeof internalUserNoSyncedProviders
| typeof internalUserHasSyncedProviders
Expand Down Expand Up @@ -249,7 +273,7 @@ describe('useUserAccessGate', () => {
'signed TOS',
{
user: loggedInUser,
internalUser: internalUserHasSyncedProviders,
internalUser: internalUserWithSignedTOS,
termsOfServicePage: true,
isSelfHosted: false,
defaultOrgSelectorPage: false,
Expand Down Expand Up @@ -361,7 +385,7 @@ describe('useUserAccessGate', () => {
'unsigned TOS',
{
user: loggedInUnsignedUser,
internalUser: internalUserHasSyncedProviders,
internalUser: internalUserWithUnsignedTOS,
termsOfServicePage: true,
isSelfHosted: false,
defaultOrgSelectorPage: false,
Expand Down
38 changes: 38 additions & 0 deletions src/pages/CommitDetailPage/Header/Header.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { render, screen } from '@testing-library/react'
import { setupServer } from 'msw/node'
import { MemoryRouter, Route } from 'react-router-dom'

import Header from './Header'

jest.mock('./HeaderDefault', () => () => 'Default Header')

const queryClient = new QueryClient({
defaultOptions: { queries: { retry: false } },
})
const server = setupServer()

const wrapper: React.FC<React.PropsWithChildren> = ({ children }) => (
<QueryClientProvider client={queryClient}>
<MemoryRouter initialEntries={['/gh/codecov/test-repo/commit/id-1']}>
<Route path="/:provider/:owner/:repo/commit/:commit">{children}</Route>
</MemoryRouter>
</QueryClientProvider>
)

beforeAll(() => server.listen())
afterEach(() => {
queryClient.clear()
server.resetHandlers()
})
afterAll(() => server.close())

describe('Header', () => {
describe('when rendered with valid values', () => {
it('renders the default header', async () => {
render(<Header />, { wrapper })
const defaultHeader = await screen.findByText(/Default Header/)
expect(defaultHeader).toBeInTheDocument()
})
})
})
7 changes: 7 additions & 0 deletions src/pages/CommitDetailPage/Header/Header.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import HeaderDefault from './HeaderDefault'

function Header() {
return <HeaderDefault />

Check warning on line 4 in src/pages/CommitDetailPage/Header/Header.tsx

View check run for this annotation

Codecov - Staging / codecov/patch

src/pages/CommitDetailPage/Header/Header.tsx#L3-L4

Added lines #L3 - L4 were not covered by tests

Check warning on line 4 in src/pages/CommitDetailPage/Header/Header.tsx

View check run for this annotation

Codecov Public QA / codecov/patch

src/pages/CommitDetailPage/Header/Header.tsx#L3-L4

Added lines #L3 - L4 were not covered by tests

Check warning on line 4 in src/pages/CommitDetailPage/Header/Header.tsx

View check run for this annotation

Codecov - QA / codecov/patch

src/pages/CommitDetailPage/Header/Header.tsx#L3-L4

Added lines #L3 - L4 were not covered by tests
}

export default Header
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import Icon from 'ui/Icon'
import TruncatedMessage from 'ui/TruncatedMessage/TruncatedMessage'

import { useCommitHeaderData } from './hooks'
import PullLabel from './PullLabel'

function Header() {
import PullLabel from '../PullLabel'

function HeaderDefault() {

Check warning on line 14 in src/pages/CommitDetailPage/Header/HeaderDefault/HeaderDefault.jsx

View check run for this annotation

Codecov - Staging / codecov/patch

src/pages/CommitDetailPage/Header/HeaderDefault/HeaderDefault.jsx#L14

Added line #L14 was not covered by tests

Check warning on line 14 in src/pages/CommitDetailPage/Header/HeaderDefault/HeaderDefault.jsx

View check run for this annotation

Codecov Public QA / codecov/patch

src/pages/CommitDetailPage/Header/HeaderDefault/HeaderDefault.jsx#L14

Added line #L14 was not covered by tests

Check warning on line 14 in src/pages/CommitDetailPage/Header/HeaderDefault/HeaderDefault.jsx

View check run for this annotation

Codecov - QA / codecov/patch

src/pages/CommitDetailPage/Header/HeaderDefault/HeaderDefault.jsx#L14

Added line #L14 was not covered by tests
const { provider, owner, repo, commit: commitSha } = useParams()
const shortSHA = commitSha?.slice(0, 7)

Expand Down Expand Up @@ -85,4 +86,4 @@ function Header() {
)
}

export default Header
export default HeaderDefault
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { MemoryRouter, Route } from 'react-router-dom'

import { useTruncation } from 'ui/TruncatedMessage/hooks'

import Header from './Header'
import HeaderDefault from './HeaderDefault'

jest.mock('ui/TruncatedMessage/hooks')

Expand Down Expand Up @@ -49,7 +49,7 @@ afterEach(() => {
})
afterAll(() => server.close())

describe('Header', () => {
describe('HeaderDefault', () => {
function setup(pullId = 1234) {
useTruncation.mockImplementation(() => ({
ref: () => {},
Expand All @@ -69,21 +69,21 @@ describe('Header', () => {
})

it('renders commit message', async () => {
render(<Header />, { wrapper })
render(<HeaderDefault />, { wrapper })

const message = await screen.findByText('Test Commit')
expect(message).toBeInTheDocument()
})

it('The summary header', async () => {
render(<Header />, { wrapper })
render(<HeaderDefault />, { wrapper })

const authored = await screen.findByText(/authored commit/)
expect(authored).toBeInTheDocument()
})

it('renders commit id and link', async () => {
render(<Header />, { wrapper })
render(<HeaderDefault />, { wrapper })

const commitLink = await screen.findByRole('link', {
name: /id-1/i,
Expand All @@ -95,14 +95,14 @@ describe('Header', () => {
})

it('renders CI Passed', async () => {
render(<Header />, { wrapper })
render(<HeaderDefault />, { wrapper })

const ciPassed = await screen.findByText('CI Passed')
expect(ciPassed).toBeInTheDocument()
})

it('renders branch name', async () => {
render(<Header />, { wrapper })
render(<HeaderDefault />, { wrapper })

const branchName = await screen.findByText('cool-branch')
expect(branchName).toBeInTheDocument()
Expand All @@ -115,7 +115,7 @@ describe('Header', () => {
})

it('does not render the pull label', async () => {
render(<Header />, { wrapper })
render(<HeaderDefault />, { wrapper })

await waitFor(() => queryClient.isFetching)
await waitFor(() => !queryClient.isFetching)
Expand Down
1 change: 1 addition & 0 deletions src/pages/CommitDetailPage/Header/HeaderDefault/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './HeaderDefault'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './useCommitHeaderDataTeam'
Loading

0 comments on commit bddf7fa

Please sign in to comment.