Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Migrate useIgnoredIds to TS Query V5 #3547

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import {
QueryClientProvider as QueryClientProviderV5,
QueryClient as QueryClientV5,
} from '@tanstack/react-queryV5'
import { render, screen, waitFor, within } from '@testing-library/react'
import { graphql, HttpResponse } from 'msw'
import { setupServer } from 'msw/node'
Expand Down Expand Up @@ -187,19 +191,24 @@ const server = setupServer()
const queryClient = new QueryClient({
defaultOptions: { queries: { retry: false, suspense: true } },
})
const queryClientV5 = new QueryClientV5({
defaultOptions: { queries: { retry: false } },
})

const wrapper: React.FC<React.PropsWithChildren> = ({ children }) => (
<QueryClientProvider client={queryClient}>
<MemoryRouter
initialEntries={[
'/gh/codecov/gazebo/commit/123sha/folder/subfolder/file.js',
]}
>
<Route path="/:provider/:owner/:repo/commit/:commit">
<Suspense fallback={<div>Loading</div>}>{children}</Suspense>
</Route>
</MemoryRouter>
</QueryClientProvider>
<QueryClientProviderV5 client={queryClientV5}>
<QueryClientProvider client={queryClient}>
<MemoryRouter
initialEntries={[
'/gh/codecov/gazebo/commit/123sha/folder/subfolder/file.js',
]}
>
<Route path="/:provider/:owner/:repo/commit/:commit">
<Suspense fallback={<div>Loading</div>}>{children}</Suspense>
</Route>
</MemoryRouter>
</QueryClientProvider>
</QueryClientProviderV5>
)

