Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholas-codecov committed Dec 3, 2024
1 parent a80d375 commit 90c5167
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
18 changes: 10 additions & 8 deletions src/pages/CommitDetailPage/Header/HeaderDefault/HeaderDefault.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useSuspenseQuery as useSuspenseQueryV5 } from '@tanstack/react-queryV5'
import { useParams } from 'react-router-dom'

import { formatTimeToNow } from 'shared/utils/dates'
Expand All @@ -7,21 +8,22 @@ import CIStatusLabel from 'ui/CIStatus'
import Icon from 'ui/Icon'
import TruncatedMessage from 'ui/TruncatedMessage/TruncatedMessage'

import { useCommitHeaderData } from './hooks'
import { CommitHeaderDataQueryOpts } from './queries/CommitHeaderDataQueryOpts'

import PullLabel from '../PullLabel'

function HeaderDefault() {
const { provider, owner, repo, commit: commitSha } = useParams()
const shortSHA = commitSha?.slice(0, 7)

const { data: headerData } = useCommitHeaderData({
provider,
owner,
repo,
commitId: commitSha,
})

const { data: headerData } = useSuspenseQueryV5(
CommitHeaderDataQueryOpts({
provider,
owner,
repo,
commitId: commitSha,
})
)
const providerPullUrl = getProviderPullURL({
provider,
owner,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import {
QueryClientProvider as QueryClientProviderV5,
QueryClient as QueryClientV5,
} from '@tanstack/react-queryV5'
import { render, screen, waitFor } from '@testing-library/react'
import { graphql, HttpResponse } from 'msw'
import { setupServer } from 'msw/node'
import { Suspense } from 'react'
import { MemoryRouter, Route } from 'react-router-dom'

import { useTruncation } from 'ui/TruncatedMessage/hooks'
Expand Down Expand Up @@ -29,22 +33,24 @@ const mockData = (pullId = null) => ({
},
})

const queryClient = new QueryClient({
const queryClientV5 = new QueryClientV5({
defaultOptions: { queries: { retry: false } },
})
const server = setupServer()

const wrapper = ({ children }) => (
<QueryClientProvider client={queryClient}>
<QueryClientProviderV5 client={queryClientV5}>
<MemoryRouter initialEntries={['/gh/codecov/test-repo/commit/id-1']}>
<Route path="/:provider/:owner/:repo/commit/:commit">{children}</Route>
<Route path="/:provider/:owner/:repo/commit/:commit">
<Suspense fallback={<p>Loading</p>}>{children}</Suspense>
</Route>
</MemoryRouter>
</QueryClientProvider>
</QueryClientProviderV5>
)

beforeAll(() => server.listen())
afterEach(() => {
queryClient.clear()
queryClientV5.clear()
server.resetHandlers()
})
afterAll(() => server.close())
Expand Down Expand Up @@ -117,8 +123,8 @@ describe('HeaderDefault', () => {
it('does not render the pull label', async () => {
render(<HeaderDefault />, { wrapper })

await waitFor(() => queryClient.isFetching)
await waitFor(() => !queryClient.isFetching)
await waitFor(() => queryClientV5.isFetching)
await waitFor(() => !queryClientV5.isFetching)

const pullIcon = screen.queryByText(/pull-request-open.svg/)
expect(pullIcon).not.toBeInTheDocument()
Expand Down

0 comments on commit 90c5167

Please sign in to comment.