1
1
import { QueryClient , QueryClientProvider } from '@tanstack/react-query'
2
+ import {
3
+ QueryClientProvider as QueryClientProviderV5 ,
4
+ QueryClient as QueryClientV5 ,
5
+ } from '@tanstack/react-queryV5'
2
6
import { render , screen } from '@testing-library/react'
3
7
import { graphql , HttpResponse } from 'msw'
4
8
import { setupServer } from 'msw/node'
9
+ import { Suspense } from 'react'
5
10
import { MemoryRouter , Route } from 'react-router-dom'
6
11
7
12
import { TierNames } from 'services/tier'
@@ -24,35 +29,54 @@ vi.mock('./DefaultBranch', () => ({
24
29
const queryClient = new QueryClient ( {
25
30
defaultOptions : { queries : { retry : false } } ,
26
31
} )
27
- const server = setupServer ( )
32
+ const queryClientV5 = new QueryClientV5 ( {
33
+ defaultOptions : { queries : { retry : false } } ,
34
+ } )
28
35
29
- const wrapper = ( { children } ) => (
30
- < QueryClientProvider client = { queryClient } >
31
- < MemoryRouter initialEntries = { [ '/gh/codecov/codecov-client/config' ] } >
32
- < Route path = "/:provider/:owner/:repo/config" > { children } </ Route >
33
- </ MemoryRouter >
34
- </ QueryClientProvider >
36
+ const wrapper : React . FC < React . PropsWithChildren > = ( { children } ) => (
37
+ < QueryClientProviderV5 client = { queryClientV5 } >
38
+ < QueryClientProvider client = { queryClient } >
39
+ < MemoryRouter initialEntries = { [ '/gh/codecov/codecov-client/config' ] } >
40
+ < Route path = "/:provider/:owner/:repo/config" >
41
+ < Suspense fallback = { < p > Loading</ p > } > { children } </ Suspense >
42
+ </ Route >
43
+ </ MemoryRouter >
44
+ </ QueryClientProvider >
45
+ </ QueryClientProviderV5 >
35
46
)
36
47
48
+ const server = setupServer ( )
37
49
beforeAll ( ( ) => {
38
50
server . listen ( )
39
51
console . error = ( ) => { }
40
52
} )
53
+
41
54
afterEach ( ( ) => {
42
55
queryClient . clear ( )
56
+ queryClientV5 . clear ( )
43
57
server . resetHandlers ( )
44
58
} )
45
- afterAll ( ( ) => server . close ( ) )
59
+
60
+ afterAll ( ( ) => {
61
+ server . close ( )
62
+ } )
63
+
64
+ interface SetupArgs {
65
+ hasDefaultBranch ?: boolean
66
+ tierValue ?: ( typeof TierNames ) [ keyof typeof TierNames ]
67
+ isPrivate ?: boolean
68
+ }
46
69
47
70
describe ( 'GeneralTab' , ( ) => {
48
71
function setup (
49
72
{
50
73
hasDefaultBranch = false ,
51
74
tierValue = TierNames . PRO ,
52
75
isPrivate = false ,
53
- } = {
76
+ } : SetupArgs = {
54
77
hasDefaultBranch : false ,
55
78
tierValue : TierNames . PRO ,
79
+ isPrivate : false ,
56
80
}
57
81
) {
58
82
server . use (
@@ -122,19 +146,19 @@ describe('GeneralTab', () => {
122
146
} )
123
147
} )
124
148
125
- it ( 'render tokens component' , ( ) => {
149
+ it ( 'render tokens component' , async ( ) => {
126
150
setup ( { tierValue : TierNames . TEAM } )
127
151
render ( < GeneralTab /> , { wrapper } )
128
152
129
- const tokensComponent = screen . getByText ( / T o k e n s C o m p o n e n t / )
153
+ const tokensComponent = await screen . findByText ( / T o k e n s C o m p o n e n t / )
130
154
expect ( tokensComponent ) . toBeInTheDocument ( )
131
155
} )
132
156
133
- it ( 'render danger zone component' , ( ) => {
157
+ it ( 'render danger zone component' , async ( ) => {
134
158
setup ( { tierValue : TierNames . TEAM } )
135
159
render ( < GeneralTab /> , { wrapper } )
136
160
137
- const tokensComponent = screen . getByText ( / D a n g e r Z o n e C o m p o n e n t / )
161
+ const tokensComponent = await screen . findByText ( / D a n g e r Z o n e C o m p o n e n t / )
138
162
expect ( tokensComponent ) . toBeInTheDocument ( )
139
163
} )
140
164
} )
@@ -152,10 +176,10 @@ describe('GeneralTab', () => {
152
176
expect ( tokensComponent ) . toBeInTheDocument ( )
153
177
} )
154
178
155
- it ( 'render danger zone component' , ( ) => {
179
+ it ( 'render danger zone component' , async ( ) => {
156
180
render ( < GeneralTab /> , { wrapper } )
157
181
158
- const tokensComponent = screen . getByText ( / D a n g e r Z o n e C o m p o n e n t / )
182
+ const tokensComponent = await screen . findByText ( / D a n g e r Z o n e C o m p o n e n t / )
159
183
expect ( tokensComponent ) . toBeInTheDocument ( )
160
184
} )
161
185
} )
@@ -165,17 +189,17 @@ describe('GeneralTab', () => {
165
189
setup ( { tierValue : TierNames . TEAM , isPrivate : false } )
166
190
} )
167
191
168
- it ( 'render tokens component' , ( ) => {
192
+ it ( 'render tokens component' , async ( ) => {
169
193
render ( < GeneralTab /> , { wrapper } )
170
194
171
- const tokensComponent = screen . getByText ( / T o k e n s C o m p o n e n t / )
195
+ const tokensComponent = await screen . findByText ( / T o k e n s C o m p o n e n t / )
172
196
expect ( tokensComponent ) . toBeInTheDocument ( )
173
197
} )
174
198
175
- it ( 'render danger zone component' , ( ) => {
199
+ it ( 'render danger zone component' , async ( ) => {
176
200
render ( < GeneralTab /> , { wrapper } )
177
201
178
- const tokensComponent = screen . getByText ( / D a n g e r Z o n e C o m p o n e n t / )
202
+ const tokensComponent = await screen . findByText ( / D a n g e r Z o n e C o m p o n e n t / )
179
203
expect ( tokensComponent ) . toBeInTheDocument ( )
180
204
} )
181
205
} )
0 commit comments