Skip to content

Commit ba50b98

Browse files
authored
feat: Use new chart library for overview tab (#3465)
1 parent 416c9f5 commit ba50b98

15 files changed

+770
-853
lines changed

src/pages/RepoPage/CoverageTab/OverviewTab/OverviewTab.test.tsx

Lines changed: 58 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,31 @@ import { render, screen } from '@testing-library/react'
33
import { graphql, http, HttpResponse } from 'msw'
44
import { setupServer } from 'msw/node'
55
import { MemoryRouter, Route } from 'react-router-dom'
6+
import { type Mock } from 'vitest'
67

78
import { TierNames, TTierNames } from 'services/tier'
89

910
import CoverageOverviewTab from './OverviewTab'
1011

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+
1131
vi.mock('./Summary', () => ({ default: () => 'Summary' }))
1232
vi.mock('./SummaryTeamPlan', () => ({ default: () => 'SummaryTeamPlan' }))
1333
vi.mock('./subroute/Sunburst', () => ({ default: () => 'Sunburst' }))
@@ -104,30 +124,9 @@ const branchesMock = {
104124
__typename: 'Repository',
105125
branches: {
106126
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' } } },
131130
],
132131
pageInfo: {
133132
hasNextPage: false,
@@ -188,22 +187,10 @@ const mockBranchMeasurements = {
188187
__typename: 'Repository',
189188
coverageAnalytics: {
190189
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 },
207194
],
208195
},
209196
},
@@ -230,15 +217,7 @@ const mockCoverageTabData = (fileCount = 10) => ({
230217
owner: {
231218
repository: {
232219
__typename: 'Repository',
233-
branch: {
234-
head: {
235-
coverageAnalytics: {
236-
totals: {
237-
fileCount,
238-
},
239-
},
240-
},
241-
},
220+
branch: { head: { coverageAnalytics: { totals: { fileCount } } } },
242221
},
243222
},
244223
})
@@ -253,14 +232,8 @@ const mockBranchComponents = {
253232
commitid: 'commit-123',
254233
coverageAnalytics: {
255234
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' },
264237
],
265238
},
266239
},
@@ -274,17 +247,8 @@ const mockFlagSelect = {
274247
repository: {
275248
__typename: 'Repository',
276249
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' },
288252
},
289253
},
290254
},
@@ -331,6 +295,30 @@ beforeAll(() => {
331295
server.listen({ onUnhandledRequest: 'warn' })
332296
})
333297

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+
334322
afterEach(() => {
335323
queryClient.clear()
336324
server.resetHandlers()
@@ -467,7 +455,7 @@ describe('Coverage overview tab', () => {
467455
wrapper: wrapper(['/gh/test-org/repoName']),
468456
})
469457

470-
const coverageAreaChart = await screen.findByTestId('coverage-area-chart')
458+
const coverageAreaChart = await screen.findByTestId('chart-container')
471459
expect(coverageAreaChart).toBeInTheDocument()
472460
})
473461

@@ -490,7 +478,7 @@ describe('Coverage overview tab', () => {
490478
wrapper: wrapper(['/gh/test-org/repoName']),
491479
})
492480

493-
const coverageChart = screen.queryByTestId('coverage-area-chart')
481+
const coverageChart = screen.queryByTestId('chart-container')
494482
expect(coverageChart).not.toBeInTheDocument()
495483
})
496484
})

src/pages/RepoPage/CoverageTab/OverviewTab/OverviewTab.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ function CoverageOverviewTab() {
9090
<div
9191
className={cn('inline-table', {
9292
'col-span-9': displaySunburst,
93-
'col-span-12 h-[21rem]': !displaySunburst,
93+
'col-span-12': !displaySunburst,
9494
})}
9595
>
9696
<SilentNetworkErrorWrapper>
97-
<CoverageChart extendedChart={!displaySunburst} />
97+
<CoverageChart />
9898
</SilentNetworkErrorWrapper>
9999
</div>
100100
{displaySunburst ? (

src/pages/RepoPage/CoverageTab/OverviewTab/hooks/useRepoCoverageTimeseries.js

Lines changed: 0 additions & 93 deletions
This file was deleted.

0 commit comments

Comments
 (0)