Skip to content

Commit 8816d1e

Browse files
authored
feat: add all branches as default capability to test analytics page (#3928)
1 parent f7c59cf commit 8816d1e

File tree

8 files changed

+54
-36
lines changed

8 files changed

+54
-36
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ const FailedTestsTable = () => {
222222
repo,
223223
ordering: getSortingOption(sorting),
224224
filters: {
225-
branch: branch ? getDecodedBranch(branch) : undefined,
225+
branch: branch ? getDecodedBranch(branch) : null,
226226
flags: flags as string[],
227227
// eslint-disable-next-line camelcase
228228
test_suites: testSuites as string[],

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -363,22 +363,27 @@ function MetricsSection() {
363363
depth: 1,
364364
})
365365

366+
const decodedBranch = getDecodedBranch(branch)
367+
const selectedBranch = decodedBranch ?? null
368+
366369
const { data: testResults } = useTestResultsAggregates({
367370
interval: queryParams?.historicalTrend as MeasurementInterval,
371+
branch: selectedBranch,
368372
})
369373
const disabledFlakeAggregates =
370374
(testResults?.isTeamPlan || testResults?.isFreePlan) && testResults?.private
371375
const { data: flakeAggregates } = useFlakeAggregates({
372376
interval: queryParams?.historicalTrend as MeasurementInterval,
377+
branch: selectedBranch,
373378
opts: {
374379
enabled: !disabledFlakeAggregates,
375380
},
376381
})
377382

378-
const decodedBranch = getDecodedBranch(branch)
379-
const selectedBranch = decodedBranch ?? testResults?.defaultBranch ?? ''
380-
381-
if (selectedBranch !== testResults?.defaultBranch) {
383+
if (
384+
selectedBranch !== testResults?.defaultBranch &&
385+
selectedBranch !== null
386+
) {
382387
return null
383388
}
384389

src/pages/RepoPage/FailedTestsTab/FailedTestsPage/SelectorSection/BranchSelector/BranchSelector.test.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -235,27 +235,27 @@ describe('BranchSelector', () => {
235235
expect(branchContext).toBeInTheDocument()
236236
})
237237

238-
it('renders default branch as selected branch', async () => {
238+
it('renders all branches as default selected option', async () => {
239239
const { queryClient } = setup()
240240
render(<BranchSelector />, {
241241
wrapper: wrapper(queryClient),
242242
})
243243

244-
const dropDownBtn = await screen.findByText('main')
244+
const dropDownBtn = await screen.findByText('All Branches')
245245
expect(dropDownBtn).toBeInTheDocument()
246246
})
247247
})
248248

249249
describe('navigating branches', () => {
250250
describe('user lands on the page', () => {
251-
it('redirects to the default branch', async () => {
251+
it('redirects to /tests', async () => {
252252
const { queryClient } = setup()
253253
render(<BranchSelector />, {
254254
wrapper: wrapper(queryClient),
255255
})
256256

257257
await waitFor(() =>
258-
expect(testLocation.pathname).toBe('/gh/codecov/test-repo/tests/main')
258+
expect(testLocation.pathname).toBe('/gh/codecov/test-repo/tests')
259259
)
260260
})
261261

@@ -274,7 +274,7 @@ describe('BranchSelector', () => {
274274
})
275275

276276
describe('user selects a branch', () => {
277-
it('shows default branch as first option in dropdown', async () => {
277+
it('shows all branches as first option in dropdown', async () => {
278278
const { queryClient, user } = setup()
279279
render(<BranchSelector />, {
280280
wrapper: wrapper(queryClient),
@@ -286,7 +286,8 @@ describe('BranchSelector', () => {
286286
await user.click(select)
287287

288288
const options = screen.getAllByRole('option')
289-
expect(options[0]).toHaveTextContent('main')
289+
expect(options[0]).toHaveTextContent('All Branches')
290+
expect(options[1]).toHaveTextContent('main')
290291
})
291292

292293
it('navigates to the selected branch', async () => {
@@ -367,7 +368,7 @@ describe('BranchSelector', () => {
367368
wrapper: wrapper(queryClient),
368369
})
369370

370-
const select = await screen.findByText('main')
371+
const select = await screen.findByText('All Branches')
371372
await user.click(select)
372373

373374
const input = await screen.findByRole('combobox')
@@ -392,7 +393,7 @@ describe('BranchSelector', () => {
392393
name: 'test results branch selector',
393394
})
394395

395-
expect(select).toHaveTextContent('Select branch')
396+
expect(select).toHaveTextContent('All Branches')
396397
})
397398
})
398399
})

src/pages/RepoPage/FailedTestsTab/FailedTestsPage/SelectorSection/BranchSelector/BranchSelector.tsx

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ interface URLParams {
1515
branch?: string
1616
}
1717

18+
export const ALL_BRANCHES = 'All Branches'
19+
1820
const getDecodedBranch = (branch?: string) =>
1921
branch ? decodeURIComponent(branch) : undefined
2022

@@ -45,44 +47,34 @@ const BranchSelector = () => {
4547
},
4648
})
4749

48-
const decodedBranch = getDecodedBranch(branch)
49-
const selectedBranch = decodedBranch ?? overview?.defaultBranch ?? ''
50+
const decodedBranch = getDecodedBranch(branch) ?? ''
5051

5152
const { data: searchBranchValue } = useBranch({
5253
provider,
5354
owner,
5455
repo,
55-
branch: selectedBranch,
56+
branch: decodedBranch,
5657
opts: {
57-
queryKey: ['GetSelectedBranch', provider, owner, repo, selectedBranch],
58-
enabled: !!selectedBranch,
58+
queryKey: ['GetSelectedBranch', provider, owner, repo, decodedBranch],
59+
enabled: !!decodedBranch,
5960
},
6061
})
6162

6263
let selection = searchBranchValue?.branch
6364
if (!selection) {
6465
selection = {
65-
name: 'Select branch',
66+
name: ALL_BRANCHES,
6667
head: null,
6768
}
6869
}
6970

70-
if (
71-
selectedBranch === overview?.defaultBranch &&
72-
!branch &&
73-
selection.head !== null
74-
) {
75-
history.push(
76-
failedTestsLink.path({ branch: encodeURIComponent(selection?.name) })
77-
)
78-
}
79-
8071
const sortedBranchList = useMemo(() => {
8172
if (!branchList?.branches) return []
8273

8374
if (overview?.defaultBranch) {
8475
return [
8576
// Pins the default branch to the top of the list always, filters it from results otherwise
77+
{ name: ALL_BRANCHES, head: null },
8678
{ name: overview.defaultBranch, head: null },
8779
...branchList.branches.filter(
8880
(branch) => branch.name !== overview.defaultBranch
@@ -109,7 +101,12 @@ const BranchSelector = () => {
109101
value={selection}
110102
onChange={(item: Branch) => {
111103
history.push(
112-
failedTestsLink.path({ branch: encodeURIComponent(item?.name) })
104+
failedTestsLink.path({
105+
branch:
106+
item?.name === ALL_BRANCHES
107+
? ''
108+
: encodeURIComponent(item?.name),
109+
})
113110
)
114111
}}
115112
variant="gray"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ function SelectorSection() {
9191
return (
9292
<div className="flex flex-1 flex-col gap-2 md:flex-row md:justify-between md:gap-0">
9393
<BranchSelector />
94-
{selectedBranch === overview?.defaultBranch ? (
94+
{selectedBranch === overview?.defaultBranch || selectedBranch === null ? (
9595
<>
9696
<div className="flex flex-col gap-1 px-4">
9797
<h3 className="text-sm font-semibold text-ds-gray-octonary">

src/pages/RepoPage/FailedTestsTab/FailedTestsPage/hooks/useFlakeAggregates/useFlakeAggregates.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,15 @@ const query = `
3636
query GetFlakeAggregates(
3737
$owner: String!
3838
$repo: String!
39+
$branch: String
3940
$interval: MeasurementInterval
4041
) {
4142
owner(username: $owner) {
4243
repository: repository(name: $repo) {
4344
__typename
4445
... on Repository {
4546
testAnalytics {
46-
flakeAggregates(interval: $interval) {
47+
flakeAggregates(branch: $branch, interval: $interval) {
4748
flakeCount
4849
flakeCountPercentChange
4950
flakeRate
@@ -72,17 +73,19 @@ interface UseFlakeAggregatesOptions {
7273

7374
interface UseFlakeAggregatesParams {
7475
interval?: MeasurementInterval
76+
branch?: string | null
7577
opts?: UseFlakeAggregatesOptions
7678
}
7779

7880
export const useFlakeAggregates = ({
7981
interval,
8082
opts,
83+
branch,
8184
}: UseFlakeAggregatesParams = {}) => {
8285
const { provider, owner, repo } = useParams<URLParams>()
8386

8487
return useQuery({
85-
queryKey: ['GetFlakeAggregates', provider, owner, repo, interval],
88+
queryKey: ['GetFlakeAggregates', provider, owner, repo, interval, branch],
8689
queryFn: ({ signal }) =>
8790
Api.graphql({
8891
provider,
@@ -92,6 +95,7 @@ export const useFlakeAggregates = ({
9295
provider,
9396
owner,
9497
repo,
98+
branch,
9599
interval,
96100
},
97101
}).then((res) => {

src/pages/RepoPage/FailedTestsTab/FailedTestsPage/hooks/useInfiniteTestResults/useInfiniteTestResults.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ interface UseTestResultsArgs {
170170
owner: string
171171
repo: string
172172
filters?: {
173-
branch?: string
173+
branch?: string | null
174174
flags?: string[]
175175
interval?: MeasurementInterval
176176
parameter?: TestResultsFilterParameterType

src/pages/RepoPage/FailedTestsTab/FailedTestsPage/hooks/useTestResultsAggregates/useTestResultsAggregates.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ const query = `
5252
query GetTestResultsAggregates(
5353
$owner: String!
5454
$repo: String!
55+
$branch: String
5556
$interval: MeasurementInterval
5657
) {
5758
owner(username: $owner) {
@@ -66,7 +67,7 @@ const query = `
6667
private
6768
defaultBranch
6869
testAnalytics {
69-
testResultsAggregates(interval: $interval) {
70+
testResultsAggregates(branch: $branch, interval: $interval) {
7071
totalDuration
7172
totalDurationPercentChange
7273
slowestTestsDuration
@@ -96,13 +97,22 @@ interface URLParams {
9697

9798
export const useTestResultsAggregates = ({
9899
interval,
100+
branch,
99101
}: {
100102
interval?: MeasurementInterval
103+
branch?: string | null
101104
}) => {
102105
const { provider, owner, repo } = useParams<URLParams>()
103106

104107
return useQuery({
105-
queryKey: ['GetTestResultsAggregates', provider, owner, repo, interval],
108+
queryKey: [
109+
'GetTestResultsAggregates',
110+
provider,
111+
owner,
112+
repo,
113+
interval,
114+
branch,
115+
],
106116
queryFn: ({ signal }) =>
107117
Api.graphql({
108118
provider,
@@ -112,6 +122,7 @@ export const useTestResultsAggregates = ({
112122
provider,
113123
owner,
114124
repo,
125+
branch,
115126
interval,
116127
},
117128
}).then((res) => {

0 commit comments

Comments
 (0)