beforeAll(() => {
Expand All @@ -208,6 +217,7 @@ beforeAll(() => {

afterEach(() => {
queryClient.clear()
queryClientV5.clear()
server.resetHandlers()
})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { useQuery as useQueryV5 } from '@tanstack/react-queryV5'
import { Fragment, useMemo } from 'react'
import { useParams } from 'react-router-dom'

import { useIgnoredIds } from 'pages/CommitDetailPage/hooks/useIgnoredIds'
import { IgnoredIdsQueryOptions } from 'pages/CommitDetailPage/queries/IgnoredIdsQueryOptions'
import {
ImpactedFileType,
useComparisonForCommitAndParent,
Expand Down Expand Up @@ -68,7 +69,7 @@ function DiffRenderer({
const { commitFileDiff } = useNavLinks()
const { provider, owner, repo, commit } = useParams<URLParams>()
const { data: overview } = useRepoOverview({ provider, owner, repo })
const { data: ignoredUploadIds } = useIgnoredIds()
const { data: ignoredUploadIds } = useQueryV5(IgnoredIdsQueryOptions())

const fileDiff = useMemo(() => {
const transformedData = transformImpactedFileToDiff(impactedFile)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import {
QueryClientProvider as QueryClientProviderV5,
QueryClient as QueryClientV5,
} from '@tanstack/react-queryV5'
import { render, screen, waitFor, within } from '@testing-library/react'
import { graphql, HttpResponse } from 'msw'
import { setupServer } from 'msw/node'
Expand Down Expand Up @@ -176,19 +180,24 @@ const server = setupServer()
const queryClient = new QueryClient({
defaultOptions: { queries: { retry: false, suspense: true } },
})
const queryClientV5 = new QueryClientV5({
defaultOptions: { queries: { retry: false } },
})

const wrapper: React.FC<React.PropsWithChildren> = ({ children }) => (
<QueryClientProvider client={queryClient}>
<MemoryRouter
initialEntries={[
'/gh/codecov/gazebo/commit/123sha/folder/subfolder/file.js',
]}
>
<Route path="/:provider/:owner/:repo/commit/:commit">
<Suspense fallback={<div>Loading</div>}>{children}</Suspense>
</Route>
</MemoryRouter>
</QueryClientProvider>
<QueryClientProviderV5 client={queryClientV5}>
<QueryClientProvider client={queryClient}>
<MemoryRouter
initialEntries={[
'/gh/codecov/gazebo/commit/123sha/folder/subfolder/file.js',
]}
>
<Route path="/:provider/:owner/:repo/commit/:commit">
<Suspense fallback={<div>Loading</div>}>{children}</Suspense>
</Route>
</MemoryRouter>
</QueryClientProvider>
</QueryClientProviderV5>
)

beforeAll(() => {
Expand All @@ -197,6 +206,7 @@ beforeAll(() => {

afterEach(() => {
queryClient.clear()
queryClientV5.clear()
server.resetHandlers()
})

Expand Down Expand Up @@ -422,6 +432,7 @@ describe('CommitFileDiff', () => {
describe('there are ignored ids', () => {
beforeEach(() => {
queryClient.setQueryData(['IgnoredUploadIds'], [0])
queryClientV5.setQueryData(['IgnoredUploadIds'], [0])
})

it('renders hit count icon', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { useQuery as useQueryV5 } from '@tanstack/react-queryV5'
import PropTypes from 'prop-types'
import { Fragment, useMemo } from 'react'
import { useParams } from 'react-router-dom'

import { useIgnoredIds } from 'pages/CommitDetailPage/hooks/useIgnoredIds'
import { IgnoredIdsQueryOptions } from 'pages/CommitDetailPage/queries/IgnoredIdsQueryOptions'
import {
type ImpactedFileType,
useComparisonForCommitAndParent,
Expand Down Expand Up @@ -69,7 +70,7 @@ function DiffRenderer({
const { commitFileDiff } = useNavLinks()
const { owner, repo, provider, commit } = useParams<URLParams>()
const { data: overview } = useRepoOverview({ provider, owner, repo })
const { data: ignoredUploadIds } = useIgnoredIds()
const { data: ignoredUploadIds } = useQueryV5(IgnoredIdsQueryOptions())

const fileDiff = useMemo(() => {
const transformedData = transformImpactedFileToDiff(impactedFile)
Expand Down
31 changes: 0 additions & 31 deletions src/pages/CommitDetailPage/hooks/useIgnoredIds.test.tsx

This file was deleted.

10 changes: 0 additions & 10 deletions src/pages/CommitDetailPage/hooks/useIgnoredIds.ts

This file was deleted.

42 changes: 42 additions & 0 deletions src/pages/CommitDetailPage/queries/IgnoredIdsQueryOptions.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import {
QueryClientProvider as QueryClientProviderV5,
QueryClient as QueryClientV5,
useQuery as useQueryV5,
} from '@tanstack/react-queryV5'
import { renderHook, waitFor } from '@testing-library/react'

import { IgnoredIdsQueryOptions } from './IgnoredIdsQueryOptions'

const queryClientV5 = new QueryClientV5()

const wrapper: React.FC<React.PropsWithChildren> = ({ children }) => (
<QueryClientProviderV5 client={queryClientV5}>
{children}
</QueryClientProviderV5>
)

afterEach(() => {
queryClientV5.clear()
})

describe('IgnoredIdsQueryOptions', () => {
it('sets the initial data to an empty array', async () => {
const { result } = renderHook(() => useQueryV5(IgnoredIdsQueryOptions()), {
wrapper,
})

await waitFor(() => expect(result.current.data).toStrictEqual([]))
})

it('returns an empty array when called a second time', async () => {
const { result } = renderHook(() => useQueryV5(IgnoredIdsQueryOptions()), {
wrapper,
})

await waitFor(() => expect(result.current.data).toStrictEqual([]))

result.current.refetch()

await waitFor(() => expect(result.current.data).toStrictEqual([]))
})
})
9 changes: 9 additions & 0 deletions src/pages/CommitDetailPage/queries/IgnoredIdsQueryOptions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { queryOptions as queryOptionsV5 } from '@tanstack/react-queryV5'

export const IgnoredIdsQueryOptions = () =>
queryOptionsV5<number[]>({
queryKey: ['IgnoredUploadIds'],
queryFn: () => Promise.resolve([]),
staleTime: Infinity,
initialData: [],
})
Loading