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 , waitFor } from '@testing-library/react'
3
7
import { graphql , HttpResponse } from 'msw'
4
8
import { setupServer } from 'msw/node'
@@ -10,31 +14,23 @@ vi.mock('./ComponentsNotConfigured', () => ({
10
14
default : ( ) => 'ComponentsNotConfigured' ,
11
15
} ) )
12
16
13
- const queryClient = new QueryClient ( )
14
- const server = setupServer ( )
15
-
16
- const wrapper =
17
- ( initialEntries = '/gh/codecov/gazebo/pull/123/components' ) =>
18
- ( { children } ) => (
19
- < QueryClientProvider client = { queryClient } >
20
- < MemoryRouter initialEntries = { [ initialEntries ] } >
21
- < Route path = "/:provider/:owner/:repo/pull/:pullId/components" >
22
- { children }
23
- </ Route >
24
- </ MemoryRouter >
25
- </ QueryClientProvider >
26
- )
27
-
28
- beforeAll ( ( ) => {
29
- server . listen ( )
30
- } )
31
- afterEach ( ( ) => {
32
- queryClient . clear ( )
33
- server . resetHandlers ( )
34
- } )
35
- afterAll ( ( ) => {
36
- server . close ( )
37
- } )
17
+ const mockPullComponentsResponse = {
18
+ owner : {
19
+ repository : {
20
+ __typename : 'Repository' ,
21
+ pull : {
22
+ compareWithBase : {
23
+ __typename : 'Comparison' ,
24
+ componentComparisons : [
25
+ { name : 'component-1' } ,
26
+ { name : 'component-2' } ,
27
+ { name : 'component-3' } ,
28
+ ] ,
29
+ } ,
30
+ } ,
31
+ } ,
32
+ } ,
33
+ }
38
34
39
35
const mockPull = {
40
36
owner : {
@@ -46,26 +42,52 @@ const mockPull = {
46
42
componentComparisons : [
47
43
{
48
44
name : 'secondTest' ,
49
- headTotals : {
50
- percentCovered : 82.71 ,
51
- } ,
52
- baseTotals : {
53
- percentCovered : 80.0 ,
54
- } ,
55
- patchTotals : {
56
- percentCovered : 59.0 ,
57
- } ,
45
+ headTotals : { percentCovered : 82.71 } ,
46
+ baseTotals : { percentCovered : 80.0 } ,
47
+ patchTotals : { percentCovered : 59.0 } ,
58
48
} ,
59
49
] ,
60
50
} ,
61
- head : {
62
- branchName : 'abc' ,
63
- } ,
51
+ head : { branchName : 'abc' } ,
64
52
} ,
65
53
} ,
66
54
} ,
67
55
}
68
56
57
+ const server = setupServer ( )
58
+ const queryClient = new QueryClient ( {
59
+ defaultOptions : { queries : { retry : false } } ,
60
+ } )
61
+ const queryClientV5 = new QueryClientV5 ( {
62
+ defaultOptions : { queries : { retry : false } } ,
63
+ } )
64
+
65
+ const wrapper =
66
+ ( initialEntries = '/gh/codecov/gazebo/pull/123/components' ) =>
67
+ ( { children } ) => (
68
+ < QueryClientProviderV5 client = { queryClientV5 } >
69
+ < QueryClientProvider client = { queryClient } >
70
+ < MemoryRouter initialEntries = { [ initialEntries ] } >
71
+ < Route path = "/:provider/:owner/:repo/pull/:pullId/components" >
72
+ { children }
73
+ </ Route >
74
+ </ MemoryRouter >
75
+ </ QueryClientProvider >
76
+ </ QueryClientProviderV5 >
77
+ )
78
+
79
+ beforeAll ( ( ) => {
80
+ server . listen ( )
81
+ } )
82
+ afterEach ( ( ) => {
83
+ queryClient . clear ( )
84
+ queryClientV5 . clear ( )
85
+ server . resetHandlers ( )
86
+ } )
87
+ afterAll ( ( ) => {
88
+ server . close ( )
89
+ } )
90
+
69
91
describe ( 'ComponentsTable' , ( ) => {
70
92
function setup ( overrideData ) {
71
93
const componentsMock = vi . fn ( )
@@ -79,22 +101,19 @@ describe('ComponentsTable', () => {
79
101
if ( overrideData ) {
80
102
return HttpResponse . json ( { data : overrideData } )
81
103
}
82
-
83
104
return HttpResponse . json ( { data : mockPull } )
105
+ } ) ,
106
+ graphql . query ( 'PullComponentsSelector' , ( ) => {
107
+ return HttpResponse . json ( { data : mockPullComponentsResponse } )
84
108
} )
85
109
)
86
110
87
111
return { componentsMock }
88
112
}
89
113
90
114
describe ( 'when there are no components in the new tab' , ( ) => {
91
- beforeEach ( ( ) => {
92
- setup ( {
93
- owner : null ,
94
- } )
95
- } )
96
-
97
115
it ( 'will render card with no dismiss button' , async ( ) => {
116
+ setup ( { owner : null } )
98
117
render ( < ComponentsTable /> , { wrapper : wrapper ( ) } )
99
118
100
119
const componentNotConfigured = await screen . findByText (
@@ -105,11 +124,8 @@ describe('ComponentsTable', () => {
105
124
} )
106
125
107
126
describe ( 'when rendered with populated data in the new tab' , ( ) => {
108
- beforeEach ( ( ) => {
109
- setup ( )
110
- } )
111
-
112
127
it ( 'shows title and body' , async ( ) => {
128
+ setup ( )
113
129
render ( < ComponentsTable /> , { wrapper : wrapper ( ) } )
114
130
115
131
const nameTableField = await screen . findByText ( `Name` )
@@ -158,6 +174,7 @@ describe('ComponentsTable', () => {
158
174
159
175
describe ( 'when loading' , ( ) => {
160
176
it ( 'renders spinner' , ( ) => {
177
+ setup ( )
161
178
render ( < ComponentsTable /> , { wrapper : wrapper ( ) } )
162
179
163
180
const spinner = screen . getByTestId ( 'spinner' )
0 commit comments