Skip to content
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

feat: Pin default branch to top of branch selector items #3477

Merged
merged 2 commits into from
Nov 8, 2024
Merged
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 @@ -274,6 +274,21 @@ describe('BranchSelector', () => {
})

describe('user selects a branch', () => {
it('shows default branch as first option in dropdown', async () => {
const { queryClient, user } = setup()
render(<BranchSelector />, {
wrapper: wrapper(queryClient),
})

const select = await screen.findByRole('button', {
name: 'test results branch selector',
})
await user.click(select)

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

it('navigates to the selected branch', async () => {
const { user, queryClient } = setup()
render(<BranchSelector />, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ const BranchSelector = () => {
)
}

const sortedBranchList = overview?.defaultBranch
? [
// Pins the default branch to the top of the list always, filters it from results otherwise
{ name: overview.defaultBranch, head: null },
...(branchList?.branches?.filter(
(branch) => branch.name !== overview.defaultBranch
) ?? []),
]
: (branchList?.branches ?? [])

return (
<div className="flex w-full flex-col gap-1 px-4 lg:w-64 xl:w-80">
<h3 className="flex items-center gap-1 text-sm font-semibold text-ds-gray-octonary">
Expand All @@ -89,7 +99,7 @@ const BranchSelector = () => {
// @ts-expect-error - Select has some TS issues because it's still written in JS
dataMarketing="branch-selector-test-results-tab"
ariaName="test results branch selector"
items={branchList?.branches ?? []}
items={sortedBranchList}
value={selection}
onChange={(item: Branch) => {
history.push(
Expand Down
Loading