Skip to content

Commit

Permalink
fix: HTML Validation issues with GitHub Rate Limit Banner (#3538)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholas-codecov authored Nov 28, 2024
1 parent f399f75 commit b2a584b
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { render, screen } from '@testing-library/react'
import { MemoryRouter, Route } from 'react-router'

import GitHubRateLimitExceededBanner from './GitHubRateLimitExceededBanner'

const wrapper =
(initialEntry = '/gh'): React.FC<React.PropsWithChildren> =>
({ children }) => (
<MemoryRouter initialEntries={[initialEntry]}>
<Route path="/:provider">{children}</Route>
</MemoryRouter>
)

describe('GitHubRateLimitExceededBanner', () => {
describe('provider is GH', () => {
it('renders the banner', () => {
render(<GitHubRateLimitExceededBanner />, {
wrapper: wrapper('/gh'),
})

const title = screen.getByText('Rate limit exceeded')
expect(title).toBeInTheDocument()

const description = screen.getByText(/Unable to calculate/)
expect(description).toBeInTheDocument()

const link = screen.getByRole('link', { name: 'Github documentation.' })
expect(link).toBeInTheDocument()
expect(link).toHaveAttribute(
'href',
'https://docs.github.com/en/rest/using-the-rest-api/rate-limits-for-the-rest-api'
)
})
})

describe('provider is not GH', () => {
it('does not render', () => {
const { container } = render(<GitHubRateLimitExceededBanner />, {
wrapper: wrapper('/bb'),
})

expect(container).toBeEmptyDOMElement()
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,31 @@ import { providerToName } from 'shared/utils/provider'
import A from 'ui/A'
import { Alert } from 'ui/Alert'

interface URLParams {
provider: Provider
}

const GitHubRateLimitExceededBanner = () => {
const { provider } = useParams<{ provider: Provider }>()
const { provider } = useParams<URLParams>()
const isGh = providerToName(provider) === 'Github'

if (!isGh) return null

return (
<div className="mb-2">
<Alert variant="warning">
<Alert.Title>
<h2 className="flex gap-2 font-semibold">Rate limit exceeded</h2>
</Alert.Title>
<Alert.Title>Rate limit exceeded</Alert.Title>
<Alert.Description>
<p className="flex items-center gap-2">
Unable to calculate coverage due to GitHub rate limit exceeded.
Please retry later. More info on rate limits:
<A
data-testid="codecovGithubApp-link"
to={{ pageName: 'githubRateLimitExceeded' }}
hook={undefined}
isExternal={true}
>
Github documentation.
</A>
</p>
Unable to calculate coverage due to GitHub rate limit exceeded. Please
retry later. More info on rate limits:{' '}
<A
data-testid="codecovGithubApp-link"
to={{ pageName: 'githubRateLimitExceeded' }}
hook={undefined}
isExternal={true}
>
Github documentation.
</A>
</Alert.Description>
</Alert>
</div>
Expand Down

0 comments on commit b2a584b

Please sign in to comment.