Skip to content

Commit

Permalink
Merge branch 'main' into release/24.5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
trent-codecov committed May 2, 2024
2 parents b0fbe04 + 784493b commit f0e630d
Show file tree
Hide file tree
Showing 33 changed files with 1,031 additions and 517 deletions.
226 changes: 146 additions & 80 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@
"dependencies": {
"@hookform/resolvers": "^2.8.5",
"@radix-ui/react-accordion": "^1.1.2",
"@radix-ui/react-label": "^2.0.2",
"@radix-ui/react-popover": "^1.0.6",
"@radix-ui/react-radio-group": "^1.1.3",
"@sentry/react": "^8.0.0-beta.4",
"@stripe/react-stripe-js": "^1.7.2",
"@stripe/stripe-js": "^1.52.1",
Expand All @@ -70,10 +72,10 @@
"prism-react-renderer": "^1.3.1",
"prop-types": "^15.8.1",
"qs": "^6.11.1",
"react": "^18.2.0",
"react": "^18.3.1",
"react-ace": "^10.1.0",
"react-day-picker": "^8.8.0",
"react-dom": "^18.2.0",
"react-dom": "^18.3.1",
"react-hook-form": "^7.43.9",
"react-hot-toast": "^2.4.1",
"react-intersection-observer": "^9.4.1",
Expand Down Expand Up @@ -107,13 +109,13 @@
"@tailwindcss/container-queries": "^0.1.1",
"@tanstack/eslint-plugin-query": "^4.29.4",
"@tanstack/react-query-devtools": "^4.29.6",
"@testing-library/jest-dom": "^6.2.1",
"@testing-library/react": "^14.1.2",
"@testing-library/jest-dom": "^6.4.2",
"@testing-library/react": "^14.3.1",
"@testing-library/user-event": "^14.5.2",
"@total-typescript/ts-reset": "^0.4.2",
"@types/jest": "^29.5.1",
"@types/node": "^20.5.7",
"@types/react": "^18.2.7",
"@types/react": "^18.3.1",
"@types/react-dom": "^18.2.4",
"@types/react-modal": "^3.16.2",
"@types/react-router-dom": "^5.3.3",
Expand All @@ -133,7 +135,7 @@
"postcss": "^8.4.31",
"prettier": "^2.8.8",
"react-scripts": "^5.0.1",
"react-test-renderer": "^18.2.0",
"react-test-renderer": "^18.3.1",
"remark-gfm": "^3.0.1",
"resolve-url-loader": "^5.0.0",
"source-map-explorer": "^2.5.3",
Expand Down
95 changes: 67 additions & 28 deletions src/layouts/shared/ErrorBoundary/ErrorBoundary.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,35 @@ describe('Error Boundary', () => {
spy.mockImplementation(mockError)
})

function setup(props) {
render(
<MemoryRouter initialEntries={['/gh/test/']}>
<Route path="/:provider/:owner/">
<ErrorBoundary {...props}>
<BadComponent />
</ErrorBoundary>
</Route>
</MemoryRouter>
)
}

describe('when a child component throw an error', () => {
beforeEach(() => {
setup()
})

it('displays it in the console', () => {
render(
<MemoryRouter initialEntries={['/gh/test/']}>
<Route path="/:provider/:owner/">
<ErrorBoundary>
<BadComponent />
</ErrorBoundary>
</Route>
</MemoryRouter>
)

expect(mockError).toHaveBeenCalled()
expect(mockError.mock.calls[0][0]).toContain(thrownError) // Can this be done better?
})

it('renders the default error UI', () => {
// @sentry/react seems to have undocumented difference in behavior when not passing fallback.
// No fallback looks like multiple error message UIs vs a single UI if fallback is set. Not ideal
setup()
render(
<MemoryRouter initialEntries={['/gh/test/']}>
<Route path="/:provider/:owner/">
<ErrorBoundary>
<BadComponent />
</ErrorBoundary>
</Route>
</MemoryRouter>
)

// Get first error message
const [defaultErrorUI] = screen.getAllByText(
/There's been an error. Please try refreshing your browser, if this error persists please/
Expand All @@ -57,6 +60,16 @@ describe('Error Boundary', () => {
})

it('links to the freshdesk support page', () => {
render(
<MemoryRouter initialEntries={['/gh/test/']}>
<Route path="/:provider/:owner/">
<ErrorBoundary>
<BadComponent />
</ErrorBoundary>
</Route>
</MemoryRouter>
)

const issueLink = screen.getByRole('link', { name: /contact support/i })
expect(issueLink).toBeInTheDocument()
expect(issueLink.href).toBe('https://codecovpro.zendesk.com/hc/en-us')
Expand All @@ -65,41 +78,67 @@ describe('Error Boundary', () => {
describe('when given a custom error component', () => {
const customMessage = 'Whoopsie'

beforeEach(() => {
setup({ errorComponent: <p>{customMessage}</p> })
})

it('displays it in the console', () => {
render(
<MemoryRouter initialEntries={['/gh/test/']}>
<Route path="/:provider/:owner/">
<ErrorBoundary errorComponent={<p>{customMessage}</p>}>
<BadComponent />
</ErrorBoundary>
</Route>
</MemoryRouter>
)

expect(mockError).toHaveBeenCalled()
expect(mockError.mock.calls[0][0]).toContain(thrownError)
})

it('renders a custom error component', () => {
render(
<MemoryRouter initialEntries={['/gh/test/']}>
<Route path="/:provider/:owner/">
<ErrorBoundary errorComponent={<p>{customMessage}</p>}>
<BadComponent />
</ErrorBoundary>
</Route>
</MemoryRouter>
)

const CustomError = screen.getByText(customMessage)

expect(CustomError).toBeInTheDocument()
})
})

describe.skip('You can set the scope to sent to Sentry.io', () => {
beforeEach(() => {
const spySentry = jest.spyOn(Sentry, 'withScope')
spySentry.mockImplementation((callback) => {
callback({ setTag: sentryMockScope })
})

setup({
sentryScopes: [
['wonderland', 'alice'],
['mad', 'hatter'],
],
})
})

afterEach(() => {
jest.resetAllMocks()
jest.unmock('@sentry/browser')
})

it('The beforeCapture prop correctly sets tags.', () => {
render(
<MemoryRouter initialEntries={['/gh/test/']}>
<Route path="/:provider/:owner/">
<ErrorBoundary
sentryScopes={[
['wonderland', 'alice'],
['mad', 'hatter'],
]}
>
<BadComponent />
</ErrorBoundary>
</Route>
</MemoryRouter>
)

expect(sentryMockScope).toHaveBeenCalledTimes(2)
expect(sentryMockScope).toHaveBeenCalledWith('wonderland', 'alice')
expect(sentryMockScope).toHaveBeenCalledWith('mad', 'hatter')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ function OrgUploadToken() {
return (
<div className="flex flex-col gap-4 lg:w-3/4">
<div className="flex gap-1">
<h1 className="text-lg font-semibold">
Global repository upload token
</h1>
<h1 className="text-lg font-semibold">Global upload token</h1>
<div className="mt-2 text-xs">
<A to={{ pageName: 'orgUploadTokenDoc' }}>learn more</A>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ describe('OrgUploadToken', () => {
it('renders title', async () => {
render(<OrgUploadToken />, { wrapper })

const title = await screen.findByText(/Global repository upload token/)
const title = await screen.findByText(/Global upload token/)
expect(title).toBeInTheDocument()
})

Expand Down Expand Up @@ -237,7 +237,7 @@ describe('OrgUploadToken', () => {
await waitFor(() =>
expect(addNotification).toHaveBeenCalledWith({
type: 'success',
text: 'Global repository upload token generated.',
text: 'Global upload token generated.',
})
)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default function useGenerateOrgUploadToken() {
} else {
addToast({
type: 'success',
text: 'Global repository upload token generated.',
text: 'Global upload token generated.',
})
}
},
Expand Down
21 changes: 11 additions & 10 deletions src/pages/DefaultOrgSelector/hooks/useMyOrganizations.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { graphql } from 'msw'
import { setupServer } from 'msw/node'
import { MemoryRouter, Route } from 'react-router-dom'

import { useMyOrganizations } from './useMyOrganizations'
import type { MyOrganizationsData } from './useMyOrganizations'
import { useMyOrganizations } from './useMyOrganizations'

const queryClient = new QueryClient({
defaultOptions: { queries: { retry: false } },
Expand Down Expand Up @@ -68,7 +68,7 @@ describe('useMyOrganizations', () => {
owner: {
avatarUrl:
'https://avatars0.githubusercontent.com/u/8226205?v=3&s=s0',
username: 'Rula',
username: 'cool-user',
ownerid: 9,
},
myOrganizations: {
Expand All @@ -93,7 +93,7 @@ describe('useMyOrganizations', () => {
})

await waitFor(() => expect(result.current.isSuccess).toBe(true))
expect(thrownMock).not.toHaveBeenCalled()
await waitFor(() => expect(thrownMock).not.toHaveBeenCalled())

expect(result.current.data).toEqual({
pageParams: [undefined],
Expand All @@ -103,7 +103,7 @@ describe('useMyOrganizations', () => {
owner: {
avatarUrl:
'https://avatars0.githubusercontent.com/u/8226205?v=3&s=s0',
username: 'Rula',
username: 'cool-user',
ownerid: 9,
},
myOrganizations: {
Expand Down Expand Up @@ -137,7 +137,7 @@ describe('useMyOrganizations', () => {
owner: {
avatarUrl:
'https://avatars0.githubusercontent.com/u/8226205?v=3&s=s0',
username: 'Rula',
username: 'cool-user',
ownerid: 9,
},
myOrganizations: {
Expand All @@ -162,7 +162,7 @@ describe('useMyOrganizations', () => {
owner: {
avatarUrl:
'https://avatars0.githubusercontent.com/u/8226205?v=3&s=s0',
username: 'Rula',
username: 'cool-user',
ownerid: 9,
},
myOrganizations: {
Expand Down Expand Up @@ -236,7 +236,7 @@ describe('useMyOrganizations', () => {
owner: {
avatarUrl:
'https://avatars0.githubusercontent.com/u/8226205?v=3&s=s0',
username: 'Rula',
username: 'cool-user',
ownerid: 9,
},
myOrganizations: {
Expand Down Expand Up @@ -271,7 +271,7 @@ describe('useMyOrganizations', () => {
owner: {
avatarUrl:
'https://avatars0.githubusercontent.com/u/8226205?v=3&s=s0',
username: 'Rula',
username: 'cool-user',
ownerid: 9,
},
myOrganizations: {
Expand All @@ -295,14 +295,15 @@ describe('useMyOrganizations', () => {
],
})
})

it('does not return a next cursor with no next page', async () => {
const { thrownMock } = setup({
MyOrganizationsData: {
me: {
owner: {
avatarUrl:
'https://avatars0.githubusercontent.com/u/8226205?v=3&s=s0',
username: 'Rula',
username: 'cool-user',
ownerid: 9,
},
myOrganizations: {
Expand Down Expand Up @@ -337,7 +338,7 @@ describe('useMyOrganizations', () => {
owner: {
avatarUrl:
'https://avatars0.githubusercontent.com/u/8226205?v=3&s=s0',
username: 'Rula',
username: 'cool-user',
ownerid: 9,
},
myOrganizations: {
Expand Down

0 comments on commit f0e630d

Please sign in to comment.