Skip to content

feat: add all branches option to TA branch selector #3842

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@ vi.mock('../TableHeader/TableHeader', () => ({
default: () => 'Table Header',
}))

const mocks = vi.hoisted(() => ({
useFlags: vi.fn(() => ({ allBranchesEnabled: false })),
}))

vi.mock('shared/featureFlags', async () => {
const actual = await vi.importActual('shared/featureFlags')

return {
...actual,
useFlags: mocks.useFlags,
}
})

const node1 = {
updatedAt: '2023-01-01T00:00:00Z',
name: 'test-1',
Expand Down Expand Up @@ -139,7 +152,12 @@ interface SetupArgs {
isFirstPullRequest?: boolean
}

describe('FailedTestsTable', () => {
describe.each([true, false])('FailedTestsTable', (allBranchesEnabled) => {
beforeEach(() => {
queryClient.clear()
mocks.useFlags.mockReturnValue({ allBranchesEnabled })
})

function setup({
noEntries = false,
planValue = Plans.USERS_ENTERPRISEM,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { useInView } from 'react-intersection-observer'
import { useLocation, useParams } from 'react-router-dom'

import { MeasurementInterval } from 'pages/RepoPage/shared/constants'
import { ALL_BRANCHES } from 'services/navigation/useNavLinks'
import { formatTimeToNow } from 'shared/utils/dates'
import Icon from 'ui/Icon'
import Spinner from 'ui/Spinner'
Expand Down Expand Up @@ -226,7 +227,8 @@ const FailedTestsTable = () => {
},
})

const isDefaultBranch = testData?.defaultBranch === branch
const isDefaultBranch =
testData?.defaultBranch === branch || ALL_BRANCHES === branch
const isTeamOrFreePlan = testData?.isTeamPlan || testData?.isFreePlan
// Only show flake rate column when on default branch for pro / enterprise plans or public repos
const hideFlakeRate =
Expand Down Expand Up @@ -298,6 +300,8 @@ const FailedTestsTable = () => {
}, [fetchNextPage, inView, hasNextPage])

if (testData?.isFirstPullRequest && testData.totalCount === 0) {
const defaultBranch = testData?.defaultBranch ?? 'default'

return (
<div className="flex flex-col gap-2">
<TableHeader
Expand All @@ -308,7 +312,8 @@ const FailedTestsTable = () => {
<div className="mt-4 text-center text-ds-gray-quinary">
<p>No data yet</p>
<p>
To see data for the main branch, merge your PR into the main branch.
To see data for the {defaultBranch} branch, merge your PR into the{' '}
{defaultBranch} branch.
</p>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ import MetricsSection, { historicalTrendToCopy } from './MetricsSection'

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

vi.mock('shared/featureFlags', async () => {
const actual = await vi.importActual('shared/featureFlags')

return {
...actual,
useFlags: vi.fn(() => ({ allBranchesEnabled: false })),
}
})

const mockAggResponse = (
planValue: PlanName = Plans.USERS_ENTERPRISEM,
isPrivate = false
Expand Down Expand Up @@ -148,11 +157,14 @@ describe('MetricsSection', () => {
})
})

describe('when on default branch', () => {
describe.each([
['default branch', 'main'],
['all branches', 'All%20branches'],
])('when on %s', (_, encodedBranch) => {
it('renders subheaders', async () => {
setup()
render(<MetricsSection />, {
wrapper: wrapper('/gh/owner/repo/tests/main'),
wrapper: wrapper(`/gh/owner/repo/tests/${encodedBranch}`),
})

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

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

const title = await screen.findByText('Slowest tests')
Expand All @@ -199,7 +211,7 @@ describe('MetricsSection', () => {
it('can update the location params on button click', async () => {
const { user } = setup()
render(<MetricsSection />, {
wrapper: wrapper('/gh/owner/repo/tests/main'),
wrapper: wrapper(`/gh/owner/repo/tests/${encodedBranch}`),
})
const select = await screen.findByText('12')
expect(select).toBeInTheDocument()
Expand All @@ -217,7 +229,7 @@ describe('MetricsSection', () => {
it('removes the location param on second button click', async () => {
const { user } = setup()
render(<MetricsSection />, {
wrapper: wrapper('/gh/owner/repo/tests/main'),
wrapper: wrapper(`/gh/owner/repo/tests/${encodedBranch}`),
})
const select = await screen.findByText('12')
expect(select).toBeInTheDocument()
Expand All @@ -239,7 +251,7 @@ describe('MetricsSection', () => {
it('renders total flaky tests card', async () => {
setup()
render(<MetricsSection />, {
wrapper: wrapper('/gh/owner/repo/tests/main'),
wrapper: wrapper(`/gh/owner/repo/tests/${encodedBranch}`),
})

const title = await screen.findByText('Flaky tests')
Expand All @@ -256,7 +268,7 @@ describe('MetricsSection', () => {
it('can update the location params on button click', async () => {
const { user } = setup()
render(<MetricsSection />, {
wrapper: wrapper('/gh/owner/repo/tests/main'),
wrapper: wrapper(`/gh/owner/repo/tests/${encodedBranch}`),
})
const select = await screen.findByText(88)
expect(select).toBeInTheDocument()
Expand All @@ -274,7 +286,7 @@ describe('MetricsSection', () => {
it('removes the location param on second button click', async () => {
const { user } = setup()
render(<MetricsSection />, {
wrapper: wrapper('/gh/owner/repo/tests/main'),
wrapper: wrapper(`/gh/owner/repo/tests/${encodedBranch}`),
})
const select = await screen.findByText(88)
expect(select).toBeInTheDocument()
Expand Down Expand Up @@ -313,7 +325,7 @@ describe('MetricsSection', () => {
it('renders total failures card', async () => {
setup()
render(<MetricsSection />, {
wrapper: wrapper('/gh/owner/repo/tests/main'),
wrapper: wrapper(`/gh/owner/repo/tests/${encodedBranch}`),
})

const title = await screen.findByText('Cumulative Failures')
Expand All @@ -330,7 +342,7 @@ describe('MetricsSection', () => {
it('can update the location params on button click', async () => {
const { user } = setup()
render(<MetricsSection />, {
wrapper: wrapper('/gh/owner/repo/tests/main'),
wrapper: wrapper(`/gh/owner/repo/tests/${encodedBranch}`),
})
const select = await screen.findByText(1)
expect(select).toBeInTheDocument()
Expand Down Expand Up @@ -370,7 +382,7 @@ describe('MetricsSection', () => {
it('renders total skips card', async () => {
setup()
render(<MetricsSection />, {
wrapper: wrapper('/gh/owner/repo/tests/main'),
wrapper: wrapper(`/gh/owner/repo/tests/${encodedBranch}`),
})

const title = await screen.findByText('Skipped tests')
Expand All @@ -387,7 +399,7 @@ describe('MetricsSection', () => {
it('can update the location params on button click', async () => {
const { user } = setup()
render(<MetricsSection />, {
wrapper: wrapper('/gh/owner/repo/tests/main'),
wrapper: wrapper(`/gh/owner/repo/tests/${encodedBranch}`),
})
const select = await screen.findByText(20)
expect(select).toBeInTheDocument()
Expand All @@ -405,7 +417,7 @@ describe('MetricsSection', () => {
it('removes the location param on second button click', async () => {
const { user } = setup()
render(<MetricsSection />, {
wrapper: wrapper('/gh/owner/repo/tests/main'),
wrapper: wrapper(`/gh/owner/repo/tests/${encodedBranch}`),
})
const select = await screen.findByText(20)
expect(select).toBeInTheDocument()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useLocation, useParams } from 'react-router-dom'

import { MeasurementInterval } from 'pages/RepoPage/shared/constants'
import { useLocationParams } from 'services/navigation/useLocationParams'
import { ALL_BRANCHES } from 'services/navigation/useNavLinks'
import { cn } from 'shared/utils/cn'
import { formatTimeFromSeconds } from 'shared/utils/dates'
import Badge from 'ui/Badge'
Expand Down Expand Up @@ -379,7 +380,10 @@ function MetricsSection() {
const decodedBranch = getDecodedBranch(branch)
const selectedBranch = decodedBranch ?? testResults?.defaultBranch ?? ''

if (selectedBranch !== testResults?.defaultBranch) {
if (
selectedBranch !== testResults?.defaultBranch &&
selectedBranch !== ALL_BRANCHES
) {
return null
}

Expand Down
Loading