diff --git a/src/shared/GlobalBanners/GitHubRateLimitExceeded/GitHubRateLimitExceededBanner.test.tsx b/src/shared/GlobalBanners/GitHubRateLimitExceeded/GitHubRateLimitExceededBanner.test.tsx new file mode 100644 index 0000000000..e3f30e2f9e --- /dev/null +++ b/src/shared/GlobalBanners/GitHubRateLimitExceeded/GitHubRateLimitExceededBanner.test.tsx @@ -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 => + ({ children }) => ( + + {children} + + ) + +describe('GitHubRateLimitExceededBanner', () => { + describe('provider is GH', () => { + it('renders the banner', () => { + render(, { + 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(, { + wrapper: wrapper('/bb'), + }) + + expect(container).toBeEmptyDOMElement() + }) + }) +}) diff --git a/src/shared/GlobalBanners/GitHubRateLimitExceeded/GitHubRateLimitExceededBanner.tsx b/src/shared/GlobalBanners/GitHubRateLimitExceeded/GitHubRateLimitExceededBanner.tsx index fb44f94f5c..500a87c573 100644 --- a/src/shared/GlobalBanners/GitHubRateLimitExceeded/GitHubRateLimitExceededBanner.tsx +++ b/src/shared/GlobalBanners/GitHubRateLimitExceeded/GitHubRateLimitExceededBanner.tsx @@ -5,8 +5,12 @@ 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() const isGh = providerToName(provider) === 'Github' if (!isGh) return null @@ -14,22 +18,18 @@ const GitHubRateLimitExceededBanner = () => { return (
- -

Rate limit exceeded

-
+ Rate limit exceeded -

- Unable to calculate coverage due to GitHub rate limit exceeded. - Please retry later. More info on rate limits: - - Github documentation. - -

+ Unable to calculate coverage due to GitHub rate limit exceeded. Please + retry later. More info on rate limits:{' '} + + Github documentation. +