Skip to content

Commit b2a584b

Browse files
authored
fix: HTML Validation issues with GitHub Rate Limit Banner (#3538)
1 parent f399f75 commit b2a584b

File tree

2 files changed

+61
-16
lines changed

2 files changed

+61
-16
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { render, screen } from '@testing-library/react'
2+
import { MemoryRouter, Route } from 'react-router'
3+
4+
import GitHubRateLimitExceededBanner from './GitHubRateLimitExceededBanner'
5+
6+
const wrapper =
7+
(initialEntry = '/gh'): React.FC<React.PropsWithChildren> =>
8+
({ children }) => (
9+
<MemoryRouter initialEntries={[initialEntry]}>
10+
<Route path="/:provider">{children}</Route>
11+
</MemoryRouter>
12+
)
13+
14+
describe('GitHubRateLimitExceededBanner', () => {
15+
describe('provider is GH', () => {
16+
it('renders the banner', () => {
17+
render(<GitHubRateLimitExceededBanner />, {
18+
wrapper: wrapper('/gh'),
19+
})
20+
21+
const title = screen.getByText('Rate limit exceeded')
22+
expect(title).toBeInTheDocument()
23+
24+
const description = screen.getByText(/Unable to calculate/)
25+
expect(description).toBeInTheDocument()
26+
27+
const link = screen.getByRole('link', { name: 'Github documentation.' })
28+
expect(link).toBeInTheDocument()
29+
expect(link).toHaveAttribute(
30+
'href',
31+
'https://docs.github.com/en/rest/using-the-rest-api/rate-limits-for-the-rest-api'
32+
)
33+
})
34+
})
35+
36+
describe('provider is not GH', () => {
37+
it('does not render', () => {
38+
const { container } = render(<GitHubRateLimitExceededBanner />, {
39+
wrapper: wrapper('/bb'),
40+
})
41+
42+
expect(container).toBeEmptyDOMElement()
43+
})
44+
})
45+
})

src/shared/GlobalBanners/GitHubRateLimitExceeded/GitHubRateLimitExceededBanner.tsx

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,31 @@ import { providerToName } from 'shared/utils/provider'
55
import A from 'ui/A'
66
import { Alert } from 'ui/Alert'
77

8+
interface URLParams {
9+
provider: Provider
10+
}
11+
812
const GitHubRateLimitExceededBanner = () => {
9-
const { provider } = useParams<{ provider: Provider }>()
13+
const { provider } = useParams<URLParams>()
1014
const isGh = providerToName(provider) === 'Github'
1115

1216
if (!isGh) return null
1317

1418
return (
1519
<div className="mb-2">
1620
<Alert variant="warning">
17-
<Alert.Title>
18-
<h2 className="flex gap-2 font-semibold">Rate limit exceeded</h2>
19-
</Alert.Title>
21+
<Alert.Title>Rate limit exceeded</Alert.Title>
2022
<Alert.Description>
21-
<p className="flex items-center gap-2">
22-
Unable to calculate coverage due to GitHub rate limit exceeded.
23-
Please retry later. More info on rate limits:
24-
<A
25-
data-testid="codecovGithubApp-link"
26-
to={{ pageName: 'githubRateLimitExceeded' }}
27-
hook={undefined}
28-
isExternal={true}
29-
>
30-
Github documentation.
31-
</A>
32-
</p>
23+
Unable to calculate coverage due to GitHub rate limit exceeded. Please
24+
retry later. More info on rate limits:{' '}
25+
<A
26+
data-testid="codecovGithubApp-link"
27+
to={{ pageName: 'githubRateLimitExceeded' }}
28+
hook={undefined}
29+
isExternal={true}
30+
>
31+
Github documentation.
32+
</A>
3333
</Alert.Description>
3434
</Alert>
3535
</div>

0 commit comments

Comments
 (0)