Skip to content

Commit

Permalink
Merge branch 'main' into chore-upgrade-to-vite-v6
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholas-codecov authored Jan 9, 2025
2 parents 030a6bc + 0922fa3 commit f466c2b
Show file tree
Hide file tree
Showing 168 changed files with 1,993 additions and 1,012 deletions.
8 changes: 8 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -500,5 +500,13 @@ module.exports = {
// https://github.com/facebook/react/tree/main/packages/eslint-plugin-react-hooks
'react-hooks/rules-of-hooks': 'error',
'react-hooks/exhaustive-deps': 'warn',

'no-restricted-syntax': [
'warn',
{
selector: "JSXText[value=/\\bGithub\\b|\\bGitlab\\b|\\bBitBucket\\b/]",
message: "Use correct casing (GitHub, GitLab, Bitbucket)"
}
]
},
}
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
24.12.2
25.1.3
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function InstallationHelpBanner() {
const { provider } = useParams()
const { params } = useLocationParams()

if (providerToName(provider) !== 'Github') return null
if (providerToName(provider) !== 'GitHub') return null

const { setup_action: setupAction } = params
if (setupAction !== 'install') return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function UserDropdown() {
})

const { provider } = useParams<URLParams>()
const isGh = providerToName(provider) === 'Github'
const isGh = providerToName(provider) === 'GitHub'
const history = useHistory()

