1- import { QueryClient , QueryClientProvider } from '@tanstack/react-query'
1+ import {
2+ QueryClientProvider as QueryClientProviderV5 ,
3+ QueryClient as QueryClientV5 ,
4+ useQuery as useQueryV5 ,
5+ } from '@tanstack/react-queryV5'
26import { renderHook , waitFor } from '@testing-library/react'
37import { graphql , HttpResponse } from 'msw'
48import { setupServer } from 'msw/node'
59import { MemoryRouter , Route } from 'react-router-dom'
610
7- import { useCoverageTabData } from './useCoverageTabData'
8-
9- const mockOverview = {
10- owner : {
11- isCurrentUserActivated : true ,
12- repository : {
13- __typename : 'Repository' ,
14- private : false ,
15- defaultBranch : 'main' ,
16- oldestCommitAt : '2022-10-10T11:59:59' ,
17- coverageEnabled : true ,
18- bundleAnalysisEnabled : true ,
19- languages : [ 'JavaScript' ] ,
20- testAnalyticsEnabled : true ,
21- } ,
22- } ,
23- }
11+ import { CoverageTabDataQueryOpts } from './CoverageTabDataQueryOpts'
2412
2513const mockCoverageTabData = {
2614 owner : {
@@ -66,7 +54,7 @@ const mockNullOwner = {
6654const mockUnsuccessfulParseError = { }
6755
6856const server = setupServer ( )
69- const queryClient = new QueryClient ( {
57+ const queryClientV5 = new QueryClientV5 ( {
7058 defaultOptions : { queries : { retry : false } } ,
7159} )
7260
@@ -75,7 +63,7 @@ const wrapper =
7563 initialEntries = '/gh/codecov/cool-repo'
7664 ) : React . FC < React . PropsWithChildren > =>
7765 ( { children } ) => (
78- < QueryClientProvider client = { queryClient } >
66+ < QueryClientProviderV5 client = { queryClientV5 } >
7967 < MemoryRouter initialEntries = { [ initialEntries ] } >
8068 < Route
8169 path = { [
@@ -86,15 +74,15 @@ const wrapper =
8674 { children }
8775 </ Route >
8876 </ MemoryRouter >
89- </ QueryClientProvider >
77+ </ QueryClientProviderV5 >
9078 )
9179
9280beforeAll ( ( ) => {
9381 server . listen ( )
9482} )
9583
9684afterEach ( ( ) => {
97- queryClient . clear ( )
85+ queryClientV5 . clear ( )
9886 server . resetHandlers ( )
9987} )
10088
@@ -109,7 +97,7 @@ interface SetupArgs {
10997 isNullOwner ?: boolean
11098}
11199
112- describe ( 'useCoverageTabData ' , ( ) => {
100+ describe ( 'CoverageTabDataQueryOpts ' , ( ) => {
113101 function setup ( {
114102 isNotFoundError = false ,
115103 isOwnerNotActivatedError = false ,
@@ -129,73 +117,40 @@ describe('useCoverageTabData', () => {
129117 } else {
130118 return HttpResponse . json ( { data : mockCoverageTabData } )
131119 }
132- } ) ,
133- graphql . query ( 'GetRepoOverview' , ( ) => {
134- return HttpResponse . json ( { data : mockOverview } )
135120 } )
136121 )
137122 }
138123
139124 describe ( 'valid data response' , ( ) => {
140- describe ( 'branch is passed' , ( ) => {
141- it ( 'returns the data for the passed branch' , async ( ) => {
142- setup ( { } )
143- const { result } = renderHook (
144- ( ) =>
145- useCoverageTabData ( {
125+ it ( 'returns the data for the passed branch' , async ( ) => {
126+ setup ( { } )
127+ const { result } = renderHook (
128+ ( ) =>
129+ useQueryV5 (
130+ CoverageTabDataQueryOpts ( {
146131 provider : 'gh' ,
147132 owner : 'codecov' ,
148133 repo : 'cool-repo' ,
149134 branch : 'main' ,
150- } ) ,
151- { wrapper : wrapper ( ) }
152- )
153-
154- await waitFor ( ( ) => expect ( result . current . isSuccess ) . toBeTruthy ( ) )
155- await waitFor ( ( ) =>
156- expect ( result . current . data ) . toEqual ( {
157- branch : {
158- head : {
159- coverageAnalytics : {
160- totals : {
161- fileCount : 10 ,
162- } ,
163- } ,
164- } ,
165- } ,
166- } )
167- )
168- } )
169- } )
170-
171- describe ( 'branch is not passed' , ( ) => {
172- it ( 'returns the data for the default branch' , async ( ) => {
173- setup ( { } )
174- const { result } = renderHook (
175- ( ) =>
176- useCoverageTabData ( {
177- provider : 'gh' ,
178- owner : 'codecov' ,
179- repo : 'cool-repo' ,
180- } ) ,
181- { wrapper : wrapper ( ) }
182- )
135+ } )
136+ ) ,
137+ { wrapper : wrapper ( ) }
138+ )
183139
184- await waitFor ( ( ) => expect ( result . current . isSuccess ) . toBeTruthy ( ) )
185- await waitFor ( ( ) =>
186- expect ( result . current . data ) . toEqual ( {
187- branch : {
188- head : {
189- coverageAnalytics : {
190- totals : {
191- fileCount : 10 ,
192- } ,
140+ await waitFor ( ( ) => expect ( result . current . isSuccess ) . toBeTruthy ( ) )
141+ await waitFor ( ( ) =>
142+ expect ( result . current . data ) . toEqual ( {
143+ branch : {
144+ head : {
145+ coverageAnalytics : {
146+ totals : {
147+ fileCount : 10 ,
193148 } ,
194149 } ,
195150 } ,
196- } )
197- )
198- } )
151+ } ,
152+ } )
153+ )
199154 } )
200155 } )
201156
@@ -214,12 +169,14 @@ describe('useCoverageTabData', () => {
214169 setup ( { isNotFoundError : true } )
215170 const { result } = renderHook (
216171 ( ) =>
217- useCoverageTabData ( {
218- provider : 'gh' ,
219- owner : 'codecov' ,
220- repo : 'cool-repo' ,
221- branch : 'main' ,
222- } ) ,
172+ useQueryV5 (
173+ CoverageTabDataQueryOpts ( {
174+ provider : 'gh' ,
175+ owner : 'codecov' ,
176+ repo : 'cool-repo' ,
177+ branch : 'main' ,
178+ } )
179+ ) ,
223180 { wrapper : wrapper ( ) }
224181 )
225182
@@ -250,12 +207,14 @@ describe('useCoverageTabData', () => {
250207 setup ( { isOwnerNotActivatedError : true } )
251208 const { result } = renderHook (
252209 ( ) =>
253- useCoverageTabData ( {
254- provider : 'gh' ,
255- owner : 'codecov' ,
256- repo : 'cool-repo' ,
257- branch : 'main' ,
258- } ) ,
210+ useQueryV5 (
211+ CoverageTabDataQueryOpts ( {
212+ provider : 'gh' ,
213+ owner : 'codecov' ,
214+ repo : 'cool-repo' ,
215+ branch : 'main' ,
216+ } )
217+ ) ,
259218 { wrapper : wrapper ( ) }
260219 )
261220
@@ -286,12 +245,14 @@ describe('useCoverageTabData', () => {
286245 setup ( { isUnsuccessfulParseError : true } )
287246 const { result } = renderHook (
288247 ( ) =>
289- useCoverageTabData ( {
290- provider : 'gh' ,
291- owner : 'codecov' ,
292- repo : 'cool-repo' ,
293- branch : 'main' ,
294- } ) ,
248+ useQueryV5 (
249+ CoverageTabDataQueryOpts ( {
250+ provider : 'gh' ,
251+ owner : 'codecov' ,
252+ repo : 'cool-repo' ,
253+ branch : 'main' ,
254+ } )
255+ ) ,
295256 { wrapper : wrapper ( ) }
296257 )
297258
0 commit comments