@@ -3,11 +3,31 @@ import { render, screen } from '@testing-library/react'
3
3
import { graphql , http , HttpResponse } from 'msw'
4
4
import { setupServer } from 'msw/node'
5
5
import { MemoryRouter , Route } from 'react-router-dom'
6
+ import { type Mock } from 'vitest'
6
7
7
8
import { TierNames , TTierNames } from 'services/tier'
8
9
9
10
import CoverageOverviewTab from './OverviewTab'
10
11
12
+ declare global {
13
+ interface Window {
14
+ ResizeObserver : unknown
15
+ }
16
+ }
17
+
18
+ vi . mock ( 'recharts' , async ( ) => {
19
+ const OriginalModule = await vi . importActual ( 'recharts' )
20
+ return {
21
+ ...OriginalModule ,
22
+ ResponsiveContainer : ( { children } : { children : React . ReactNode } ) => (
23
+ // @ts -expect-error - something is off with the import actual but this does exist, and this mock does work
24
+ < OriginalModule . ResponsiveContainer width = { 800 } height = { 800 } >
25
+ { children }
26
+ </ OriginalModule . ResponsiveContainer >
27
+ ) ,
28
+ }
29
+ } )
30
+
11
31
vi . mock ( './Summary' , ( ) => ( { default : ( ) => 'Summary' } ) )
12
32
vi . mock ( './SummaryTeamPlan' , ( ) => ( { default : ( ) => 'SummaryTeamPlan' } ) )
13
33
vi . mock ( './subroute/Sunburst' , ( ) => ( { default : ( ) => 'Sunburst' } ) )
@@ -104,30 +124,9 @@ const branchesMock = {
104
124
__typename : 'Repository' ,
105
125
branches : {
106
126
edges : [
107
- {
108
- node : {
109
- name : 'main' ,
110
- head : {
111
- commitid : '1' ,
112
- } ,
113
- } ,
114
- } ,
115
- {
116
- node : {
117
- name : 'dummy' ,
118
- head : {
119
- commitid : '2' ,
120
- } ,
121
- } ,
122
- } ,
123
- {
124
- node : {
125
- name : 'dummy2' ,
126
- head : {
127
- commitid : '3' ,
128
- } ,
129
- } ,
130
- } ,
127
+ { node : { name : 'main' , head : { commitid : '1' } } } ,
128
+ { node : { name : 'dummy' , head : { commitid : '2' } } } ,
129
+ { node : { name : 'dummy2' , head : { commitid : '3' } } } ,
131
130
] ,
132
131
pageInfo : {
133
132
hasNextPage : false ,
@@ -188,22 +187,10 @@ const mockBranchMeasurements = {
188
187
__typename : 'Repository' ,
189
188
coverageAnalytics : {
190
189
measurements : [
191
- {
192
- timestamp : '2023-01-01T00:00:00+00:00' ,
193
- max : 85 ,
194
- } ,
195
- {
196
- timestamp : '2023-01-02T00:00:00+00:00' ,
197
- max : 80 ,
198
- } ,
199
- {
200
- timestamp : '2023-01-03T00:00:00+00:00' ,
201
- max : 90 ,
202
- } ,
203
- {
204
- timestamp : '2023-01-04T00:00:00+00:00' ,
205
- max : 100 ,
206
- } ,
190
+ { timestamp : '2023-01-01T00:00:00+00:00' , max : 85 } ,
191
+ { timestamp : '2023-01-02T00:00:00+00:00' , max : 80 } ,
192
+ { timestamp : '2023-01-03T00:00:00+00:00' , max : 90 } ,
193
+ { timestamp : '2023-01-04T00:00:00+00:00' , max : 100 } ,
207
194
] ,
208
195
} ,
209
196
} ,
@@ -230,15 +217,7 @@ const mockCoverageTabData = (fileCount = 10) => ({
230
217
owner : {
231
218
repository : {
232
219
__typename : 'Repository' ,
233
- branch : {
234
- head : {
235
- coverageAnalytics : {
236
- totals : {
237
- fileCount,
238
- } ,
239
- } ,
240
- } ,
241
- } ,
220
+ branch : { head : { coverageAnalytics : { totals : { fileCount } } } } ,
242
221
} ,
243
222
} ,
244
223
} )
@@ -253,14 +232,8 @@ const mockBranchComponents = {
253
232
commitid : 'commit-123' ,
254
233
coverageAnalytics : {
255
234
components : [
256
- {
257
- id : 'compOneId' ,
258
- name : 'compOneName' ,
259
- } ,
260
- {
261
- id : 'compTwoId' ,
262
- name : 'compTwoName' ,
263
- } ,
235
+ { id : 'compOneId' , name : 'compOneName' } ,
236
+ { id : 'compTwoId' , name : 'compTwoName' } ,
264
237
] ,
265
238
} ,
266
239
} ,
@@ -274,17 +247,8 @@ const mockFlagSelect = {
274
247
repository : {
275
248
__typename : 'Repository' ,
276
249
flags : {
277
- edges : [
278
- {
279
- node : {
280
- name : 'flag-1' ,
281
- } ,
282
- } ,
283
- ] ,
284
- pageInfo : {
285
- hasNextPage : true ,
286
- endCursor : '1-flag-1' ,
287
- } ,
250
+ edges : [ { node : { name : 'flag-1' } } ] ,
251
+ pageInfo : { hasNextPage : true , endCursor : '1-flag-1' } ,
288
252
} ,
289
253
} ,
290
254
} ,
@@ -331,6 +295,30 @@ beforeAll(() => {
331
295
server . listen ( { onUnhandledRequest : 'warn' } )
332
296
} )
333
297
298
+ beforeEach ( ( ) => {
299
+ let resizeObserverMock : Mock
300
+ /**
301
+ * ResizeObserver is not available, so we have to create a mock to avoid error coming
302
+ * from `react-resize-detector`.
303
+ * @see https://github.com/maslianok/react-resize-detector/issues/145
304
+ *
305
+ * This mock also allow us to use {@link notifyResizeObserverChange} to fire changes
306
+ * from inside our test.
307
+ */
308
+ resizeObserverMock = vi . fn ( ) . mockImplementation ( ( callback ) => {
309
+ return {
310
+ observe : vi . fn ( ) ,
311
+ unobserve : vi . fn ( ) ,
312
+ disconnect : vi . fn ( ) ,
313
+ }
314
+ } )
315
+
316
+ // @ts -ignore
317
+ delete window . ResizeObserver
318
+
319
+ window . ResizeObserver = resizeObserverMock
320
+ } )
321
+
334
322
afterEach ( ( ) => {
335
323
queryClient . clear ( )
336
324
server . resetHandlers ( )
@@ -467,7 +455,7 @@ describe('Coverage overview tab', () => {
467
455
wrapper : wrapper ( [ '/gh/test-org/repoName' ] ) ,
468
456
} )
469
457
470
- const coverageAreaChart = await screen . findByTestId ( 'coverage-area- chart' )
458
+ const coverageAreaChart = await screen . findByTestId ( 'chart-container ' )
471
459
expect ( coverageAreaChart ) . toBeInTheDocument ( )
472
460
} )
473
461
@@ -490,7 +478,7 @@ describe('Coverage overview tab', () => {
490
478
wrapper : wrapper ( [ '/gh/test-org/repoName' ] ) ,
491
479
} )
492
480
493
- const coverageChart = screen . queryByTestId ( 'coverage-area- chart' )
481
+ const coverageChart = screen . queryByTestId ( 'chart-container ' )
494
482
expect ( coverageChart ) . not . toBeInTheDocument ( )
495
483
} )
496
484
} )
0 commit comments