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 @@ -235,13 +235,13 @@ const FailedTestsTable = () => {
},
})

const [isDefaultBranch, setIsDefaultBranch] = useState(false)
const [showResetButton, setShowResetButton] = useState(false)
const [isTeamOrFreePlan, setIsTeamOrFreePlan] = useState(false)
const [isPrivate, setIsPrivate] = useState(false)

useEffect(() => {
if (testData?.defaultBranch) {
setIsDefaultBranch(testData.defaultBranch === branch)
setShowResetButton(testData.defaultBranch === branch || !branch)
}
}, [testData?.defaultBranch, branch])

Expand All @@ -258,7 +258,7 @@ const FailedTestsTable = () => {
}, [testData?.private])

const hideFlakeRate =
(isTeamOrFreePlan && isPrivate) || (!!branch && !isDefaultBranch)
(isTeamOrFreePlan && isPrivate) || (!!branch && !showResetButton)

const tableData = useMemo(() => {
if (!testData?.testResults) return []
Expand Down Expand Up @@ -325,30 +325,35 @@ const FailedTestsTable = () => {
}
}, [fetchNextPage, inView, hasNextPage])

if (testData?.isFirstPullRequest && testData.totalCount === 0) {
if (
testData?.isFirstPullRequest &&
testData.totalCount === 0 &&
branch === testData?.defaultBranch
) {
return (
<div className="flex flex-col gap-2">
<TableHeader
totalCount={testData?.totalCount}
isDefaultBranch={isDefaultBranch}
showResetButton={showResetButton}
/>
<hr />
<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 {testData?.defaultBranch} branch, merge your PR
into the {testData?.defaultBranch} branch.
Comment on lines +343 to +344
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be some fallback copy if the default branch doesn't exist?

</p>
</div>
</div>
)
}

if (testData.totalCount === 0 && !isLoading && !!branch) {
if (testData.totalCount === 0 && !isLoading) {
return (
<div className="flex flex-col gap-2">
<TableHeader
totalCount={testData?.totalCount}
isDefaultBranch={isDefaultBranch}
showResetButton={showResetButton}
/>
<hr />
<p className="mt-4 text-center">No test results found</p>
Expand All @@ -363,7 +368,7 @@ const FailedTestsTable = () => {
<>
<TableHeader
totalCount={testData?.totalCount}
isDefaultBranch={isDefaultBranch}
showResetButton={showResetButton}
/>
<div className="tableui">
<table>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,14 @@ describe('MetricsSection', () => {
})
})

describe('when on default branch', () => {
describe.each([
['default branch', 'main'],
['all branches', ''],
])('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 +167,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 +185,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 +202,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 +220,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 +242,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 +259,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 +277,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 +316,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 +333,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 +373,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 +390,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 +408,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 @@ -377,9 +377,12 @@ function MetricsSection() {
})

const decodedBranch = getDecodedBranch(branch)
const selectedBranch = decodedBranch ?? testResults?.defaultBranch ?? ''
const selectedBranch = decodedBranch

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ interface SetupArgs {
hasNextPage?: boolean
nullOverview?: boolean
nullHead?: boolean
nullBranch?: boolean
}

describe('BranchSelector', () => {
Expand All @@ -142,10 +143,12 @@ describe('BranchSelector', () => {
hasNextPage = false,
nullOverview = false,
nullHead = false,
nullBranch = false,
}: SetupArgs = {
hasNextPage: false,
nullOverview: false,
nullHead: false,
nullBranch: false,
}
) {
const user = userEvent.setup()
Expand Down Expand Up @@ -182,6 +185,16 @@ describe('BranchSelector', () => {
branch = info.variables?.branch
}

if (nullBranch) {
return HttpResponse.json({
data: {
owner: {
repository: { __typename: 'Repository', branch: null },
},
},
})
}

let mockedBranch = mockBranch(branch)
if (nullHead) {
mockedBranch = mockBranch(branch, null)
Expand Down Expand Up @@ -241,7 +254,7 @@ describe('BranchSelector', () => {
wrapper: wrapper(queryClient),
})

const dropDownBtn = await screen.findByText('main')
const dropDownBtn = await screen.findByText('All branches')
expect(dropDownBtn).toBeInTheDocument()
})
})
Expand All @@ -255,7 +268,7 @@ describe('BranchSelector', () => {
})

await waitFor(() =>
expect(testLocation.pathname).toBe('/gh/codecov/test-repo/tests/main')
expect(testLocation.pathname).toBe('/gh/codecov/test-repo/tests')
)
})

Expand Down Expand Up @@ -286,7 +299,7 @@ describe('BranchSelector', () => {
await user.click(select)

const options = screen.getAllByRole('option')
expect(options[0]).toHaveTextContent('main')
expect(options[0]).toHaveTextContent('All branches')
})

it('navigates to the selected branch', async () => {
Expand Down Expand Up @@ -367,7 +380,7 @@ describe('BranchSelector', () => {
wrapper: wrapper(queryClient),
})

const select = await screen.findByText('main')
const select = await screen.findByText('All branches')
await user.click(select)

const input = await screen.findByRole('combobox')
Expand All @@ -383,9 +396,13 @@ describe('BranchSelector', () => {
it('displays select a branch in the button', async () => {
const { queryClient } = setup({
nullOverview: true,
nullBranch: true,
})
render(<BranchSelector />, {
wrapper: wrapper(queryClient),
wrapper: wrapper(
queryClient,
'/gh/codecov/test-repo/tests/nonexistent-branch'
),
})

const select = await screen.findByRole('button', {
Expand Down
Loading
Loading