Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -92,7 +92,7 @@ export function SourceControlBranchSection({
type="button"
variant="ghost"
size="xs"
className="px-1.5 text-muted-foreground hover:text-foreground"
className="shrink-0 whitespace-nowrap px-1.5 text-muted-foreground hover:text-foreground"
onClick={(e) => {
e.stopPropagation()
if (currentWorktreeId && worktreePath && branchSummary) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// @vitest-environment happy-dom
import { render, screen, fireEvent } from '@testing-library/react'
import { describe, expect, it, vi } from 'vitest'
import { SectionHeader } from './section-header'

describe('SectionHeader', () => {
it('renders section label and file count without wrapping classes', () => {
const { container } = render(
<SectionHeader
label="Changes"
count={13}
isCollapsed={false}
onToggle={vi.fn()}
actions={<button type="button">Action</button>}
/>
)

expect(screen.getByText('Changes')).toBeDefined()
expect(screen.getByText('13')).toBeDefined()
expect(screen.getByRole('button', { name: /Changes/i })).toBeDefined()

// Ensure flex-wrap is not used on container or action clusters
const sectionRow = container.querySelector('.group\\/section')
expect(sectionRow).not.toBeNull()
expect(sectionRow?.className).not.toContain('flex-wrap')
expect(sectionRow?.className).toContain('flex')

// Ensure actions container does not wrap and has shrink-0
const actionsContainer = sectionRow?.lastElementChild
expect(actionsContainer?.className).toContain('shrink-0')
expect(actionsContainer?.className).not.toContain('flex-wrap')

// Ensure label has truncate to prevent overflowing row on narrow widths
const labelSpan = screen.getByText('Changes')
expect(labelSpan.className).toContain('truncate')
})

it('calls onToggle when header button is clicked', () => {
const onToggle = vi.fn()
render(
<SectionHeader label="Staged Changes" count={5} isCollapsed={true} onToggle={onToggle} />
)

fireEvent.click(screen.getByRole('button', { name: /Staged Changes/i }))
expect(onToggle).toHaveBeenCalledTimes(1)
})

it('keeps View all text button and icon actions together without wrapping', () => {
Comment thread
AmethystLiang marked this conversation as resolved.
Resolved
render(
<SectionHeader
label="Changes"
count={13}
isCollapsed={false}
onToggle={vi.fn()}
actions={
<div className="flex shrink-0 items-center">
<button type="button" aria-label="Discard all">
Discard
</button>
<button type="button" aria-label="Stage all">
Stage
</button>
<button type="button" className="shrink-0 whitespace-nowrap">
View all
</button>
</div>
}
/>
)

expect(screen.getByText('View all')).toBeDefined()
expect(screen.getByLabelText('Discard all')).toBeDefined()
expect(screen.getByLabelText('Stage all')).toBeDefined()
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -25,37 +25,39 @@ export function SectionHeader({
// Why: shared rounded container so the hover background spans the whole row instead of clipping around the label.
return (
<div className="pl-1 pr-3 pt-3 pb-1">
<div className="group/section flex flex-wrap items-center gap-x-1 rounded-md pr-1 hover:bg-accent hover:text-accent-foreground">
<div className="group/section flex items-center gap-x-1 rounded-md pr-1 hover:bg-accent hover:text-accent-foreground">
<Button
type="button"
variant="ghost"
size="xs"
className="h-auto min-h-6 min-w-0 flex-auto justify-start gap-x-1 gap-y-0 py-0.5 text-left font-semibold uppercase tracking-wider text-foreground/70 group-hover/section:text-accent-foreground"
className="h-auto min-h-6 min-w-0 flex-1 justify-start gap-x-1 gap-y-0 py-0.5 text-left font-semibold uppercase tracking-wider text-foreground/70 group-hover/section:text-accent-foreground"
onClick={onToggle}
aria-expanded={!isCollapsed}
>
<ChevronDown
className={cn('size-3.5 shrink-0 transition-transform', isCollapsed && '-rotate-90')}
/>
<span className="min-w-0">
<span className="flex items-center gap-1">
<span className="min-w-0 whitespace-normal break-words">{label}</span>
<span className="min-w-0 flex-1">
<span className="flex min-w-0 items-center gap-1">
<span className="min-w-0 truncate" title={label}>
{label}
</span>
{/* Why: no aria-label here — inside the toggle button it would rewrite the
button's accessible name; the explanation stays a hover-only title. */}
<span className="shrink-0 text-[11px] font-medium tabular-nums" title={countTitle}>
{count}
</span>
</span>
{conflictCount > 0 && (
<span className="block whitespace-normal text-[11px] font-medium text-destructive/80">
<span className="block truncate text-[11px] font-medium text-destructive/80">
{conflictCount}{' '}
{translate('auto.components.right.sidebar.SourceControl.413a3ba113', 'conflict')}
{conflictCount === 1 ? '' : 's'}
</span>
)}
</span>
</Button>
<div className="ml-auto flex max-w-full flex-wrap items-center justify-end">{actions}</div>
<div className="ml-auto flex shrink-0 items-center justify-end">{actions}</div>
</div>
</div>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,64 +112,62 @@ export function SourceControlUncommittedSections(props: {
isCollapsed={isCollapsed}
onToggle={() => props.toggleSection(id)}
actions={
<>
<div className="flex items-center">
{canRevertAll && (
<ActionButton
icon={area === 'untracked' ? Trash : Undo2}
title={
area === 'untracked'
? translate(
'auto.components.right.sidebar.SourceControl.2f609a2e7c',
'Delete all untracked'
)
: translate(
'auto.components.right.sidebar.SourceControl.ce41708855',
'Discard all'
)
}
onClick={(event) => {
event.stopPropagation()
props.requestDiscardAllInArea(area, discardAllPaths)
}}
disabled={props.isExecutingBulk}
/>
)}
{canStageAll && (
<ActionButton
icon={Plus}
title={translate(
'auto.components.right.sidebar.SourceControl.24d2598eff',
'Stage all'
)}
onClick={(event) => {
event.stopPropagation()
void props.handleStageAllPaths(stageAllPaths)
}}
disabled={props.isExecutingBulk}
/>
)}
{canUnstageAll && (
<ActionButton
icon={Minus}
title={translate(
'auto.components.right.sidebar.SourceControl.9339382454',
'Unstage all'
)}
onClick={(event) => {
event.stopPropagation()
void props.handleUnstagePaths(unstageAllPaths)
}}
disabled={props.isExecutingBulk}
/>
)}
</div>
<div className="flex items-center">
{canRevertAll && (
<ActionButton
icon={area === 'untracked' ? Trash : Undo2}
title={
area === 'untracked'
? translate(
'auto.components.right.sidebar.SourceControl.2f609a2e7c',
'Delete all untracked'
)
: translate(
'auto.components.right.sidebar.SourceControl.ce41708855',
'Discard all'
)
}
onClick={(event) => {
event.stopPropagation()
props.requestDiscardAllInArea(area, discardAllPaths)
}}
disabled={props.isExecutingBulk}
/>
)}
{canStageAll && (
<ActionButton
icon={Plus}
title={translate(
'auto.components.right.sidebar.SourceControl.24d2598eff',
'Stage all'
)}
onClick={(event) => {
event.stopPropagation()
void props.handleStageAllPaths(stageAllPaths)
}}
disabled={props.isExecutingBulk}
/>
)}
{canUnstageAll && (
<ActionButton
icon={Minus}
title={translate(
'auto.components.right.sidebar.SourceControl.9339382454',
'Unstage all'
)}
onClick={(event) => {
event.stopPropagation()
void props.handleUnstagePaths(unstageAllPaths)
}}
disabled={props.isExecutingBulk}
/>
)}
{sectionViewAction ? (
<Button
type="button"
variant="ghost"
size="xs"
className="px-1.5 text-muted-foreground hover:text-foreground"
className="shrink-0 whitespace-nowrap px-1.5 text-muted-foreground hover:text-foreground"
onClick={(event) => {
event.stopPropagation()
props.onViewSection(sectionViewAction)
Expand All @@ -181,7 +179,7 @@ export function SourceControlUncommittedSections(props: {
)}
</Button>
) : null}
</>
</div>
}
/>
{!isCollapsed && (
Expand Down
Loading