Skip to content

Commit

Permalink
add in tests for banner
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholas-codecov committed Nov 28, 2024
1 parent 0b7a7b0 commit 772b4c6
Showing 1 changed file with 45 additions and 0 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()
})
})
})

0 comments on commit 772b4c6

Please sign in to comment.