const items =
Expand Down
1 change: 1 addition & 0 deletions src/pages/AccountSettings/AccountSettings.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ describe('AccountSettings', () => {
planValue === Plans.USERS_TEAMM ||
planValue === Plans.USERS_TEAMY,
isTrialPlan: false,
isSentryPlan: false,
},
},
},
Expand Down
1 change: 1 addition & 0 deletions src/pages/AccountSettings/AccountSettingsSideMenu.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ describe('AccountSettingsSideMenu', () => {
planValue === Plans.USERS_TEAMM ||
planValue === Plans.USERS_TEAMY,
isTrialPlan: false,
isSentryPlan: false,
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ beforeEach(() => {
server.resetHandlers()
})

afterEach(() => {
vi.clearAllMocks()
})

afterAll(() => {
server.close()
})
Expand All @@ -43,7 +47,7 @@ describe('DetailsSection', () => {
const mutate = vi.fn()
const addNotification = vi.fn()

useAddNotification.mockReturnValue(addNotification)
vi.mocked(useAddNotification).mockReturnValue(addNotification)
server.use(
graphql.mutation('UpdateProfile', (info) => {
mutate(info.variables)
Expand All @@ -52,15 +56,23 @@ describe('DetailsSection', () => {
data: {
updateProfile: {
me: {
username: 'donald duck',
email: info.variables.input.email
? info.variables.input.email
: '[email protected]',
name: info.variables.input.name
? info.variables.input.name
: 'donald duck',
avatarUrl: 'http://127.0.0.1/avatar-url',
onboardingCompleted: false,
onboardingCompleted: true,
privateAccess: null,
businessEmail: null,
user: {
name: info.variables.input.name
? info.variables.input.name
: 'donald duck',
username: 'donald duck',
avatarUrl: 'http://127.0.0.1/avatar-url',
avatar: 'http://127.0.0.1/avatar-url',
student: false,
studentCreatedAt: null,
studentUpdatedAt: null,
},
},
},
},
Expand Down Expand Up @@ -218,10 +230,15 @@ describe('DetailsSection', () => {
)
})
})

describe('when mutation is not successful', () => {
it('adds an error notification', async () => {
const { user, addNotification } = setup()
server.use(
graphql.mutation('UpdateProfile', () => {
return HttpResponse.error()
})
)

render(<DetailsSection name="donald duck" email="[email protected]" />, {
wrapper,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function GithubIntegrationCopy({ integrationId }) {
return (
<p>
This account is configured via the GitHub App. You can manage the apps
repository integration on <A to={{ pageName: 'github' }}>Github.</A>
repository integration on <A to={{ pageName: 'github' }}>GitHub.</A>
</p>
)
return (
Expand Down Expand Up @@ -47,7 +47,7 @@ function GithubIntegrationSection() {

return (
<div className="flex flex-col gap-2">
<h2 className="text-lg font-semibold">Github Integration</h2>
<h2 className="text-lg font-semibold">GitHub Integration</h2>
<GithubIntegrationCopy integrationId={accountDetails?.integrationId} />
</div>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ describe('GithubIntegrationSection', () => {
render(<GithubIntegrationSection />, { wrapper: wrapper() })

const link = await screen.findByRole('link', {
name: /Github/i,
name: /GitHub/i,
})
expect(link).toBeInTheDocument()
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export default function AdminTable() {
if (!isLoading && !tableData?.length) {
return (
<p>
No admins yet. Note that admins in your Github organization are
No admins yet. Note that admins in your GitHub organization are
automatically considered admins.
</p>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ describe('ManageAdminCard', () => {
render(<ManageAdminCard />, { wrapper })

const noAdmins = await screen.findByText(
/No admins yet. Note that admins in your Github organization are automatically considered admins./
/No admins yet. Note that admins in your GitHub organization are automatically considered admins./
)
expect(noAdmins).toBeInTheDocument()
})
Expand All @@ -123,7 +123,7 @@ describe('ManageAdminCard', () => {
render(<ManageAdminCard />, { wrapper })

const noAdmins = await screen.findByText(
/No admins yet. Note that admins in your Github organization are automatically considered admins./
/No admins yet. Note that admins in your GitHub organization are automatically considered admins./
)
expect(noAdmins).toBeInTheDocument()
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ import Icon from 'ui/Icon'

import useGenerateOrgUploadToken from './useGenerateOrgUploadToken'

interface URLParams {
owner: string
}

function GenerateOrgUploadToken() {
const { owner } = useParams()
const { owner } = useParams<URLParams>()
const { regenerateToken, isLoading } = useGenerateOrgUploadToken()
const isAdmin = useIsCurrentUserAnAdmin({ owner })

Expand All @@ -33,11 +37,12 @@ function GenerateOrgUploadToken() {
</div>
{!isAdmin && (
<div className="flex gap-1">
<Icon name="information-circle" size="sm" />
<Icon name="informationCircle" size="sm" />
Only organization admins can regenerate this token.
</div>
)}
<div className="flex gap-1">
{/* @ts-expect-error error until convert A to ts */}
<A to={{ pageName: 'orgUploadTokenDoc' }}>Learn more</A>
<p>how to generate and use the global upload token.</p>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const queryClient = new QueryClient({
},
})

const wrapper = ({ children }) => (
const wrapper: React.FC<React.PropsWithChildren> = ({ children }) => (
<MemoryRouter initialEntries={['/account/gh/codecov/orgUploadToken']}>
<QueryClientProvider client={queryClient}>
<Route path="/account/:provider/:owner/orgUploadToken">
Expand All @@ -46,26 +46,31 @@ beforeAll(() => {
afterEach(() => {
queryClient.clear()
server.resetHandlers()
vi.clearAllMocks()
})

afterAll(() => {
server.close()
})

type SetupOptions = {
orgUploadToken?: string | null
error?: string | null
isAdmin?: boolean
}

describe('OrgUploadToken', () => {
function setup(
{ orgUploadToken = null, error = null, isAdmin = true } = {
orgUploadToken: null,
error: null,
isAdmin: true,
}
) {
function setup({
orgUploadToken = null,
error = null,
isAdmin = true,
}: SetupOptions = {}) {
const user = userEvent.setup()
const mutate = vi.fn()
const addNotification = vi.fn()
useFlags.mockReturnValue({ tokenlessSection: true })

useAddNotification.mockReturnValue(addNotification)
vi.mocked(useFlags).mockReturnValue({ tokenlessSection: true })
vi.mocked(useAddNotification).mockReturnValue(addNotification)

server.use(
graphql.query('DetailOwner', () => {
Expand All @@ -87,15 +92,17 @@ describe('OrgUploadToken', () => {
},
})
}),
graphql.mutation('regenerateOrgUploadToken', () => {
mutate('regenerateOrgUploadToken')
graphql.mutation('RegenerateOrgUploadToken', () => {
mutate('RegenerateOrgUploadToken')
return HttpResponse.json({
data: {
regenerateOrgUploadToken: {
orgUploadToken,
error: {
__typename: error,
},
...(error && {
error: {
__typename: error,
},
}),
},
},
})
Expand Down Expand Up @@ -163,7 +170,7 @@ describe('OrgUploadToken', () => {

describe('when user clicks on Generate button', () => {
it('calls the mutation', async () => {
const { mutate, user } = setup()
const { mutate, user } = setup({ orgUploadToken: '' })

render(<OrgUploadToken />, { wrapper })

Expand All @@ -177,7 +184,7 @@ describe('OrgUploadToken', () => {
it('calls the mutation', async () => {
const { user, mutate } = setup({
orgUploadToken: '',
error: 'Authentication Error',
error: 'UnauthenticatedError',
isAdmin: true,
})
render(<OrgUploadToken />, { wrapper })
Expand All @@ -193,7 +200,7 @@ describe('OrgUploadToken', () => {
it('adds an error notification', async () => {
const { addNotification, user } = setup({
orgUploadToken: '',
error: 'Authentication Error',
error: 'UnauthenticatedError',
isAdmin: true,
})
const { rerender } = render(<OrgUploadToken />, { wrapper })
Expand All @@ -203,12 +210,12 @@ describe('OrgUploadToken', () => {

await user.click(genBtn)

rerender()
rerender(<OrgUploadToken />)

await waitFor(() =>
expect(addNotification).toHaveBeenCalledWith({
type: 'error',
text: 'Authentication Error',
text: 'UnauthenticatedError',
})
)
})
Expand Down Expand Up @@ -299,7 +306,7 @@ describe('OrgUploadToken', () => {

const show = await screen.findAllByText('Show')
expect(show[1]).toBeInTheDocument()
await user.click(show[1])
await user.click(show[1]!)

const token1 = await screen.findByText('CODECOV_TOKEN=token')
expect(token1).toBeInTheDocument()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ import RegenerateOrgUploadToken from './RegenerateOrgUploadToken'

const TokenlessSection = lazy(() => import('./TokenlessSection'))

interface URLParams {
provider: string
owner: string
}

function OrgUploadToken() {
const { provider, owner } = useParams()
const { provider, owner } = useParams<URLParams>()
const { data: orgUploadToken } = useOrgUploadToken({ provider, owner })
const { tokenlessSection: tokenlessSectionFlag } = useFlags({
tokenlessSection: false,
Expand All @@ -23,6 +28,7 @@ function OrgUploadToken() {
<div className="flex gap-1">
<h1 className="text-lg font-semibold">Global upload token</h1>
<div className="mt-2 text-xs">
{/* @ts-expect-error error until we can convert A component to ts */}
<A to={{ pageName: 'orgUploadTokenDoc' }}>learn more</A>
</div>
</div>
Expand Down
Loading

0 comments on commit f466c2b

Please sign in to comment.