Skip to content

Commit 9531248

Browse files
committed
feat: add all branches option to TA branch selector
we want to allow users to not filter by any specific branch and aggregate the results from all branches we also want to make this the default option when users land on the tests tab from now on i'm putting this behind a feature flag because the backend is not capable of serving this data yet since it relies on the TA timescale data migration
1 parent cea4ae6 commit 9531248

File tree

9 files changed

+390
-50
lines changed

9 files changed

+390
-50
lines changed

src/pages/RepoPage/FailedTestsTab/FailedTestsPage/FailedTestsTable/FailedTestsTable.test.tsx

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,19 @@ vi.mock('../TableHeader/TableHeader', () => ({
2424
default: () => 'Table Header',
2525
}))
2626

27+
const mocks = vi.hoisted(() => ({
28+
useFlags: vi.fn(() => ({ allBranchesEnabled: false })),
29+
}))
30+
31+
vi.mock('shared/featureFlags', async () => {
32+
const actual = await vi.importActual('shared/featureFlags')
33+
34+
return {
35+
...actual,
36+
useFlags: mocks.useFlags,
37+
}
38+
})
39+
2740
const node1 = {
2841
updatedAt: '2023-01-01T00:00:00Z',
2942
name: 'test-1',
@@ -139,7 +152,12 @@ interface SetupArgs {
139152
isFirstPullRequest?: boolean
140153
}
141154

142-
describe('FailedTestsTable', () => {
155+
describe.each([true, false])('FailedTestsTable', (allBranchesEnabled) => {
156+
beforeEach(() => {
157+
queryClient.clear()
158+
mocks.useFlags.mockReturnValue({ allBranchesEnabled })
159+
})
160+
143161
function setup({
144162
noEntries = false,
145163
planValue = Plans.USERS_ENTERPRISEM,

src/pages/RepoPage/FailedTestsTab/FailedTestsPage/FailedTestsTable/FailedTestsTable.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { useInView } from 'react-intersection-observer'
1414
import { useLocation, useParams } from 'react-router-dom'
1515

1616
import { MeasurementInterval } from 'pages/RepoPage/shared/constants'
17+
import { ALL_BRANCHES } from 'services/navigation/useNavLinks'
1718
import { formatTimeToNow } from 'shared/utils/dates'
1819
import Icon from 'ui/Icon'
1920
import Spinner from 'ui/Spinner'
@@ -226,7 +227,8 @@ const FailedTestsTable = () => {
226227
},
227228
})
228229

229-
const isDefaultBranch = testData?.defaultBranch === branch
230+
const isDefaultBranch =
231+
testData?.defaultBranch === branch || ALL_BRANCHES === branch
230232
const isTeamOrFreePlan = testData?.isTeamPlan || testData?.isFreePlan
231233
// Only show flake rate column when on default branch for pro / enterprise plans or public repos
232234
const hideFlakeRate =
@@ -308,7 +310,8 @@ const FailedTestsTable = () => {
308310
<div className="mt-4 text-center text-ds-gray-quinary">
309311
<p>No data yet</p>
310312
<p>
311-
To see data for the main branch, merge your PR into the main branch.
313+
To see data for the {testData?.defaultBranch} branch, merge your PR
314+
into the {testData?.defaultBranch} branch.
312315
</p>
313316
</div>
314317
</div>

src/pages/RepoPage/FailedTestsTab/FailedTestsPage/MetricsSection/MetricsSection.test.tsx

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ import MetricsSection, { historicalTrendToCopy } from './MetricsSection'
1212

1313
import { TestResultsFilterParameter } from '../hooks/useInfiniteTestResults/useInfiniteTestResults'
1414

15+
vi.mock('shared/featureFlags', async () => {
16+
const actual = await vi.importActual('shared/featureFlags')
17+
18+
return {
19+
...actual,
20+
useFlags: vi.fn(() => ({ allBranchesEnabled: false })),
21+
}
22+
})
23+
1524
const mockAggResponse = (
1625
planValue: PlanName = Plans.USERS_ENTERPRISEM,
1726
isPrivate = false
@@ -148,11 +157,14 @@ describe('MetricsSection', () => {
148157
})
149158
})
150159

151-
describe('when on default branch', () => {
160+
describe.each([
161+
['default branch', 'main'],
162+
['all branches', 'All%20branches'],
163+
])('when on %s', (_, encodedBranch) => {
152164
it('renders subheaders', async () => {
153165
setup()
154166
render(<MetricsSection />, {
155-
wrapper: wrapper('/gh/owner/repo/tests/main'),
167+
wrapper: wrapper(`/gh/owner/repo/tests/${encodedBranch}`),
156168
})
157169

158170
const runEfficiency = await screen.findByText('Improve CI Run Efficiency')
@@ -164,7 +176,7 @@ describe('MetricsSection', () => {
164176
it('renders total test runtime card', async () => {
165177
setup()
166178
render(<MetricsSection />, {
167-
wrapper: wrapper('/gh/owner/repo/tests/main'),
179+
wrapper: wrapper(`/gh/owner/repo/tests/${encodedBranch}`),
168180
})
169181

170182
const title = await screen.findByText('Total test run time')
@@ -182,7 +194,7 @@ describe('MetricsSection', () => {
182194
it('renders slowest tests card', async () => {
183195
setup()
184196
render(<MetricsSection />, {
185-
wrapper: wrapper('/gh/owner/repo/tests/main'),
197+
wrapper: wrapper(`/gh/owner/repo/tests/${encodedBranch}`),
186198
})
187199

188200
const title = await screen.findByText('Slowest tests')
@@ -199,7 +211,7 @@ describe('MetricsSection', () => {
199211
it('can update the location params on button click', async () => {
200212
const { user } = setup()
201213
render(<MetricsSection />, {
202-
wrapper: wrapper('/gh/owner/repo/tests/main'),
214+
wrapper: wrapper(`/gh/owner/repo/tests/${encodedBranch}`),
203215
})
204216
const select = await screen.findByText('12')
205217
expect(select).toBeInTheDocument()
@@ -217,7 +229,7 @@ describe('MetricsSection', () => {
217229
it('removes the location param on second button click', async () => {
218230
const { user } = setup()
219231
render(<MetricsSection />, {
220-
wrapper: wrapper('/gh/owner/repo/tests/main'),
232+
wrapper: wrapper(`/gh/owner/repo/tests/${encodedBranch}`),
221233
})
222234
const select = await screen.findByText('12')
223235
expect(select).toBeInTheDocument()
@@ -239,7 +251,7 @@ describe('MetricsSection', () => {
239251
it('renders total flaky tests card', async () => {
240252
setup()
241253
render(<MetricsSection />, {
242-
wrapper: wrapper('/gh/owner/repo/tests/main'),
254+
wrapper: wrapper(`/gh/owner/repo/tests/${encodedBranch}`),
243255
})
244256

245257
const title = await screen.findByText('Flaky tests')
@@ -256,7 +268,7 @@ describe('MetricsSection', () => {
256268
it('can update the location params on button click', async () => {
257269
const { user } = setup()
258270
render(<MetricsSection />, {
259-
wrapper: wrapper('/gh/owner/repo/tests/main'),
271+
wrapper: wrapper(`/gh/owner/repo/tests/${encodedBranch}`),
260272
})
261273
const select = await screen.findByText(88)
262274
expect(select).toBeInTheDocument()
@@ -274,7 +286,7 @@ describe('MetricsSection', () => {
274286
it('removes the location param on second button click', async () => {
275287
const { user } = setup()
276288
render(<MetricsSection />, {
277-
wrapper: wrapper('/gh/owner/repo/tests/main'),
289+
wrapper: wrapper(`/gh/owner/repo/tests/${encodedBranch}`),
278290
})
279291
const select = await screen.findByText(88)
280292
expect(select).toBeInTheDocument()
@@ -313,7 +325,7 @@ describe('MetricsSection', () => {
313325
it('renders total failures card', async () => {
314326
setup()
315327
render(<MetricsSection />, {
316-
wrapper: wrapper('/gh/owner/repo/tests/main'),
328+
wrapper: wrapper(`/gh/owner/repo/tests/${encodedBranch}`),
317329
})
318330

319331
const title = await screen.findByText('Cumulative Failures')
@@ -330,7 +342,7 @@ describe('MetricsSection', () => {
330342
it('can update the location params on button click', async () => {
331343
const { user } = setup()
332344
render(<MetricsSection />, {
333-
wrapper: wrapper('/gh/owner/repo/tests/main'),
345+
wrapper: wrapper(`/gh/owner/repo/tests/${encodedBranch}`),
334346
})
335347
const select = await screen.findByText(1)
336348
expect(select).toBeInTheDocument()
@@ -370,7 +382,7 @@ describe('MetricsSection', () => {
370382
it('renders total skips card', async () => {
371383
setup()
372384
render(<MetricsSection />, {
373-
wrapper: wrapper('/gh/owner/repo/tests/main'),
385+
wrapper: wrapper(`/gh/owner/repo/tests/${encodedBranch}`),
374386
})
375387

376388
const title = await screen.findByText('Skipped tests')
@@ -387,7 +399,7 @@ describe('MetricsSection', () => {
387399
it('can update the location params on button click', async () => {
388400
const { user } = setup()
389401
render(<MetricsSection />, {
390-
wrapper: wrapper('/gh/owner/repo/tests/main'),
402+
wrapper: wrapper(`/gh/owner/repo/tests/${encodedBranch}`),
391403
})
392404
const select = await screen.findByText(20)
393405
expect(select).toBeInTheDocument()
@@ -405,7 +417,7 @@ describe('MetricsSection', () => {
405417
it('removes the location param on second button click', async () => {
406418
const { user } = setup()
407419
render(<MetricsSection />, {
408-
wrapper: wrapper('/gh/owner/repo/tests/main'),
420+
wrapper: wrapper(`/gh/owner/repo/tests/${encodedBranch}`),
409421
})
410422
const select = await screen.findByText(20)
411423
expect(select).toBeInTheDocument()

src/pages/RepoPage/FailedTestsTab/FailedTestsPage/MetricsSection/MetricsSection.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { useLocation, useParams } from 'react-router-dom'
33

44
import { MeasurementInterval } from 'pages/RepoPage/shared/constants'
55
import { useLocationParams } from 'services/navigation/useLocationParams'
6+
import { ALL_BRANCHES } from 'services/navigation/useNavLinks'
67
import { cn } from 'shared/utils/cn'
78
import { formatTimeFromSeconds } from 'shared/utils/dates'
89
import Badge from 'ui/Badge'
@@ -379,7 +380,10 @@ function MetricsSection() {
379380
const decodedBranch = getDecodedBranch(branch)
380381
const selectedBranch = decodedBranch ?? testResults?.defaultBranch ?? ''
381382

382-
if (selectedBranch !== testResults?.defaultBranch) {
383+
if (
384+
selectedBranch !== testResults?.defaultBranch &&
385+
selectedBranch !== ALL_BRANCHES
386+
) {
383387
return null
384388
}
385389

0 commit comments

Comments
 (0)