From 3f1285a62ef2973aa916b1c01ad40dc841a67a4f Mon Sep 17 00:00:00 2001 From: Brennan Benson <79079362+brennanb2025@users.noreply.github.com> Date: Thu, 23 Jul 2026 14:06:15 -0700 Subject: [PATCH] test(source-control): harden identity-row detached + no-identity contracts Add a stable data-testid to the identity row so the no-identity case proves no row renders, and assert the detached badge's accessible label + focusability. Addresses CodeRabbit review on #10215. --- .../source-control-header-toolbar-identity.test.tsx | 8 ++++++++ .../right-sidebar/source-control-header-toolbar.tsx | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/renderer/src/components/right-sidebar/source-control-header-toolbar-identity.test.tsx b/src/renderer/src/components/right-sidebar/source-control-header-toolbar-identity.test.tsx index ce3e813d8a5..a7039795932 100644 --- a/src/renderer/src/components/right-sidebar/source-control-header-toolbar-identity.test.tsx +++ b/src/renderer/src/components/right-sidebar/source-control-header-toolbar-identity.test.tsx @@ -74,6 +74,7 @@ describe('SourceControlHeaderToolbar branch identity', () => { const createPrIndex = markup.indexOf('Create PR') // Why: the #9787 revert regression — identity must not evict Create PR. + expect(markup).toContain('data-testid="source-control-git-identity-row"') expect(branchIndex).toBeGreaterThan(-1) expect(createPrIndex).toBeGreaterThan(-1) // Identity row renders above the toolbar row that hosts Create PR. @@ -94,13 +95,20 @@ describe('SourceControlHeaderToolbar branch identity', () => { }) expect(markup).not.toContain('aria-label="Current branch:') + expect(markup).toContain('data-testid="source-control-git-identity-row"') expect(markup).toContain('Detached HEAD · 8cec248') + // Detached badge stays keyboard-reachable and exposes the full tooltip as its label. + expect(markup).toContain( + 'aria-label="Detached HEAD at 8cec248. You are viewing a commit, not a branch."' + ) + expect(markup).toContain('tabindex="0"') expect(markup).toContain('Create PR') }) it('omits the identity row when there is no git identity', () => { const markup = renderToolbar({ gitIdentityDisplay: null }) + expect(markup).not.toContain('data-testid="source-control-git-identity-row"') expect(markup).not.toContain('aria-label="Current branch:') expect(markup).toContain('Create PR') }) diff --git a/src/renderer/src/components/right-sidebar/source-control-header-toolbar.tsx b/src/renderer/src/components/right-sidebar/source-control-header-toolbar.tsx index 90b662602bb..d56d56b0cb6 100644 --- a/src/renderer/src/components/right-sidebar/source-control-header-toolbar.tsx +++ b/src/renderer/src/components/right-sidebar/source-control-header-toolbar.tsx @@ -55,7 +55,7 @@ function SourceControlGitIdentityRow({ }): React.JSX.Element { if (display.kind === 'detached') { return ( -