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'
2
6
import { renderHook , waitFor } from '@testing-library/react'
3
7
import { graphql , HttpResponse } from 'msw'
4
8
import { setupServer } from 'msw/node'
5
9
import { MemoryRouter , Route } from 'react-router-dom'
6
10
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'
24
12
25
13
const mockCoverageTabData = {
26
14
owner : {
@@ -66,7 +54,7 @@ const mockNullOwner = {
66
54
const mockUnsuccessfulParseError = { }
67
55
68
56
const server = setupServer ( )
69
- const queryClient = new QueryClient ( {
57
+ const queryClientV5 = new QueryClientV5 ( {
70
58
defaultOptions : { queries : { retry : false } } ,
71
59
} )
72
60
@@ -75,7 +63,7 @@ const wrapper =
75
63
initialEntries = '/gh/codecov/cool-repo'
76
64
) : React . FC < React . PropsWithChildren > =>
77
65
( { children } ) => (
78
- < QueryClientProvider client = { queryClient } >
66
+ < QueryClientProviderV5 client = { queryClientV5 } >
79
67
< MemoryRouter initialEntries = { [ initialEntries ] } >
80
68
< Route
81
69
path = { [
@@ -86,15 +74,15 @@ const wrapper =
86
74
{ children }
87
75
</ Route >
88
76
</ MemoryRouter >
89
- </ QueryClientProvider >
77
+ </ QueryClientProviderV5 >
90
78
)
91
79
92
80
beforeAll ( ( ) => {
93
81
server . listen ( )
94
82
} )
95
83
96
84
afterEach ( ( ) => {
97
- queryClient . clear ( )
85
+ queryClientV5 . clear ( )
98
86
server . resetHandlers ( )
99
87
} )
100
88
@@ -109,7 +97,7 @@ interface SetupArgs {
109
97
isNullOwner ?: boolean
110
98
}
111
99
112
- describe ( 'useCoverageTabData ' , ( ) => {
100
+ describe ( 'CoverageTabDataQueryOpts ' , ( ) => {
113
101
function setup ( {
114
102
isNotFoundError = false ,
115
103
isOwnerNotActivatedError = false ,
@@ -129,73 +117,40 @@ describe('useCoverageTabData', () => {
129
117
} else {
130
118
return HttpResponse . json ( { data : mockCoverageTabData } )
131
119
}
132
- } ) ,
133
- graphql . query ( 'GetRepoOverview' , ( ) => {
134
- return HttpResponse . json ( { data : mockOverview } )
135
120
} )
136
121
)
137
122
}
138
123
139
124
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 ( {
146
131
provider : 'gh' ,
147
132
owner : 'codecov' ,
148
133
repo : 'cool-repo' ,
149
134
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
+ )
183
139
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 ,
193
148
} ,
194
149
} ,
195
150
} ,
196
- } )
197
- )
198
- } )
151
+ } ,
152
+ } )
153
+ )
199
154
} )
200
155
} )
201
156
@@ -214,12 +169,14 @@ describe('useCoverageTabData', () => {
214
169
setup ( { isNotFoundError : true } )
215
170
const { result } = renderHook (
216
171
( ) =>
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
+ ) ,
223
180
{ wrapper : wrapper ( ) }
224
181
)
225
182
@@ -250,12 +207,14 @@ describe('useCoverageTabData', () => {
250
207
setup ( { isOwnerNotActivatedError : true } )
251
208
const { result } = renderHook (
252
209
( ) =>
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
+ ) ,
259
218
{ wrapper : wrapper ( ) }
260
219
)
261
220
@@ -286,12 +245,14 @@ describe('useCoverageTabData', () => {
286
245
setup ( { isUnsuccessfulParseError : true } )
287
246
const { result } = renderHook (
288
247
( ) =>
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
+ ) ,
295
256
{ wrapper : wrapper ( ) }
296
257
)
297
258
0 commit comments